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 <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <sal/log.hxx>
28 #include <osl/diagnose.h>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <tools/urlobj.hxx>
31 #include <tools/debug.hxx>
41 // helper -------------------------------------------------------------
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::lang
;
45 using namespace ::com::sun::star::ui::dialogs
;
47 using namespace ExtendedFilePickerElementIds
;
48 using namespace CommonFilePickerElementIds
;
49 using namespace InternalFilePickerElementIds
;
55 struct ControlDescription
57 const char* pControlName
;
59 PropFlags nPropertyFlags
;
63 typedef const ControlDescription
* ControlDescIterator
;
66 #define PROPERTY_FLAGS_COMMON ( PropFlags::Enabled | PropFlags::Visible | PropFlags::HelpUrl )
67 #define PROPERTY_FLAGS_LISTBOX ( PropFlags::ListItems | PropFlags::SelectedItem | PropFlags::SelectedItemIndex )
68 #define PROPERTY_FLAGS_CHECKBOX ( PropFlags::Checked | PropFlags::Text )
70 // Note: this array MUST be sorted by name!
71 const ControlDescription aDescriptions
[] = {
72 { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
73 { "CancelButton", PUSHBUTTON_CANCEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
74 { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
75 { "FileURLEdit", EDIT_FILEURL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
76 { "FileURLEditLabel", EDIT_FILEURL_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
77 { "FileView", CONTROL_FILEVIEW
, PROPERTY_FLAGS_COMMON
},
78 { "FilterList", LISTBOX_FILTER
, PROPERTY_FLAGS_COMMON
},
79 { "FilterListLabel", LISTBOX_FILTER_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
80 { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
81 { "GpgPassword", CHECKBOX_GPGENCRYPTION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
82 { "HelpButton", PUSHBUTTON_HELP
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
83 { "ImageAnchorList", LISTBOX_IMAGE_ANCHOR
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
84 { "ImageAnchorListLabel", LISTBOX_IMAGE_ANCHOR_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
85 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
86 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
87 { "LevelUpButton", TOOLBOXBUTTON_LEVEL_UP
, PROPERTY_FLAGS_COMMON
},
88 { "LinkBox", CHECKBOX_LINK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
89 { "NewFolderButton", TOOLBOXBUTTON_NEW_FOLDER
, PROPERTY_FLAGS_COMMON
},
90 { "OkButton", PUSHBUTTON_OK
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
91 { "PasswordBox", CHECKBOX_PASSWORD
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
92 { "PlayButton", PUSHBUTTON_PLAY
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
93 { "PreviewBox", CHECKBOX_PREVIEW
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
94 { "ReadOnlyBox", CHECKBOX_READONLY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
95 { "SelectionBox", CHECKBOX_SELECTION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
96 { "TemplateList", LISTBOX_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
97 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
98 { "VersionList", LISTBOX_VERSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
99 { "VersionListLabel", LISTBOX_VERSION_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
}
102 const sal_Int32 s_nControlCount
= SAL_N_ELEMENTS( aDescriptions
);
104 ControlDescIterator s_pControls
= aDescriptions
;
105 ControlDescIterator s_pControlsEnd
= aDescriptions
+ s_nControlCount
;
107 struct ControlDescriptionLookup
109 bool operator()( const ControlDescription
& rDesc1
, const ControlDescription
& rDesc2
)
111 return strcmp(rDesc1
.pControlName
, rDesc2
.pControlName
) < 0;
115 struct ControlProperty
117 const char* pPropertyName
;
118 PropFlags nPropertyId
;
121 typedef const ControlProperty
* ControlPropertyIterator
;
123 const ControlProperty aProperties
[] = {
124 { "Text", PropFlags::Text
},
125 { "Enabled", PropFlags::Enabled
},
126 { "Visible", PropFlags::Visible
},
127 { "HelpURL", PropFlags::HelpUrl
},
128 { "ListItems", PropFlags::ListItems
},
129 { "SelectedItem", PropFlags::SelectedItem
},
130 { "SelectedItemIndex", PropFlags::SelectedItemIndex
},
131 { "Checked", PropFlags::Checked
}
134 const int s_nPropertyCount
= SAL_N_ELEMENTS( aProperties
);
136 ControlPropertyIterator s_pProperties
= aProperties
;
137 ControlPropertyIterator s_pPropertiesEnd
= aProperties
+ s_nPropertyCount
;
140 struct ControlPropertyLookup
143 explicit ControlPropertyLookup(OUString aLookup
)
144 : m_sLookup(std::move(aLookup
))
148 bool operator()(const ControlProperty
& rProp
)
150 return m_sLookup
.equalsAscii(rProp
.pPropertyName
);
155 OControlAccess::OControlAccess(IFilePickerController
* pController
, SvtFileView
* pFileView
)
156 : m_pFilePickerController(pController
)
157 , m_pFileView(pFileView
)
159 DBG_ASSERT( m_pFilePickerController
, "OControlAccess::OControlAccess: invalid control locator!" );
162 bool OControlAccess::IsFileViewWidget(weld::Widget
const * pControl
) const
168 return pControl
== m_pFileView
->identifier();
171 void OControlAccess::setHelpURL(weld::Widget
* pControl
, const OUString
& sHelpURL
)
173 OUString
sHelpID( sHelpURL
);
174 INetURLObject
aHID( sHelpURL
);
175 if (aHID
.GetProtocol() == INetProtocol::Hid
)
176 sHelpID
= aHID
.GetURLPath();
178 // URLs should always be escaped
179 if (IsFileViewWidget(pControl
))
181 // the file view "overrides" the SetHelpId
182 m_pFileView
->set_help_id(sHelpID
);
185 pControl
->set_help_id(sHelpID
);
188 OUString
OControlAccess::getHelpURL(weld::Widget
const * pControl
) const
190 OUString aHelpId
= pControl
->get_help_id();
191 if (IsFileViewWidget(pControl
))
193 // the file view "overrides" the SetHelpId
194 aHelpId
= m_pFileView
->get_help_id();
198 INetURLObject
aHID(aHelpId
);
199 if ( aHID
.GetProtocol() == INetProtocol::NotValid
)
200 sHelpURL
= INET_HID_SCHEME
;
205 Any
OControlAccess::getControlProperty( std::u16string_view rControlName
, const OUString
& rControlProperty
)
207 // look up the control
208 sal_Int16 nControlId
= -1;
209 PropFlags nPropertyMask
= PropFlags::NONE
;
210 weld::Widget
* pControl
= implGetControl( rControlName
, &nControlId
, &nPropertyMask
);
211 // will throw an IllegalArgumentException if the name is not valid
213 // look up the property
214 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( rControlProperty
) );
215 if ( aPropDesc
== s_pPropertiesEnd
)
216 // it's a completely unknown property
217 throw IllegalArgumentException();
219 if ( !( nPropertyMask
& aPropDesc
->nPropertyId
) )
220 // it's a property which is known, but not allowed for this control
221 throw IllegalArgumentException();
223 return implGetControlProperty( pControl
, aPropDesc
->nPropertyId
);
226 weld::Widget
* OControlAccess::implGetControl( std::u16string_view rControlName
, sal_Int16
* _pId
, PropFlags
* _pPropertyMask
) const
228 weld::Widget
* pControl
= nullptr;
229 ControlDescription tmpDesc
;
230 OString aControlName
= OUStringToOString( rControlName
, RTL_TEXTENCODING_UTF8
);
231 tmpDesc
.pControlName
= aControlName
.getStr();
233 // translate the name into an id
234 auto aFoundRange
= ::std::equal_range( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
235 if ( aFoundRange
.first
!= aFoundRange
.second
)
237 // get the VCL control determined by this id
238 pControl
= m_pFilePickerController
->getControl( aFoundRange
.first
->nControlId
);
241 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
243 throw IllegalArgumentException();
245 // out parameters and outta here
247 *_pId
= aFoundRange
.first
->nControlId
;
248 if ( _pPropertyMask
)
249 *_pPropertyMask
= aFoundRange
.first
->nPropertyFlags
;
254 void OControlAccess::setControlProperty( std::u16string_view rControlName
, const OUString
& rControlProperty
, const css::uno::Any
& rValue
)
256 // look up the control
257 sal_Int16 nControlId
= -1;
258 weld::Widget
* pControl
= implGetControl( rControlName
, &nControlId
);
259 // will throw an IllegalArgumentException if the name is not valid
261 // look up the property
262 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( rControlProperty
) );
263 if ( aPropDesc
== s_pPropertiesEnd
)
264 throw IllegalArgumentException();
267 implSetControlProperty( nControlId
, pControl
, aPropDesc
->nPropertyId
, rValue
, false );
270 Sequence
< OUString
> OControlAccess::getSupportedControls( ) const
272 Sequence
< OUString
> aControls( s_nControlCount
);
273 OUString
* pControls
= aControls
.getArray();
275 // collect the names of all _actually_existent_ controls
276 for ( ControlDescIterator aControl
= s_pControls
; aControl
!= s_pControlsEnd
; ++aControl
)
278 if ( m_pFilePickerController
->getControl( aControl
->nControlId
) )
279 *pControls
++ = OUString::createFromAscii( aControl
->pControlName
);
282 aControls
.realloc( pControls
- aControls
.getArray() );
286 Sequence
< OUString
> OControlAccess::getSupportedControlProperties( std::u16string_view rControlName
)
288 sal_Int16 nControlId
= -1;
289 PropFlags nPropertyMask
= PropFlags::NONE
;
290 implGetControl( rControlName
, &nControlId
, &nPropertyMask
);
291 // will throw an IllegalArgumentException if the name is not valid
293 // fill in the property names
294 Sequence
< OUString
> aProps( s_nPropertyCount
);
295 OUString
* pProperty
= aProps
.getArray();
297 for ( ControlPropertyIterator aProp
= s_pProperties
; aProp
!= s_pPropertiesEnd
; ++aProp
)
298 if ( nPropertyMask
& aProp
->nPropertyId
)
299 *pProperty
++ = OUString::createFromAscii( aProp
->pPropertyName
);
301 aProps
.realloc( pProperty
- aProps
.getArray() );
305 bool OControlAccess::isControlSupported( std::u16string_view rControlName
)
307 ControlDescription tmpDesc
;
308 OString aControlName
= OUStringToOString(rControlName
, RTL_TEXTENCODING_UTF8
);
309 tmpDesc
.pControlName
= aControlName
.getStr();
310 return ::std::binary_search( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
313 bool OControlAccess::isControlPropertySupported( std::u16string_view rControlName
, const OUString
& rControlProperty
)
315 // look up the control
316 sal_Int16 nControlId
= -1;
317 PropFlags nPropertyMask
= PropFlags::NONE
;
318 implGetControl( rControlName
, &nControlId
, &nPropertyMask
);
319 // will throw an IllegalArgumentException if the name is not valid
321 // look up the property
322 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( rControlProperty
) );
323 if ( aPropDesc
== s_pPropertiesEnd
)
324 // it's a property which is completely unknown
327 return bool( aPropDesc
->nPropertyId
& nPropertyMask
);
330 void OControlAccess::setValue( sal_Int16 nControlId
, sal_Int16 nControlAction
, const Any
& rValue
)
332 weld::Widget
* pControl
= m_pFilePickerController
->getControl( nControlId
);
333 DBG_ASSERT( pControl
, "OControlAccess::SetValue: don't have this control in the current mode!" );
337 PropFlags nPropertyId
= PropFlags::Unknown
;
338 if ( ControlActions::SET_HELP_URL
== nControlAction
)
340 nPropertyId
= PropFlags::HelpUrl
;
344 switch ( nControlId
)
346 case CHECKBOX_AUTOEXTENSION
:
347 case CHECKBOX_PASSWORD
:
348 case CHECKBOX_FILTEROPTIONS
:
349 case CHECKBOX_READONLY
:
351 case CHECKBOX_PREVIEW
:
352 case CHECKBOX_SELECTION
:
353 nPropertyId
= PropFlags::Checked
;
357 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
360 case LISTBOX_VERSION
:
361 case LISTBOX_TEMPLATE
:
362 case LISTBOX_IMAGE_TEMPLATE
:
363 case LISTBOX_IMAGE_ANCHOR
:
364 if ( ControlActions::SET_SELECT_ITEM
== nControlAction
)
366 nPropertyId
= PropFlags::SelectedItemIndex
;
370 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
371 assert(pComboBox
&& "OControlAccess::SetValue: implGetControl returned nonsense!");
372 implDoListboxAction(pComboBox
, nControlAction
, rValue
);
378 if ( PropFlags::Unknown
!= nPropertyId
)
379 implSetControlProperty( nControlId
, pControl
, nPropertyId
, rValue
);
382 Any
OControlAccess::getValue( sal_Int16 nControlId
, sal_Int16 nControlAction
) const
386 weld::Widget
* pControl
= m_pFilePickerController
->getControl( nControlId
);
387 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
390 PropFlags nPropertyId
= PropFlags::Unknown
;
391 if ( ControlActions::SET_HELP_URL
== nControlAction
)
393 nPropertyId
= PropFlags::HelpUrl
;
397 switch ( nControlId
)
399 case CHECKBOX_AUTOEXTENSION
:
400 case CHECKBOX_PASSWORD
:
401 case CHECKBOX_GPGENCRYPTION
:
402 case CHECKBOX_FILTEROPTIONS
:
403 case CHECKBOX_READONLY
:
405 case CHECKBOX_PREVIEW
:
406 case CHECKBOX_SELECTION
:
407 nPropertyId
= PropFlags::Checked
;
411 if ( ControlActions::GET_SELECTED_ITEM
== nControlAction
)
413 aRet
<<= m_pFilePickerController
->getCurFilter();
417 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
421 case LISTBOX_VERSION
:
422 case LISTBOX_TEMPLATE
:
423 case LISTBOX_IMAGE_TEMPLATE
:
424 case LISTBOX_IMAGE_ANCHOR
:
425 switch ( nControlAction
)
427 case ControlActions::GET_SELECTED_ITEM
:
428 nPropertyId
= PropFlags::SelectedItem
;
430 case ControlActions::GET_SELECTED_ITEM_INDEX
:
431 nPropertyId
= PropFlags::SelectedItemIndex
;
433 case ControlActions::GET_ITEMS
:
434 nPropertyId
= PropFlags::ListItems
;
437 SAL_WARN( "fpicker.office", "OControlAccess::GetValue: invalid control action for the listbox!" );
444 if ( PropFlags::Unknown
!= nPropertyId
)
445 aRet
= implGetControlProperty( pControl
, nPropertyId
);
451 void OControlAccess::setLabel( sal_Int16 nId
, const OUString
&rLabel
)
453 weld::Widget
* pControl
= m_pFilePickerController
->getControl(nId
, true);
454 if (weld::Label
* pLabel
= dynamic_cast<weld::Label
*>(pControl
))
456 pLabel
->set_label(rLabel
);
459 if (weld::Button
* pButton
= dynamic_cast<weld::Button
*>(pControl
))
461 pButton
->set_label(rLabel
);
464 assert(false && "OControlAccess::GetValue: don't have this control in the current mode!");
467 OUString
OControlAccess::getLabel( sal_Int16 nId
) const
469 weld::Widget
* pControl
= m_pFilePickerController
->getControl(nId
, true);
470 if (weld::Label
* pLabel
= dynamic_cast<weld::Label
*>(pControl
))
471 return pLabel
->get_label();
472 if (weld::Button
* pButton
= dynamic_cast<weld::Button
*>(pControl
))
473 return pButton
->get_label();
474 assert(false && "OControlAccess::GetValue: don't have this control in the current mode!");
478 void OControlAccess::enableControl(sal_Int16 nId
, bool bEnable
)
480 m_pFilePickerController
->enableControl(nId
, bEnable
);
483 void OControlAccess::implDoListboxAction(weld::ComboBox
* pListbox
, sal_Int16 nControlAction
, const Any
& rValue
)
485 switch ( nControlAction
)
487 case ControlActions::ADD_ITEM
:
491 if ( !aEntry
.isEmpty() )
492 pListbox
->append_text( aEntry
);
496 case ControlActions::ADD_ITEMS
:
498 Sequence
< OUString
> aTemplateList
;
499 rValue
>>= aTemplateList
;
501 if ( aTemplateList
.hasElements() )
503 for ( const OUString
& s
: std::as_const(aTemplateList
) )
504 pListbox
->append_text( s
);
509 case ControlActions::DELETE_ITEM
:
512 if ( rValue
>>= nPos
)
513 pListbox
->remove( nPos
);
517 case ControlActions::DELETE_ITEMS
:
522 SAL_WARN( "fpicker.office", "Wrong ControlAction for implDoListboxAction()" );
526 void OControlAccess::implSetControlProperty( sal_Int16 nControlId
, weld::Widget
* pControl
, PropFlags _nProperty
, const Any
& rValue
, bool _bIgnoreIllegalArgument
)
529 pControl
= m_pFilePickerController
->getControl( nControlId
);
530 DBG_ASSERT( pControl
, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
534 DBG_ASSERT( pControl
== m_pFilePickerController
->getControl( nControlId
),
535 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
537 switch ( _nProperty
)
539 case PropFlags::Text
:
542 if (rValue
>>= sText
)
544 weld::Label
* pLabel
= dynamic_cast<weld::Label
*>(pControl
);
546 pLabel
->set_label(sText
);
548 else if ( !_bIgnoreIllegalArgument
)
550 throw IllegalArgumentException();
555 case PropFlags::Enabled
:
557 bool bEnabled
= false;
558 if ( rValue
>>= bEnabled
)
560 m_pFilePickerController
->enableControl( nControlId
, bEnabled
);
562 else if ( !_bIgnoreIllegalArgument
)
564 throw IllegalArgumentException();
569 case PropFlags::Visible
:
571 bool bVisible
= false;
572 if ( rValue
>>= bVisible
)
574 pControl
->set_visible( bVisible
);
576 else if ( !_bIgnoreIllegalArgument
)
578 throw IllegalArgumentException();
583 case PropFlags::HelpUrl
:
586 if ( rValue
>>= sHelpURL
)
588 setHelpURL(pControl
, sHelpURL
);
590 else if ( !_bIgnoreIllegalArgument
)
592 throw IllegalArgumentException();
597 case PropFlags::ListItems
:
599 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
600 assert(pComboBox
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
602 Sequence
< OUString
> aItems
;
603 if ( rValue
>>= aItems
)
605 // remove all previous items
609 for (auto const & item
: std::as_const(aItems
))
611 pComboBox
->append_text(item
);
615 else if ( !_bIgnoreIllegalArgument
)
617 throw IllegalArgumentException();
622 case PropFlags::SelectedItem
:
624 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
625 assert(pComboBox
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
628 if ( rValue
>>= sSelected
)
630 pComboBox
->set_active_text(sSelected
);
632 else if ( !_bIgnoreIllegalArgument
)
634 throw IllegalArgumentException();
639 case PropFlags::SelectedItemIndex
:
641 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
642 assert(pComboBox
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
645 if ( rValue
>>= nPos
)
647 pComboBox
->set_active(nPos
);
649 else if ( !_bIgnoreIllegalArgument
)
651 throw IllegalArgumentException();
656 case PropFlags::Checked
:
658 weld::Toggleable
* pToggleButton
= dynamic_cast<weld::Toggleable
*>(pControl
);
659 assert(pToggleButton
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
661 bool bChecked
= false;
662 if ( rValue
>>= bChecked
)
664 pToggleButton
->set_active(bChecked
);
666 else if ( !_bIgnoreIllegalArgument
)
668 throw IllegalArgumentException();
674 OSL_FAIL( "OControlAccess::implSetControlProperty: invalid property id!" );
678 Any
OControlAccess::implGetControlProperty( weld::Widget
const * pControl
, PropFlags _nProperty
) const
680 assert(pControl
&& "OControlAccess::implGetControlProperty: invalid argument, this will crash!");
683 switch ( _nProperty
)
685 case PropFlags::Text
:
687 const weld::Label
* pLabel
= dynamic_cast<const weld::Label
*>(pControl
);
689 aReturn
<<= pLabel
->get_label();
692 case PropFlags::Enabled
:
693 aReturn
<<= pControl
->get_sensitive();
696 case PropFlags::Visible
:
697 aReturn
<<= pControl
->get_visible();
700 case PropFlags::HelpUrl
:
701 aReturn
<<= getHelpURL(pControl
);
704 case PropFlags::ListItems
:
706 const weld::ComboBox
* pComboBox
= dynamic_cast<const weld::ComboBox
*>(pControl
);
707 assert(pComboBox
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
709 Sequence
< OUString
> aItems(pComboBox
->get_count());
710 OUString
* pItems
= aItems
.getArray();
711 for (sal_Int32 i
= 0; i
< pComboBox
->get_count(); ++i
)
712 *pItems
++ = pComboBox
->get_text(i
);
718 case PropFlags::SelectedItem
:
720 const weld::ComboBox
* pComboBox
= dynamic_cast<const weld::ComboBox
*>(pControl
);
721 assert(pComboBox
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
723 sal_Int32 nSelected
= pComboBox
->get_active();
726 sSelected
= pComboBox
->get_active_text();
727 aReturn
<<= sSelected
;
731 case PropFlags::SelectedItemIndex
:
733 const weld::ComboBox
* pComboBox
= dynamic_cast<const weld::ComboBox
*>(pControl
);
734 assert(pComboBox
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
736 sal_Int32 nSelected
= pComboBox
->get_active();
738 aReturn
<<= nSelected
;
740 aReturn
<<= sal_Int32(-1);
744 case PropFlags::Checked
:
746 const weld::Toggleable
* pToggleButton
= dynamic_cast<const weld::Toggleable
*>(pControl
);
747 assert(pToggleButton
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
749 aReturn
<<= pToggleButton
->get_active();
754 OSL_FAIL( "OControlAccess::implGetControlProperty: invalid property id!" );
761 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */