1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
38 // helper -------------------------------------------------------------
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::ui::dialogs
;
44 using namespace ExtendedFilePickerElementIds
;
45 using namespace CommonFilePickerElementIds
;
46 using namespace InternalFilePickerElementIds
;
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
62 struct ControlDescription
64 const sal_Char
* pControlName
;
66 sal_Int32 nPropertyFlags
;
70 typedef const ControlDescription
* ControlDescIterator
;
71 typedef ::std::pair
< ControlDescIterator
, ControlDescIterator
> ControlDescRange
;
74 #define PROPERTY_FLAGS_COMMON ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL )
75 #define PROPERTY_FLAGS_LISTBOX ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX )
76 #define PROPERTY_FLAGS_CHECKBOX ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT )
78 // Note: this array MUST be sorted by name!
79 static const ControlDescription aDescriptions
[] = {
80 { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
81 { "CancelButton", PUSHBUTTON_CANCEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
82 { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
83 { "DefaultLocationButton", TOOLBOXBUTOON_DEFAULT_LOCATION
, PROPERTY_FLAGS_COMMON
},
84 { "FileURLEdit", EDIT_FILEURL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
85 { "FileURLEditLabel", EDIT_FILEURL_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
86 { "FileView", CONTROL_FILEVIEW
, PROPERTY_FLAGS_COMMON
},
87 { "FilterList", LISTBOX_FILTER
, PROPERTY_FLAGS_COMMON
},
88 { "FilterListLabel", LISTBOX_FILTER_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
89 { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
90 { "HelpButton", PUSHBUTTON_HELP
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
91 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
92 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
93 { "LevelUpButton", TOOLBOXBUTOON_LEVEL_UP
, PROPERTY_FLAGS_COMMON
},
94 { "LinkBox", CHECKBOX_LINK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
95 { "NewFolderButton", TOOLBOXBUTOON_NEW_FOLDER
, PROPERTY_FLAGS_COMMON
},
96 { "OkButton", PUSHBUTTON_OK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
97 { "PasswordBox", CHECKBOX_PASSWORD
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
98 { "PlayButton", PUSHBUTTON_PLAY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
99 { "PreviewBox", CHECKBOX_PREVIEW
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
100 { "ReadOnlyBox", CHECKBOX_READONLY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
101 { "SelectionBox", CHECKBOX_SELECTION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
102 { "TemplateList", LISTBOX_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
103 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
104 { "VersionList", LISTBOX_VERSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
105 { "VersionListLabel", LISTBOX_VERSION_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
}
109 static const sal_Int32 s_nControlCount
= SAL_N_ELEMENTS( aDescriptions
);
111 static ControlDescIterator s_pControls
= aDescriptions
;
112 static ControlDescIterator s_pControlsEnd
= aDescriptions
+ s_nControlCount
;
115 struct ControlDescriptionLookup
117 bool operator()( const ControlDescription
& _rDesc1
, const ControlDescription
& _rDesc2
)
119 return strcmp(_rDesc1
.pControlName
, _rDesc2
.pControlName
) < 0;
124 struct ControlProperty
126 const sal_Char
* pPropertyName
;
127 sal_Int16 nPropertyId
;
130 typedef const ControlProperty
* ControlPropertyIterator
;
133 static const ControlProperty aProperties
[] = {
134 { "Text", PROPERTY_FLAG_TEXT
},
135 { "Enabled", PROPERTY_FLAG_ENDBALED
},
136 { "Visible", PROPERTY_FLAG_VISIBLE
},
137 { "HelpURL", PROPERTY_FLAG_HELPURL
},
138 { "ListItems", PROPERTY_FLAG_LISTITEMS
},
139 { "SelectedItem", PROPERTY_FLAG_SELECTEDITEM
},
140 { "SelectedItemIndex", PROPERTY_FLAG_SELECTEDITEMINDEX
},
141 { "Checked", PROPERTY_FLAG_CHECKED
}
145 static const int s_nPropertyCount
= SAL_N_ELEMENTS( aProperties
);
147 static ControlPropertyIterator s_pProperties
= aProperties
;
148 static ControlPropertyIterator s_pPropertiesEnd
= aProperties
+ s_nPropertyCount
;
151 struct ControlPropertyLookup
154 explicit ControlPropertyLookup(const OUString
& rLookup
)
159 bool operator()(const ControlProperty
& rProp
)
161 return m_sLookup
.equalsAscii(rProp
.pPropertyName
);
166 void lcl_throwIllegalArgumentException( )
168 throw IllegalArgumentException();
169 // TODO: error message in the exception
174 OControlAccess::OControlAccess( IFilePickerController
* _pController
, SvtFileView
* _pFileView
)
175 :m_pFilePickerController( _pController
)
176 ,m_pFileView( _pFileView
)
178 DBG_ASSERT( m_pFilePickerController
, "OControlAccess::OControlAccess: invalid control locator!" );
182 void OControlAccess::setHelpURL( vcl::Window
* _pControl
, const OUString
& sHelpURL
, bool _bFileView
)
184 OUString
sHelpID( sHelpURL
);
185 INetURLObject
aHID( sHelpURL
);
186 if ( aHID
.GetProtocol() == INetProtocol::Hid
)
187 sHelpID
= aHID
.GetURLPath();
189 // URLs should always be UTF8 encoded and escaped
190 OString
sID( OUStringToOString( sHelpID
, RTL_TEXTENCODING_UTF8
) );
192 // the file view "overrides" the SetHelpId
193 static_cast< SvtFileView
* >( _pControl
)->SetHelpId( sID
);
195 _pControl
->SetHelpId( sID
);
199 OUString
OControlAccess::getHelpURL( vcl::Window
* _pControl
, bool _bFileView
)
201 OString aHelpId
= _pControl
->GetHelpId();
203 // the file view "overrides" the SetHelpId
204 aHelpId
= static_cast< SvtFileView
* >( _pControl
)->GetHelpId( );
207 OUString
aTmp( OStringToOUString( aHelpId
, RTL_TEXTENCODING_UTF8
) );
208 INetURLObject
aHID( aTmp
);
209 if ( aHID
.GetProtocol() == INetProtocol::NotValid
)
210 sHelpURL
= INET_HID_SCHEME
;
216 Any
OControlAccess::getControlProperty( const OUString
& _rControlName
, const OUString
& _rControlProperty
)
218 // look up the control
219 sal_Int16 nControlId
= -1;
220 sal_Int32 nPropertyMask
= 0;
221 Control
* pControl
= implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
222 // will throw an IllegalArgumentException if the name is not valid
224 // look up the property
225 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
226 if ( aPropDesc
== s_pPropertiesEnd
)
227 // it's a completely unknown property
228 lcl_throwIllegalArgumentException();
230 if ( 0 == ( nPropertyMask
& aPropDesc
->nPropertyId
) )
231 // it's a property which is known, but not allowed for this control
232 lcl_throwIllegalArgumentException();
234 return implGetControlProperty( pControl
, aPropDesc
->nPropertyId
);
238 Control
* OControlAccess::implGetControl( const OUString
& _rControlName
, sal_Int16
* _pId
, sal_Int32
* _pPropertyMask
) const
240 Control
* pControl
= nullptr;
241 ControlDescription tmpDesc
;
242 OString aControlName
= OUStringToOString( _rControlName
, RTL_TEXTENCODING_UTF8
);
243 tmpDesc
.pControlName
= aControlName
.getStr();
245 // translate the name into an id
246 ControlDescRange aFoundRange
= ::std::equal_range( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
247 if ( aFoundRange
.first
!= aFoundRange
.second
)
249 // get the VCL control determined by this id
250 pControl
= m_pFilePickerController
->getControl( aFoundRange
.first
->nControlId
);
253 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
255 lcl_throwIllegalArgumentException();
257 // out parameters and outta here
259 *_pId
= aFoundRange
.first
->nControlId
;
260 if ( _pPropertyMask
)
261 *_pPropertyMask
= aFoundRange
.first
->nPropertyFlags
;
267 void OControlAccess::setControlProperty( const OUString
& _rControlName
, const OUString
& _rControlProperty
, const css::uno::Any
& _rValue
)
269 // look up the control
270 sal_Int16 nControlId
= -1;
271 Control
* pControl
= implGetControl( _rControlName
, &nControlId
);
272 // will throw an IllegalArgumentException if the name is not valid
274 // look up the property
275 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
276 if ( aPropDesc
== s_pPropertiesEnd
)
277 lcl_throwIllegalArgumentException();
280 implSetControlProperty( nControlId
, pControl
, aPropDesc
->nPropertyId
, _rValue
, false );
284 Sequence
< OUString
> OControlAccess::getSupportedControls( )
286 Sequence
< OUString
> aControls( s_nControlCount
);
287 OUString
* pControls
= aControls
.getArray();
289 // collect the names of all _actually_existent_ controls
290 for ( ControlDescIterator aControl
= s_pControls
; aControl
!= s_pControlsEnd
; ++aControl
)
292 if ( m_pFilePickerController
->getControl( aControl
->nControlId
) )
293 *pControls
++ = OUString::createFromAscii( aControl
->pControlName
);
296 aControls
.realloc( pControls
- aControls
.getArray() );
301 Sequence
< OUString
> OControlAccess::getSupportedControlProperties( const OUString
& _rControlName
)
303 sal_Int16 nControlId
= -1;
304 sal_Int32 nPropertyMask
= 0;
305 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
306 // will throw an IllegalArgumentException if the name is not valid
308 // fill in the property names
309 Sequence
< OUString
> aProps( s_nPropertyCount
);
310 OUString
* pProperty
= aProps
.getArray();
312 for ( ControlPropertyIterator aProp
= s_pProperties
; aProp
!= s_pPropertiesEnd
; ++aProp
)
313 if ( 0 != ( nPropertyMask
& aProp
->nPropertyId
) )
314 *pProperty
++ = OUString::createFromAscii( aProp
->pPropertyName
);
316 aProps
.realloc( pProperty
- aProps
.getArray() );
321 bool OControlAccess::isControlSupported( const OUString
& _rControlName
)
323 ControlDescription tmpDesc
;
324 OString aControlName
= OUStringToOString(_rControlName
, RTL_TEXTENCODING_UTF8
);
325 tmpDesc
.pControlName
= aControlName
.getStr();
326 return ::std::binary_search( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
330 bool OControlAccess::isControlPropertySupported( const OUString
& _rControlName
, const OUString
& _rControlProperty
)
332 // look up the control
333 sal_Int16 nControlId
= -1;
334 sal_Int32 nPropertyMask
= 0;
335 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
336 // will throw an IllegalArgumentException if the name is not valid
338 // look up the property
339 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
340 if ( aPropDesc
== s_pPropertiesEnd
)
341 // it's a property which is completely unknown
344 return 0 != ( aPropDesc
->nPropertyId
& nPropertyMask
);
348 void OControlAccess::setValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
, const Any
& _rValue
)
350 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
);
351 DBG_ASSERT( pControl
, "OControlAccess::SetValue: don't have this control in the current mode!" );
354 sal_Int16 nPropertyId
= -1;
355 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
357 nPropertyId
= PROPERTY_FLAG_HELPURL
;
361 switch ( _nControlId
)
363 case CHECKBOX_AUTOEXTENSION
:
364 case CHECKBOX_PASSWORD
:
365 case CHECKBOX_FILTEROPTIONS
:
366 case CHECKBOX_READONLY
:
368 case CHECKBOX_PREVIEW
:
369 case CHECKBOX_SELECTION
:
370 nPropertyId
= PROPERTY_FLAG_CHECKED
;
374 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
377 case LISTBOX_VERSION
:
378 case LISTBOX_TEMPLATE
:
379 case LISTBOX_IMAGE_TEMPLATE
:
380 if ( ControlActions::SET_SELECT_ITEM
== _nControlAction
)
382 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
386 DBG_ASSERT( WINDOW_LISTBOX
== pControl
->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" );
387 implDoListboxAction( static_cast< ListBox
* >( pControl
), _nControlAction
, _rValue
);
393 if ( -1 != nPropertyId
)
394 implSetControlProperty( _nControlId
, pControl
, nPropertyId
, _rValue
);
399 Any
OControlAccess::getValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
) const
403 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
);
404 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
407 sal_Int16 nPropertyId
= -1;
408 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
410 nPropertyId
= PROPERTY_FLAG_HELPURL
;
414 switch ( _nControlId
)
416 case CHECKBOX_AUTOEXTENSION
:
417 case CHECKBOX_PASSWORD
:
418 case CHECKBOX_FILTEROPTIONS
:
419 case CHECKBOX_READONLY
:
421 case CHECKBOX_PREVIEW
:
422 case CHECKBOX_SELECTION
:
423 nPropertyId
= PROPERTY_FLAG_CHECKED
;
427 if ( ControlActions::GET_SELECTED_ITEM
== _nControlAction
)
429 aRet
<<= OUString( m_pFilePickerController
->getCurFilter() );
433 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
437 case LISTBOX_VERSION
:
438 case LISTBOX_TEMPLATE
:
439 case LISTBOX_IMAGE_TEMPLATE
:
440 switch ( _nControlAction
)
442 case ControlActions::GET_SELECTED_ITEM
:
443 nPropertyId
= PROPERTY_FLAG_SELECTEDITEM
;
445 case ControlActions::GET_SELECTED_ITEM_INDEX
:
446 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
448 case ControlActions::GET_ITEMS
:
449 nPropertyId
= PROPERTY_FLAG_LISTITEMS
;
452 SAL_WARN( "fpicker.office", "OControlAccess::GetValue: invalid control action for the listbox!" );
459 if ( -1 != nPropertyId
)
460 aRet
= implGetControlProperty( pControl
, nPropertyId
);
467 void OControlAccess::setLabel( sal_Int16 nId
, const OUString
&rLabel
)
469 Control
* pControl
= m_pFilePickerController
->getControl( nId
, true );
470 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
472 pControl
->SetText( rLabel
);
476 OUString
OControlAccess::getLabel( sal_Int16 nId
) const
480 Control
* pControl
= m_pFilePickerController
->getControl( nId
, true );
481 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
483 sLabel
= pControl
->GetText();
489 void OControlAccess::enableControl( sal_Int16 _nId
, bool _bEnable
)
491 m_pFilePickerController
->enableControl( _nId
, _bEnable
);
495 void OControlAccess::implDoListboxAction( ListBox
* _pListbox
, sal_Int16 _nControlAction
, const Any
& _rValue
)
497 switch ( _nControlAction
)
499 case ControlActions::ADD_ITEM
:
503 if ( !aEntry
.isEmpty() )
504 _pListbox
->InsertEntry( aEntry
);
508 case ControlActions::ADD_ITEMS
:
510 Sequence
< OUString
> aTemplateList
;
511 _rValue
>>= aTemplateList
;
513 if ( aTemplateList
.getLength() )
515 for ( long i
=0; i
< aTemplateList
.getLength(); i
++ )
516 _pListbox
->InsertEntry( aTemplateList
[i
] );
521 case ControlActions::DELETE_ITEM
:
524 if ( _rValue
>>= nPos
)
525 _pListbox
->RemoveEntry( nPos
);
529 case ControlActions::DELETE_ITEMS
:
534 SAL_WARN( "fpicker.office", "Wrong ControlAction for implDoListboxAction()" );
539 void OControlAccess::implSetControlProperty( sal_Int16 _nControlId
, Control
* _pControl
, sal_Int16 _nProperty
, const Any
& _rValue
, bool _bIgnoreIllegalArgument
)
542 _pControl
= m_pFilePickerController
->getControl( _nControlId
);
543 DBG_ASSERT( _pControl
, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
547 DBG_ASSERT( _pControl
== m_pFilePickerController
->getControl( _nControlId
),
548 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
550 switch ( _nProperty
)
552 case PROPERTY_FLAG_TEXT
:
555 if ( _rValue
>>= sText
)
557 _pControl
->SetText( sText
);
559 else if ( !_bIgnoreIllegalArgument
)
561 lcl_throwIllegalArgumentException();
566 case PROPERTY_FLAG_ENDBALED
:
568 bool bEnabled
= false;
569 if ( _rValue
>>= bEnabled
)
571 m_pFilePickerController
->enableControl( _nControlId
, bEnabled
);
573 else if ( !_bIgnoreIllegalArgument
)
575 lcl_throwIllegalArgumentException();
580 case PROPERTY_FLAG_VISIBLE
:
582 bool bVisible
= false;
583 if ( _rValue
>>= bVisible
)
585 _pControl
->Show( bVisible
);
587 else if ( !_bIgnoreIllegalArgument
)
589 lcl_throwIllegalArgumentException();
594 case PROPERTY_FLAG_HELPURL
:
597 if ( _rValue
>>= sHelpURL
)
599 setHelpURL( _pControl
, sHelpURL
, m_pFileView
== _pControl
);
601 else if ( !_bIgnoreIllegalArgument
)
603 lcl_throwIllegalArgumentException();
608 case PROPERTY_FLAG_LISTITEMS
:
610 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
611 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
613 Sequence
< OUString
> aItems
;
614 if ( _rValue
>>= aItems
)
616 // remove all previous items
617 static_cast< ListBox
* >( _pControl
)->Clear();
620 const OUString
* pItems
= aItems
.getConstArray();
621 const OUString
* pItemsEnd
= aItems
.getConstArray() + aItems
.getLength();
622 for ( const OUString
* pItem
= pItems
;
627 static_cast< ListBox
* >( _pControl
)->InsertEntry( *pItem
);
631 else if ( !_bIgnoreIllegalArgument
)
633 lcl_throwIllegalArgumentException();
638 case PROPERTY_FLAG_SELECTEDITEM
:
640 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
641 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
644 if ( _rValue
>>= sSelected
)
646 static_cast< ListBox
* >( _pControl
)->SelectEntry( sSelected
);
648 else if ( !_bIgnoreIllegalArgument
)
650 lcl_throwIllegalArgumentException();
655 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
657 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
658 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
661 if ( _rValue
>>= nPos
)
663 static_cast< ListBox
* >( _pControl
)->SelectEntryPos( nPos
);
665 else if ( !_bIgnoreIllegalArgument
)
667 lcl_throwIllegalArgumentException();
672 case PROPERTY_FLAG_CHECKED
:
674 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
675 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
677 bool bChecked
= false;
678 if ( _rValue
>>= bChecked
)
680 static_cast< CheckBox
* >( _pControl
)->Check( bChecked
);
682 else if ( !_bIgnoreIllegalArgument
)
684 lcl_throwIllegalArgumentException();
690 OSL_FAIL( "OControlAccess::implSetControlProperty: invalid property id!" );
695 Any
OControlAccess::implGetControlProperty( Control
* _pControl
, sal_Int16 _nProperty
) const
697 DBG_ASSERT( _pControl
, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" );
700 switch ( _nProperty
)
702 case PROPERTY_FLAG_TEXT
:
703 aReturn
<<= OUString( _pControl
->GetText() );
706 case PROPERTY_FLAG_ENDBALED
:
707 aReturn
<<= _pControl
->IsEnabled();
710 case PROPERTY_FLAG_VISIBLE
:
711 aReturn
<<= _pControl
->IsVisible();
714 case PROPERTY_FLAG_HELPURL
:
715 aReturn
<<= getHelpURL( _pControl
, m_pFileView
== _pControl
);
718 case PROPERTY_FLAG_LISTITEMS
:
720 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
721 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
723 Sequence
< OUString
> aItems( static_cast< ListBox
* >( _pControl
)->GetEntryCount() );
724 OUString
* pItems
= aItems
.getArray();
725 for ( sal_Int32 i
=0; i
<static_cast< ListBox
* >( _pControl
)->GetEntryCount(); ++i
)
726 *pItems
++ = static_cast< ListBox
* >( _pControl
)->GetEntry( i
);
732 case PROPERTY_FLAG_SELECTEDITEM
:
734 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
735 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
737 sal_Int32 nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
739 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
740 sSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntry();
741 aReturn
<<= sSelected
;
745 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
747 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
748 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
750 sal_Int32 nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
751 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
752 aReturn
<<= (sal_Int32
)static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
754 aReturn
<<= (sal_Int32
)-1;
758 case PROPERTY_FLAG_CHECKED
:
759 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
760 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
762 aReturn
<<= static_cast< CheckBox
* >( _pControl
)->IsChecked( );
766 OSL_FAIL( "OControlAccess::implGetControlProperty: invalid property id!" );
775 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */