1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OfficeControlAccess.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
34 #include "OfficeControlAccess.hxx"
35 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
36 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
37 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
38 #include <vcl/lstbox.hxx>
39 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HPP_
40 #include <com/sun/star/uno/Sequence.hxx>
46 //.........................................................................
49 //.........................................................................
51 // helper -------------------------------------------------------------
53 using namespace ::com::sun::star::uno
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::ui::dialogs
;
57 using namespace ExtendedFilePickerElementIds
;
58 using namespace CommonFilePickerElementIds
;
59 using namespace InternalFilePickerElementIds
;
61 // --------------------------------------------------------------------
64 // ----------------------------------------------------------------
65 #define PROPERTY_FLAG_TEXT 0x00000001
66 #define PROPERTY_FLAG_ENDBALED 0x00000002
67 #define PROPERTY_FLAG_VISIBLE 0x00000004
68 #define PROPERTY_FLAG_HELPURL 0x00000008
69 #define PROPERTY_FLAG_LISTITEMS 0x00000010
70 #define PROPERTY_FLAG_SELECTEDITEM 0x00000020
71 #define PROPERTY_FLAG_SELECTEDITEMINDEX 0x00000040
72 #define PROPERTY_FLAG_CHECKED 0x00000080
74 // ----------------------------------------------------------------
75 // ................................................................
76 struct ControlDescription
78 const sal_Char
* pControlName
;
80 sal_Int32 nPropertyFlags
;
83 // ................................................................
84 typedef const ControlDescription
* ControlDescIterator
;
85 typedef ::std::pair
< ControlDescIterator
, ControlDescIterator
> ControlDescRange
;
87 // ......................................................................
88 #define PROPERTY_FLAGS_COMMON ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL )
89 #define PROPERTY_FLAGS_LISTBOX ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX )
90 #define PROPERTY_FLAGS_CHECKBOX ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT )
92 // Note: this array MUST be sorted by name!
93 static const ControlDescription aDescriptions
[] = {
94 { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
95 { "CancelButton", PUSHBUTTON_CANCEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
96 { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
97 { "DefaultLocationButton", TOOLBOXBUTOON_DEFAULT_LOCATION
, PROPERTY_FLAGS_COMMON
},
98 { "FileURLEdit", EDIT_FILEURL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
99 { "FileURLEditLabel", EDIT_FILEURL_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
100 { "FileView", CONTROL_FILEVIEW
, PROPERTY_FLAGS_COMMON
},
101 { "FilterList", LISTBOX_FILTER
, PROPERTY_FLAGS_COMMON
},
102 { "FilterListLabel", LISTBOX_FILTER_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
103 { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
104 { "HelpButton", PUSHBUTTON_HELP
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
105 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
106 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
107 { "LevelUpButton", TOOLBOXBUTOON_LEVEL_UP
, PROPERTY_FLAGS_COMMON
},
108 { "LinkBox", CHECKBOX_LINK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
109 { "NewFolderButton", TOOLBOXBUTOON_NEW_FOLDER
, PROPERTY_FLAGS_COMMON
},
110 { "OkButton", PUSHBUTTON_OK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
111 { "PasswordBox", CHECKBOX_PASSWORD
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
112 { "PlayButton", PUSHBUTTON_PLAY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
113 { "PreviewBox", CHECKBOX_PREVIEW
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
114 { "ReadOnlyBox", CHECKBOX_READONLY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
115 { "SelectionBox", CHECKBOX_SELECTION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
116 { "TemplateList", LISTBOX_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
117 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
118 { "VersionList", LISTBOX_VERSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
119 { "VersionListLabel", LISTBOX_VERSION_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
}
122 // ................................................................
123 static const sal_Int32 s_nControlCount
= sizeof( aDescriptions
) / sizeof( aDescriptions
[0] );
125 static ControlDescIterator s_pControls
= aDescriptions
;
126 static ControlDescIterator s_pControlsEnd
= aDescriptions
+ s_nControlCount
;
128 // ................................................................
129 struct ControlDescriptionLookup
131 bool operator()( const ::rtl::OUString
& _rLookup
, const ControlDescription
& _rDesc
)
133 return _rLookup
.compareToAscii( _rDesc
.pControlName
) < 0;
135 bool operator()( const ControlDescription
& _rDesc
, const ::rtl::OUString
& _rLookup
)
137 return _rLookup
.compareToAscii( _rDesc
.pControlName
) > 0;
141 // ................................................................
142 struct ExtractControlName
: public ::std::unary_function
< ControlDescription
, ::rtl::OUString
>
144 ::rtl::OUString
operator()( const ControlDescription
& _rDesc
)
146 return ::rtl::OUString::createFromAscii( _rDesc
.pControlName
);
150 // ----------------------------------------------------------------
151 // ................................................................
152 struct ControlProperty
154 const sal_Char
* pPropertyName
;
155 sal_Int16 nPropertyId
;
158 typedef const ControlProperty
* ControlPropertyIterator
;
160 // ................................................................
161 static const ControlProperty aProperties
[] = {
162 { "Text", PROPERTY_FLAG_TEXT
},
163 { "Enabled", PROPERTY_FLAG_ENDBALED
},
164 { "Visible", PROPERTY_FLAG_VISIBLE
},
165 { "HelpURL", PROPERTY_FLAG_HELPURL
},
166 { "ListItems", PROPERTY_FLAG_LISTITEMS
},
167 { "SelectedItem", PROPERTY_FLAG_SELECTEDITEM
},
168 { "SelectedItemIndex", PROPERTY_FLAG_SELECTEDITEMINDEX
},
169 { "Checked", PROPERTY_FLAG_CHECKED
}
172 // ................................................................
173 static const int s_nPropertyCount
= sizeof( aProperties
) / sizeof( aProperties
[0] );
175 static ControlPropertyIterator s_pProperties
= aProperties
;
176 static ControlPropertyIterator s_pPropertiesEnd
= aProperties
+ s_nPropertyCount
;
178 // ................................................................
179 struct ControlPropertyLookup
181 ::rtl::OUString m_sLookup
;
182 ControlPropertyLookup( const ::rtl::OUString
& _rLookup
) : m_sLookup( _rLookup
) { }
184 sal_Bool
operator()( const ControlProperty
& _rProp
)
186 return m_sLookup
.equalsAscii( _rProp
.pPropertyName
);
190 //-----------------------------------------------------------------
191 void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException
) )
193 throw IllegalArgumentException();
194 // TODO: error message in the exception
198 //---------------------------------------------------------------------
199 OControlAccess::OControlAccess( IFilePickerController
* _pController
, SvtFileView
* _pFileView
)
200 :m_pFilePickerController( _pController
)
201 ,m_pFileView( _pFileView
)
203 DBG_ASSERT( m_pFilePickerController
, "OControlAccess::OControlAccess: invalid control locator!" );
206 //---------------------------------------------------------------------
207 void OControlAccess::setHelpURL( Window
* _pControl
, const ::rtl::OUString
& _rURL
, sal_Bool _bFileView
)
209 String
sHelpURL( _rURL
);
210 if ( COMPARE_EQUAL
== sHelpURL
.CompareIgnoreCaseToAscii( "HID:", sizeof( "HID:" ) - 1 ) )
212 String sID
= sHelpURL
.Copy( sizeof( "HID:" ) - 1 );
213 sal_Int32 nHelpId
= sID
.ToInt32();
216 // the file view "overloaded" the SetHelpId
217 static_cast< SvtFileView
* >( _pControl
)->SetHelpId( nHelpId
);
219 _pControl
->SetHelpId( nHelpId
);
223 DBG_ERRORFILE( "OControlAccess::setHelpURL: unsupported help URL type!" );
227 //---------------------------------------------------------------------
228 ::rtl::OUString
OControlAccess::getHelpURL( Window
* _pControl
, sal_Bool _bFileView
)
230 sal_Int32 nHelpId
= _pControl
->GetHelpId();
232 // the file view "overloaded" the SetHelpId
233 nHelpId
= static_cast< SvtFileView
* >( _pControl
)->GetHelpId( );
235 ::rtl::OUString
sHelpURL( RTL_CONSTASCII_USTRINGPARAM( "HID:" ) );
236 sHelpURL
+= ::rtl::OUString::valueOf( (sal_Int32
)nHelpId
);
241 // --------------------------------------------------------------------------
242 Any
OControlAccess::getControlProperty( const ::rtl::OUString
& _rControlName
, const ::rtl::OUString
& _rControlProperty
)
244 // look up the control
245 sal_Int16 nControlId
= -1;
246 sal_Int32 nPropertyMask
= 0;
247 Control
* pControl
= implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
248 // will throw an IllegalArgumentException if the name is not valid
250 // look up the property
251 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
252 if ( aPropDesc
== s_pPropertiesEnd
)
253 // it's a completely unknown property
254 lcl_throwIllegalArgumentException();
256 if ( 0 == ( nPropertyMask
& aPropDesc
->nPropertyId
) )
257 // it's a property which is known, but not allowed for this control
258 lcl_throwIllegalArgumentException();
260 return implGetControlProperty( pControl
, aPropDesc
->nPropertyId
);
263 //---------------------------------------------------------------------
264 Control
* OControlAccess::implGetControl( const ::rtl::OUString
& _rControlName
, sal_Int16
* _pId
, sal_Int32
* _pPropertyMask
) const SAL_THROW( (IllegalArgumentException
) )
266 Control
* pControl
= NULL
;
268 // translate the name into an id
269 ControlDescRange aFoundRange
= ::std::equal_range( s_pControls
, s_pControlsEnd
, _rControlName
, ControlDescriptionLookup() );
270 if ( aFoundRange
.first
!= aFoundRange
.second
)
272 // get the VCL control determined by this id
273 pControl
= m_pFilePickerController
->getControl( aFoundRange
.first
->nControlId
);
276 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
278 lcl_throwIllegalArgumentException();
280 // out parameters and outta here
282 *_pId
= aFoundRange
.first
->nControlId
;
283 if ( _pPropertyMask
)
284 *_pPropertyMask
= aFoundRange
.first
->nPropertyFlags
;
289 //---------------------------------------------------------------------
290 void OControlAccess::setControlProperty( const ::rtl::OUString
& _rControlName
, const ::rtl::OUString
& _rControlProperty
, const ::com::sun::star::uno::Any
& _rValue
)
292 // look up the control
293 sal_Int16 nControlId
= -1;
294 Control
* pControl
= implGetControl( _rControlName
, &nControlId
);
295 // will throw an IllegalArgumentException if the name is not valid
297 // look up the property
298 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
299 if ( aPropDesc
== s_pPropertiesEnd
)
300 lcl_throwIllegalArgumentException();
303 implSetControlProperty( nControlId
, pControl
, aPropDesc
->nPropertyId
, _rValue
, sal_False
);
306 // --------------------------------------------------------------------------
307 Sequence
< ::rtl::OUString
> OControlAccess::getSupportedControls( )
309 Sequence
< ::rtl::OUString
> aControls( s_nControlCount
);
310 ::rtl::OUString
* pControls
= aControls
.getArray();
312 // collect the names of all _actually_existent_ controls
313 for ( ControlDescIterator aControl
= s_pControls
; aControl
!= s_pControlsEnd
; ++aControl
)
315 if ( m_pFilePickerController
->getControl( aControl
->nControlId
) )
316 *pControls
++ = ::rtl::OUString::createFromAscii( aControl
->pControlName
);
319 aControls
.realloc( pControls
- aControls
.getArray() );
323 // --------------------------------------------------------------------------
324 Sequence
< ::rtl::OUString
> OControlAccess::getSupportedControlProperties( const ::rtl::OUString
& _rControlName
)
326 sal_Int16 nControlId
= -1;
327 sal_Int32 nPropertyMask
= 0;
328 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
329 // will throw an IllegalArgumentException if the name is not valid
331 // fill in the property names
332 Sequence
< ::rtl::OUString
> aProps( s_nPropertyCount
);
333 ::rtl::OUString
* pProperty
= aProps
.getArray();
335 for ( ControlPropertyIterator aProp
= s_pProperties
; aProp
!= s_pPropertiesEnd
; ++aProp
)
336 if ( 0 != ( nPropertyMask
& aProp
->nPropertyId
) )
337 *pProperty
++ = ::rtl::OUString::createFromAscii( aProp
->pPropertyName
);
339 aProps
.realloc( pProperty
- aProps
.getArray() );
343 // --------------------------------------------------------------------------
344 sal_Bool
OControlAccess::isControlSupported( const ::rtl::OUString
& _rControlName
)
346 return ::std::binary_search( s_pControls
, s_pControlsEnd
, _rControlName
, ControlDescriptionLookup() );
349 // --------------------------------------------------------------------------
350 sal_Bool
OControlAccess::isControlPropertySupported( const ::rtl::OUString
& _rControlName
, const ::rtl::OUString
& _rControlProperty
)
352 // look up the control
353 sal_Int16 nControlId
= -1;
354 sal_Int32 nPropertyMask
= 0;
355 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
356 // will throw an IllegalArgumentException if the name is not valid
358 // look up the property
359 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
360 if ( aPropDesc
== s_pPropertiesEnd
)
361 // it's a property which is completely unknown
364 return 0 != ( aPropDesc
->nPropertyId
& nPropertyMask
);
367 //-----------------------------------------------------------------------------
368 void OControlAccess::setValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
, const Any
& _rValue
)
370 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
);
371 DBG_ASSERT( pControl
, "OControlAccess::SetValue: don't have this control in the current mode!" );
374 sal_Int16 nPropertyId
= -1;
375 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
377 nPropertyId
= PROPERTY_FLAG_HELPURL
;
381 switch ( _nControlId
)
383 case CHECKBOX_AUTOEXTENSION
:
384 case CHECKBOX_PASSWORD
:
385 case CHECKBOX_FILTEROPTIONS
:
386 case CHECKBOX_READONLY
:
388 case CHECKBOX_PREVIEW
:
389 case CHECKBOX_SELECTION
:
390 nPropertyId
= PROPERTY_FLAG_CHECKED
;
394 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
397 case LISTBOX_VERSION
:
398 case LISTBOX_TEMPLATE
:
399 case LISTBOX_IMAGE_TEMPLATE
:
400 if ( ControlActions::SET_SELECT_ITEM
== _nControlAction
)
402 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
406 DBG_ASSERT( WINDOW_LISTBOX
== pControl
->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" );
407 implDoListboxAction( static_cast< ListBox
* >( pControl
), _nControlAction
, _rValue
);
413 if ( -1 != nPropertyId
)
414 implSetControlProperty( _nControlId
, pControl
, nPropertyId
, _rValue
);
418 //-----------------------------------------------------------------------------
419 Any
OControlAccess::getValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
) const
423 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
, sal_False
);
424 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
427 sal_Int16 nPropertyId
= -1;
428 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
430 nPropertyId
= PROPERTY_FLAG_HELPURL
;
434 switch ( _nControlId
)
436 case CHECKBOX_AUTOEXTENSION
:
437 case CHECKBOX_PASSWORD
:
438 case CHECKBOX_FILTEROPTIONS
:
439 case CHECKBOX_READONLY
:
441 case CHECKBOX_PREVIEW
:
442 case CHECKBOX_SELECTION
:
443 nPropertyId
= PROPERTY_FLAG_CHECKED
;
447 if ( ControlActions::GET_SELECTED_ITEM
== _nControlAction
)
449 aRet
<<= ::rtl::OUString( m_pFilePickerController
->getCurFilter() );;
453 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
457 case LISTBOX_VERSION
:
458 case LISTBOX_TEMPLATE
:
459 case LISTBOX_IMAGE_TEMPLATE
:
460 switch ( _nControlAction
)
462 case ControlActions::GET_SELECTED_ITEM
:
463 nPropertyId
= PROPERTY_FLAG_SELECTEDITEM
;
465 case ControlActions::GET_SELECTED_ITEM_INDEX
:
466 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
468 case ControlActions::GET_ITEMS
:
469 nPropertyId
= PROPERTY_FLAG_LISTITEMS
;
472 DBG_ERRORFILE( "OControlAccess::GetValue: invalid control action for the listbox!" );
479 if ( -1 != nPropertyId
)
480 aRet
= implGetControlProperty( pControl
, nPropertyId
);
486 //-----------------------------------------------------------------------------
487 void OControlAccess::setLabel( sal_Int16 nId
, const ::rtl::OUString
&rLabel
)
489 Control
* pControl
= m_pFilePickerController
->getControl( nId
, sal_True
);
490 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
492 pControl
->SetText( rLabel
);
495 //-----------------------------------------------------------------------------
496 ::rtl::OUString
OControlAccess::getLabel( sal_Int16 nId
) const
498 ::rtl::OUString sLabel
;
500 Control
* pControl
= m_pFilePickerController
->getControl( nId
, sal_True
);
501 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
503 sLabel
= pControl
->GetText();
508 //-----------------------------------------------------------------------------
509 void OControlAccess::enableControl( sal_Int16 _nId
, sal_Bool _bEnable
)
511 m_pFilePickerController
->enableControl( _nId
, _bEnable
);
514 // -----------------------------------------------------------------------
515 void OControlAccess::implDoListboxAction( ListBox
* _pListbox
, sal_Int16 _nControlAction
, const Any
& _rValue
)
517 switch ( _nControlAction
)
519 case ControlActions::ADD_ITEM
:
521 ::rtl::OUString aEntry
;
523 if ( aEntry
.getLength() )
524 _pListbox
->InsertEntry( aEntry
);
528 case ControlActions::ADD_ITEMS
:
530 Sequence
< ::rtl::OUString
> aTemplateList
;
531 _rValue
>>= aTemplateList
;
533 if ( aTemplateList
.getLength() )
535 for ( long i
=0; i
< aTemplateList
.getLength(); i
++ )
536 _pListbox
->InsertEntry( aTemplateList
[i
] );
541 case ControlActions::DELETE_ITEM
:
544 if ( _rValue
>>= nPos
)
545 _pListbox
->RemoveEntry( (USHORT
) nPos
);
549 case ControlActions::DELETE_ITEMS
:
554 DBG_ERRORFILE( "Wrong ControlAction for implDoListboxAction()" );
558 //-----------------------------------------------------------------------------
559 void OControlAccess::implSetControlProperty( sal_Int16 _nControlId
, Control
* _pControl
, sal_Int16 _nProperty
, const Any
& _rValue
, sal_Bool _bIgnoreIllegalArgument
)
562 _pControl
= m_pFilePickerController
->getControl( _nControlId
);
563 DBG_ASSERT( _pControl
, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
567 DBG_ASSERT( _pControl
== m_pFilePickerController
->getControl( _nControlId
),
568 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
570 switch ( _nProperty
)
572 case PROPERTY_FLAG_TEXT
:
574 ::rtl::OUString sText
;
575 if ( _rValue
>>= sText
)
577 _pControl
->SetText( sText
);
579 else if ( !_bIgnoreIllegalArgument
)
581 lcl_throwIllegalArgumentException();
586 case PROPERTY_FLAG_ENDBALED
:
588 sal_Bool bEnabled
= sal_False
;
589 if ( _rValue
>>= bEnabled
)
591 m_pFilePickerController
->enableControl( _nControlId
, bEnabled
);
593 else if ( !_bIgnoreIllegalArgument
)
595 lcl_throwIllegalArgumentException();
600 case PROPERTY_FLAG_VISIBLE
:
602 sal_Bool bVisible
= sal_False
;
603 if ( _rValue
>>= bVisible
)
605 _pControl
->Show( bVisible
);
607 else if ( !_bIgnoreIllegalArgument
)
609 lcl_throwIllegalArgumentException();
614 case PROPERTY_FLAG_HELPURL
:
616 ::rtl::OUString sHelpURL
;
617 if ( _rValue
>>= sHelpURL
)
619 setHelpURL( _pControl
, sHelpURL
, m_pFileView
== _pControl
);
621 else if ( !_bIgnoreIllegalArgument
)
623 lcl_throwIllegalArgumentException();
628 case PROPERTY_FLAG_LISTITEMS
:
630 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
631 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
633 Sequence
< ::rtl::OUString
> aItems
;
634 if ( _rValue
>>= aItems
)
636 // remove all previous items
637 static_cast< ListBox
* >( _pControl
)->Clear();
640 const ::rtl::OUString
* pItems
= aItems
.getConstArray();
641 const ::rtl::OUString
* pItemsEnd
= aItems
.getConstArray() + aItems
.getLength();
642 for ( const ::rtl::OUString
* pItem
= pItems
;
647 static_cast< ListBox
* >( _pControl
)->InsertEntry( *pItem
);
651 else if ( !_bIgnoreIllegalArgument
)
653 lcl_throwIllegalArgumentException();
658 case PROPERTY_FLAG_SELECTEDITEM
:
660 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
661 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
663 ::rtl::OUString sSelected
;
664 if ( _rValue
>>= sSelected
)
666 static_cast< ListBox
* >( _pControl
)->SelectEntry( sSelected
);
668 else if ( !_bIgnoreIllegalArgument
)
670 lcl_throwIllegalArgumentException();
675 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
677 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
678 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
681 if ( _rValue
>>= nPos
)
683 static_cast< ListBox
* >( _pControl
)->SelectEntryPos( (USHORT
) nPos
);
685 else if ( !_bIgnoreIllegalArgument
)
687 lcl_throwIllegalArgumentException();
692 case PROPERTY_FLAG_CHECKED
:
694 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
695 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
697 sal_Bool bChecked
= sal_False
;
698 if ( _rValue
>>= bChecked
)
700 static_cast< CheckBox
* >( _pControl
)->Check( bChecked
);
702 else if ( !_bIgnoreIllegalArgument
)
704 lcl_throwIllegalArgumentException();
710 DBG_ERROR( "OControlAccess::implSetControlProperty: invalid property id!" );
714 //-----------------------------------------------------------------------------
715 Any
OControlAccess::implGetControlProperty( Control
* _pControl
, sal_Int16 _nProperty
) const
717 DBG_ASSERT( _pControl
, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" );
720 switch ( _nProperty
)
722 case PROPERTY_FLAG_TEXT
:
723 aReturn
<<= ::rtl::OUString( _pControl
->GetText() );
726 case PROPERTY_FLAG_ENDBALED
:
727 aReturn
<<= (sal_Bool
)_pControl
->IsEnabled();
730 case PROPERTY_FLAG_VISIBLE
:
731 aReturn
<<= (sal_Bool
)_pControl
->IsVisible();
734 case PROPERTY_FLAG_HELPURL
:
735 aReturn
<<= getHelpURL( _pControl
, m_pFileView
== _pControl
);
738 case PROPERTY_FLAG_LISTITEMS
:
740 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
741 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
743 Sequence
< ::rtl::OUString
> aItems( static_cast< ListBox
* >( _pControl
)->GetEntryCount() );
744 ::rtl::OUString
* pItems
= aItems
.getArray();
745 for ( USHORT i
=0; i
<static_cast< ListBox
* >( _pControl
)->GetEntryCount(); ++i
)
746 *pItems
++ = static_cast< ListBox
* >( _pControl
)->GetEntry( i
);
752 case PROPERTY_FLAG_SELECTEDITEM
:
754 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
755 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
757 USHORT nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
758 ::rtl::OUString sSelected
;
759 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
760 sSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntry();
761 aReturn
<<= sSelected
;
765 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
767 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
768 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
770 USHORT nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
771 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
772 aReturn
<<= (sal_Int32
)static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
774 aReturn
<<= (sal_Int32
)-1;
778 case PROPERTY_FLAG_CHECKED
:
779 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
780 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
782 aReturn
<<= (sal_Bool
)static_cast< CheckBox
* >( _pControl
)->IsChecked( );
786 DBG_ERROR( "OControlAccess::implGetControlProperty: invalid property id!" );
791 //.........................................................................
793 //.........................................................................