merged tag ooo/DEV300_m102
[LibreOffice.git] / fpicker / source / office / OfficeControlAccess.cxx
blob6afe6e509acfadee8378162bbf11e4b736b592e6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
31 #include "OfficeControlAccess.hxx"
32 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
33 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
34 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
35 #include <vcl/lstbox.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <tools/urlobj.hxx>
39 #include <algorithm>
40 #include <functional>
42 //.........................................................................
43 namespace svt
45 //.........................................................................
47 // helper -------------------------------------------------------------
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::ui::dialogs;
53 using namespace ExtendedFilePickerElementIds;
54 using namespace CommonFilePickerElementIds;
55 using namespace InternalFilePickerElementIds;
57 // --------------------------------------------------------------------
58 namespace
60 // ----------------------------------------------------------------
61 #define PROPERTY_FLAG_TEXT 0x00000001
62 #define PROPERTY_FLAG_ENDBALED 0x00000002
63 #define PROPERTY_FLAG_VISIBLE 0x00000004
64 #define PROPERTY_FLAG_HELPURL 0x00000008
65 #define PROPERTY_FLAG_LISTITEMS 0x00000010
66 #define PROPERTY_FLAG_SELECTEDITEM 0x00000020
67 #define PROPERTY_FLAG_SELECTEDITEMINDEX 0x00000040
68 #define PROPERTY_FLAG_CHECKED 0x00000080
70 // ----------------------------------------------------------------
71 // ................................................................
72 struct ControlDescription
74 const sal_Char* pControlName;
75 sal_Int16 nControlId;
76 sal_Int32 nPropertyFlags;
79 // ................................................................
80 typedef const ControlDescription* ControlDescIterator;
81 typedef ::std::pair< ControlDescIterator, ControlDescIterator > ControlDescRange;
83 // ......................................................................
84 #define PROPERTY_FLAGS_COMMON ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL )
85 #define PROPERTY_FLAGS_LISTBOX ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX )
86 #define PROPERTY_FLAGS_CHECKBOX ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT )
88 // Note: this array MUST be sorted by name!
89 static const ControlDescription aDescriptions[] = {
90 { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX },
91 { "CancelButton", PUSHBUTTON_CANCEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
92 { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
93 { "DefaultLocationButton", TOOLBOXBUTOON_DEFAULT_LOCATION, PROPERTY_FLAGS_COMMON },
94 { "FileURLEdit", EDIT_FILEURL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
95 { "FileURLEditLabel", EDIT_FILEURL_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
96 { "FileView", CONTROL_FILEVIEW, PROPERTY_FLAGS_COMMON },
97 { "FilterList", LISTBOX_FILTER, PROPERTY_FLAGS_COMMON },
98 { "FilterListLabel", LISTBOX_FILTER_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
99 { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX },
100 { "HelpButton", PUSHBUTTON_HELP, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
101 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX },
102 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
103 { "LevelUpButton", TOOLBOXBUTOON_LEVEL_UP, PROPERTY_FLAGS_COMMON },
104 { "LinkBox", CHECKBOX_LINK, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX },
105 { "NewFolderButton", TOOLBOXBUTOON_NEW_FOLDER, PROPERTY_FLAGS_COMMON },
106 { "OkButton", PUSHBUTTON_OK , PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
107 { "PasswordBox", CHECKBOX_PASSWORD, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX },
108 { "PlayButton", PUSHBUTTON_PLAY, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
109 { "PreviewBox", CHECKBOX_PREVIEW, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX },
110 { "ReadOnlyBox", CHECKBOX_READONLY, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX },
111 { "SelectionBox", CHECKBOX_SELECTION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX },
112 { "TemplateList", LISTBOX_TEMPLATE, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX },
113 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT },
114 { "VersionList", LISTBOX_VERSION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX },
115 { "VersionListLabel", LISTBOX_VERSION_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }
118 // ................................................................
119 static const sal_Int32 s_nControlCount = sizeof( aDescriptions ) / sizeof( aDescriptions[0] );
121 static ControlDescIterator s_pControls = aDescriptions;
122 static ControlDescIterator s_pControlsEnd = aDescriptions + s_nControlCount;
124 // ................................................................
125 struct ControlDescriptionLookup
127 bool operator()( const ::rtl::OUString& _rLookup, const ControlDescription& _rDesc )
129 return _rLookup.compareToAscii( _rDesc.pControlName ) < 0;
131 bool operator()( const ControlDescription& _rDesc, const ::rtl::OUString& _rLookup )
133 return _rLookup.compareToAscii( _rDesc.pControlName ) > 0;
137 // ................................................................
138 struct ExtractControlName : public ::std::unary_function< ControlDescription, ::rtl::OUString >
140 ::rtl::OUString operator()( const ControlDescription& _rDesc )
142 return ::rtl::OUString::createFromAscii( _rDesc.pControlName );
146 // ----------------------------------------------------------------
147 // ................................................................
148 struct ControlProperty
150 const sal_Char* pPropertyName;
151 sal_Int16 nPropertyId;
154 typedef const ControlProperty* ControlPropertyIterator;
156 // ................................................................
157 static const ControlProperty aProperties[] = {
158 { "Text", PROPERTY_FLAG_TEXT },
159 { "Enabled", PROPERTY_FLAG_ENDBALED },
160 { "Visible", PROPERTY_FLAG_VISIBLE },
161 { "HelpURL", PROPERTY_FLAG_HELPURL },
162 { "ListItems", PROPERTY_FLAG_LISTITEMS },
163 { "SelectedItem", PROPERTY_FLAG_SELECTEDITEM },
164 { "SelectedItemIndex", PROPERTY_FLAG_SELECTEDITEMINDEX },
165 { "Checked", PROPERTY_FLAG_CHECKED }
168 // ................................................................
169 static const int s_nPropertyCount = sizeof( aProperties ) / sizeof( aProperties[0] );
171 static ControlPropertyIterator s_pProperties = aProperties;
172 static ControlPropertyIterator s_pPropertiesEnd = aProperties + s_nPropertyCount;
174 // ................................................................
175 struct ControlPropertyLookup
177 ::rtl::OUString m_sLookup;
178 ControlPropertyLookup( const ::rtl::OUString& _rLookup ) : m_sLookup( _rLookup ) { }
180 sal_Bool operator()( const ControlProperty& _rProp )
182 return m_sLookup.equalsAscii( _rProp.pPropertyName );
186 //-----------------------------------------------------------------
187 void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException) )
189 throw IllegalArgumentException();
190 // TODO: error message in the exception
194 //---------------------------------------------------------------------
195 OControlAccess::OControlAccess( IFilePickerController* _pController, SvtFileView* _pFileView )
196 :m_pFilePickerController( _pController )
197 ,m_pFileView( _pFileView )
199 DBG_ASSERT( m_pFilePickerController, "OControlAccess::OControlAccess: invalid control locator!" );
202 //---------------------------------------------------------------------
203 void OControlAccess::setHelpURL( Window* _pControl, const ::rtl::OUString& sHelpURL, sal_Bool _bFileView )
205 rtl::OUString sHelpID( sHelpURL );
206 INetURLObject aHID( sHelpURL );
207 if ( aHID.GetProtocol() == INET_PROT_HID )
208 sHelpID = aHID.GetURLPath();
210 // URLs should always be UTF8 encoded and escaped
211 rtl::OString sID( rtl::OUStringToOString( sHelpID, RTL_TEXTENCODING_UTF8 ) );
212 if ( _bFileView )
213 // the file view "overloaded" the SetHelpId
214 static_cast< SvtFileView* >( _pControl )->SetHelpId( sID );
215 else
216 _pControl->SetHelpId( sID );
219 //---------------------------------------------------------------------
220 ::rtl::OUString OControlAccess::getHelpURL( Window* _pControl, sal_Bool _bFileView )
222 rtl::OString aHelpId = _pControl->GetHelpId();
223 if ( _bFileView )
224 // the file view "overloaded" the SetHelpId
225 aHelpId = static_cast< SvtFileView* >( _pControl )->GetHelpId( );
227 ::rtl::OUString sHelpURL;
228 ::rtl::OUString aTmp( rtl::OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ) );
229 INetURLObject aHID( aTmp );
230 if ( aHID.GetProtocol() == INET_PROT_NOT_VALID )
231 sHelpURL = rtl::OUString::createFromAscii( INET_HID_SCHEME );
232 sHelpURL += aTmp;
233 return sHelpURL;
236 // --------------------------------------------------------------------------
237 Any OControlAccess::getControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty )
239 // look up the control
240 sal_Int16 nControlId = -1;
241 sal_Int32 nPropertyMask = 0;
242 Control* pControl = implGetControl( _rControlName, &nControlId, &nPropertyMask );
243 // will throw an IllegalArgumentException if the name is not valid
245 // look up the property
246 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
247 if ( aPropDesc == s_pPropertiesEnd )
248 // it's a completely unknown property
249 lcl_throwIllegalArgumentException();
251 if ( 0 == ( nPropertyMask & aPropDesc->nPropertyId ) )
252 // it's a property which is known, but not allowed for this control
253 lcl_throwIllegalArgumentException();
255 return implGetControlProperty( pControl, aPropDesc->nPropertyId );
258 //---------------------------------------------------------------------
259 Control* OControlAccess::implGetControl( const ::rtl::OUString& _rControlName, sal_Int16* _pId, sal_Int32* _pPropertyMask ) const SAL_THROW( (IllegalArgumentException) )
261 Control* pControl = NULL;
263 // translate the name into an id
264 ControlDescRange aFoundRange = ::std::equal_range( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() );
265 if ( aFoundRange.first != aFoundRange.second )
267 // get the VCL control determined by this id
268 pControl = m_pFilePickerController->getControl( aFoundRange.first->nControlId );
271 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
272 if ( !pControl )
273 lcl_throwIllegalArgumentException();
275 // out parameters and outta here
276 if ( _pId )
277 *_pId = aFoundRange.first->nControlId;
278 if ( _pPropertyMask )
279 *_pPropertyMask = aFoundRange.first->nPropertyFlags;
281 return pControl;
284 //---------------------------------------------------------------------
285 void OControlAccess::setControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty, const ::com::sun::star::uno::Any& _rValue )
287 // look up the control
288 sal_Int16 nControlId = -1;
289 Control* pControl = implGetControl( _rControlName, &nControlId );
290 // will throw an IllegalArgumentException if the name is not valid
292 // look up the property
293 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
294 if ( aPropDesc == s_pPropertiesEnd )
295 lcl_throwIllegalArgumentException();
297 // set the property
298 implSetControlProperty( nControlId, pControl, aPropDesc->nPropertyId, _rValue, sal_False );
301 // --------------------------------------------------------------------------
302 Sequence< ::rtl::OUString > OControlAccess::getSupportedControls( )
304 Sequence< ::rtl::OUString > aControls( s_nControlCount );
305 ::rtl::OUString* pControls = aControls.getArray();
307 // collect the names of all _actually_existent_ controls
308 for ( ControlDescIterator aControl = s_pControls; aControl != s_pControlsEnd; ++aControl )
310 if ( m_pFilePickerController->getControl( aControl->nControlId ) )
311 *pControls++ = ::rtl::OUString::createFromAscii( aControl->pControlName );
314 aControls.realloc( pControls - aControls.getArray() );
315 return aControls;
318 // --------------------------------------------------------------------------
319 Sequence< ::rtl::OUString > OControlAccess::getSupportedControlProperties( const ::rtl::OUString& _rControlName )
321 sal_Int16 nControlId = -1;
322 sal_Int32 nPropertyMask = 0;
323 implGetControl( _rControlName, &nControlId, &nPropertyMask );
324 // will throw an IllegalArgumentException if the name is not valid
326 // fill in the property names
327 Sequence< ::rtl::OUString > aProps( s_nPropertyCount );
328 ::rtl::OUString* pProperty = aProps.getArray();
330 for ( ControlPropertyIterator aProp = s_pProperties; aProp != s_pPropertiesEnd; ++aProp )
331 if ( 0 != ( nPropertyMask & aProp->nPropertyId ) )
332 *pProperty++ = ::rtl::OUString::createFromAscii( aProp->pPropertyName );
334 aProps.realloc( pProperty - aProps.getArray() );
335 return aProps;
338 // --------------------------------------------------------------------------
339 sal_Bool OControlAccess::isControlSupported( const ::rtl::OUString& _rControlName )
341 return ::std::binary_search( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() );
344 // --------------------------------------------------------------------------
345 sal_Bool OControlAccess::isControlPropertySupported( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty )
347 // look up the control
348 sal_Int16 nControlId = -1;
349 sal_Int32 nPropertyMask = 0;
350 implGetControl( _rControlName, &nControlId, &nPropertyMask );
351 // will throw an IllegalArgumentException if the name is not valid
353 // look up the property
354 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
355 if ( aPropDesc == s_pPropertiesEnd )
356 // it's a property which is completely unknown
357 return sal_False;
359 return 0 != ( aPropDesc->nPropertyId & nPropertyMask );
362 //-----------------------------------------------------------------------------
363 void OControlAccess::setValue( sal_Int16 _nControlId, sal_Int16 _nControlAction, const Any& _rValue )
365 Control* pControl = m_pFilePickerController->getControl( _nControlId );
366 DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" );
367 if ( pControl )
369 sal_Int16 nPropertyId = -1;
370 if ( ControlActions::SET_HELP_URL == _nControlAction )
372 nPropertyId = PROPERTY_FLAG_HELPURL;
374 else
376 switch ( _nControlId )
378 case CHECKBOX_AUTOEXTENSION:
379 case CHECKBOX_PASSWORD:
380 case CHECKBOX_FILTEROPTIONS:
381 case CHECKBOX_READONLY:
382 case CHECKBOX_LINK:
383 case CHECKBOX_PREVIEW:
384 case CHECKBOX_SELECTION:
385 nPropertyId = PROPERTY_FLAG_CHECKED;
386 break;
388 case LISTBOX_FILTER:
389 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
390 break;
392 case LISTBOX_VERSION:
393 case LISTBOX_TEMPLATE:
394 case LISTBOX_IMAGE_TEMPLATE:
395 if ( ControlActions::SET_SELECT_ITEM == _nControlAction )
397 nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX;
399 else
401 DBG_ASSERT( WINDOW_LISTBOX == pControl->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" );
402 implDoListboxAction( static_cast< ListBox* >( pControl ), _nControlAction, _rValue );
404 break;
408 if ( -1 != nPropertyId )
409 implSetControlProperty( _nControlId, pControl, nPropertyId, _rValue );
413 //-----------------------------------------------------------------------------
414 Any OControlAccess::getValue( sal_Int16 _nControlId, sal_Int16 _nControlAction ) const
416 Any aRet;
418 Control* pControl = m_pFilePickerController->getControl( _nControlId, sal_False );
419 DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
420 if ( pControl )
422 sal_Int16 nPropertyId = -1;
423 if ( ControlActions::SET_HELP_URL == _nControlAction )
425 nPropertyId = PROPERTY_FLAG_HELPURL;
427 else
429 switch ( _nControlId )
431 case CHECKBOX_AUTOEXTENSION:
432 case CHECKBOX_PASSWORD:
433 case CHECKBOX_FILTEROPTIONS:
434 case CHECKBOX_READONLY:
435 case CHECKBOX_LINK:
436 case CHECKBOX_PREVIEW:
437 case CHECKBOX_SELECTION:
438 nPropertyId = PROPERTY_FLAG_CHECKED;
439 break;
441 case LISTBOX_FILTER:
442 if ( ControlActions::GET_SELECTED_ITEM == _nControlAction )
444 aRet <<= ::rtl::OUString( m_pFilePickerController->getCurFilter() );;
446 else
448 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
450 break;
452 case LISTBOX_VERSION:
453 case LISTBOX_TEMPLATE:
454 case LISTBOX_IMAGE_TEMPLATE:
455 switch ( _nControlAction )
457 case ControlActions::GET_SELECTED_ITEM:
458 nPropertyId = PROPERTY_FLAG_SELECTEDITEM;
459 break;
460 case ControlActions::GET_SELECTED_ITEM_INDEX:
461 nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX;
462 break;
463 case ControlActions::GET_ITEMS:
464 nPropertyId = PROPERTY_FLAG_LISTITEMS;
465 break;
466 default:
467 DBG_ERRORFILE( "OControlAccess::GetValue: invalid control action for the listbox!" );
468 break;
470 break;
474 if ( -1 != nPropertyId )
475 aRet = implGetControlProperty( pControl, nPropertyId );
478 return aRet;
481 //-----------------------------------------------------------------------------
482 void OControlAccess::setLabel( sal_Int16 nId, const ::rtl::OUString &rLabel )
484 Control* pControl = m_pFilePickerController->getControl( nId, sal_True );
485 DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
486 if ( pControl )
487 pControl->SetText( rLabel );
490 //-----------------------------------------------------------------------------
491 ::rtl::OUString OControlAccess::getLabel( sal_Int16 nId ) const
493 ::rtl::OUString sLabel;
495 Control* pControl = m_pFilePickerController->getControl( nId, sal_True );
496 DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
497 if ( pControl )
498 sLabel = pControl->GetText();
500 return sLabel;
503 //-----------------------------------------------------------------------------
504 void OControlAccess::enableControl( sal_Int16 _nId, sal_Bool _bEnable )
506 m_pFilePickerController->enableControl( _nId, _bEnable );
509 // -----------------------------------------------------------------------
510 void OControlAccess::implDoListboxAction( ListBox* _pListbox, sal_Int16 _nControlAction, const Any& _rValue )
512 switch ( _nControlAction )
514 case ControlActions::ADD_ITEM:
516 ::rtl::OUString aEntry;
517 _rValue >>= aEntry;
518 if ( aEntry.getLength() )
519 _pListbox->InsertEntry( aEntry );
521 break;
523 case ControlActions::ADD_ITEMS:
525 Sequence < ::rtl::OUString > aTemplateList;
526 _rValue >>= aTemplateList;
528 if ( aTemplateList.getLength() )
530 for ( long i=0; i < aTemplateList.getLength(); i++ )
531 _pListbox->InsertEntry( aTemplateList[i] );
534 break;
536 case ControlActions::DELETE_ITEM:
538 sal_Int32 nPos = 0;
539 if ( _rValue >>= nPos )
540 _pListbox->RemoveEntry( (sal_uInt16) nPos );
542 break;
544 case ControlActions::DELETE_ITEMS:
545 _pListbox->Clear();
546 break;
548 default:
549 DBG_ERRORFILE( "Wrong ControlAction for implDoListboxAction()" );
553 //-----------------------------------------------------------------------------
554 void OControlAccess::implSetControlProperty( sal_Int16 _nControlId, Control* _pControl, sal_Int16 _nProperty, const Any& _rValue, sal_Bool _bIgnoreIllegalArgument )
556 if ( !_pControl )
557 _pControl = m_pFilePickerController->getControl( _nControlId );
558 DBG_ASSERT( _pControl, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
559 if ( !_pControl )
560 return;
562 DBG_ASSERT( _pControl == m_pFilePickerController->getControl( _nControlId ),
563 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
565 switch ( _nProperty )
567 case PROPERTY_FLAG_TEXT:
569 ::rtl::OUString sText;
570 if ( _rValue >>= sText )
572 _pControl->SetText( sText );
574 else if ( !_bIgnoreIllegalArgument )
576 lcl_throwIllegalArgumentException();
579 break;
581 case PROPERTY_FLAG_ENDBALED:
583 sal_Bool bEnabled = sal_False;
584 if ( _rValue >>= bEnabled )
586 m_pFilePickerController->enableControl( _nControlId, bEnabled );
588 else if ( !_bIgnoreIllegalArgument )
590 lcl_throwIllegalArgumentException();
593 break;
595 case PROPERTY_FLAG_VISIBLE:
597 sal_Bool bVisible = sal_False;
598 if ( _rValue >>= bVisible )
600 _pControl->Show( bVisible );
602 else if ( !_bIgnoreIllegalArgument )
604 lcl_throwIllegalArgumentException();
607 break;
609 case PROPERTY_FLAG_HELPURL:
611 ::rtl::OUString sHelpURL;
612 if ( _rValue >>= sHelpURL )
614 setHelpURL( _pControl, sHelpURL, m_pFileView == _pControl );
616 else if ( !_bIgnoreIllegalArgument )
618 lcl_throwIllegalArgumentException();
621 break;
623 case PROPERTY_FLAG_LISTITEMS:
625 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
626 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
628 Sequence< ::rtl::OUString > aItems;
629 if ( _rValue >>= aItems )
631 // remove all previous items
632 static_cast< ListBox* >( _pControl )->Clear();
634 // add the new ones
635 const ::rtl::OUString* pItems = aItems.getConstArray();
636 const ::rtl::OUString* pItemsEnd = aItems.getConstArray() + aItems.getLength();
637 for ( const ::rtl::OUString* pItem = pItems;
638 pItem != pItemsEnd;
639 ++pItem
642 static_cast< ListBox* >( _pControl )->InsertEntry( *pItem );
646 else if ( !_bIgnoreIllegalArgument )
648 lcl_throwIllegalArgumentException();
651 break;
653 case PROPERTY_FLAG_SELECTEDITEM:
655 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
656 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
658 ::rtl::OUString sSelected;
659 if ( _rValue >>= sSelected )
661 static_cast< ListBox* >( _pControl )->SelectEntry( sSelected );
663 else if ( !_bIgnoreIllegalArgument )
665 lcl_throwIllegalArgumentException();
668 break;
670 case PROPERTY_FLAG_SELECTEDITEMINDEX:
672 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
673 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
675 sal_Int32 nPos = 0;
676 if ( _rValue >>= nPos )
678 static_cast< ListBox* >( _pControl )->SelectEntryPos( (sal_uInt16) nPos );
680 else if ( !_bIgnoreIllegalArgument )
682 lcl_throwIllegalArgumentException();
685 break;
687 case PROPERTY_FLAG_CHECKED:
689 DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(),
690 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
692 sal_Bool bChecked = sal_False;
693 if ( _rValue >>= bChecked )
695 static_cast< CheckBox* >( _pControl )->Check( bChecked );
697 else if ( !_bIgnoreIllegalArgument )
699 lcl_throwIllegalArgumentException();
702 break;
704 default:
705 DBG_ERROR( "OControlAccess::implSetControlProperty: invalid property id!" );
709 //-----------------------------------------------------------------------------
710 Any OControlAccess::implGetControlProperty( Control* _pControl, sal_Int16 _nProperty ) const
712 DBG_ASSERT( _pControl, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" );
714 Any aReturn;
715 switch ( _nProperty )
717 case PROPERTY_FLAG_TEXT:
718 aReturn <<= ::rtl::OUString( _pControl->GetText() );
719 break;
721 case PROPERTY_FLAG_ENDBALED:
722 aReturn <<= (sal_Bool)_pControl->IsEnabled();
723 break;
725 case PROPERTY_FLAG_VISIBLE:
726 aReturn <<= (sal_Bool)_pControl->IsVisible();
727 break;
729 case PROPERTY_FLAG_HELPURL:
730 aReturn <<= getHelpURL( _pControl, m_pFileView == _pControl );
731 break;
733 case PROPERTY_FLAG_LISTITEMS:
735 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
736 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
738 Sequence< ::rtl::OUString > aItems( static_cast< ListBox* >( _pControl )->GetEntryCount() );
739 ::rtl::OUString* pItems = aItems.getArray();
740 for ( sal_uInt16 i=0; i<static_cast< ListBox* >( _pControl )->GetEntryCount(); ++i )
741 *pItems++ = static_cast< ListBox* >( _pControl )->GetEntry( i );
743 aReturn <<= aItems;
745 break;
747 case PROPERTY_FLAG_SELECTEDITEM:
749 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
750 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
752 sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
753 ::rtl::OUString sSelected;
754 if ( LISTBOX_ENTRY_NOTFOUND != nSelected )
755 sSelected = static_cast< ListBox* >( _pControl )->GetSelectEntry();
756 aReturn <<= sSelected;
758 break;
760 case PROPERTY_FLAG_SELECTEDITEMINDEX:
762 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
763 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
765 sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
766 if ( LISTBOX_ENTRY_NOTFOUND != nSelected )
767 aReturn <<= (sal_Int32)static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
768 else
769 aReturn <<= (sal_Int32)-1;
771 break;
773 case PROPERTY_FLAG_CHECKED:
774 DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(),
775 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
777 aReturn <<= (sal_Bool)static_cast< CheckBox* >( _pControl )->IsChecked( );
778 break;
780 default:
781 DBG_ERROR( "OControlAccess::implGetControlProperty: invalid property id!" );
783 return aReturn;
786 //.........................................................................
787 } // namespace svt
788 //.........................................................................