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 { "GpgSign", CHECKBOX_GPGSIGN
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
83 { "HelpButton", PUSHBUTTON_HELP
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
84 { "ImageAnchorList", LISTBOX_IMAGE_ANCHOR
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
85 { "ImageAnchorListLabel", LISTBOX_IMAGE_ANCHOR_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
86 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
87 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
88 { "LevelUpButton", TOOLBOXBUTTON_LEVEL_UP
, PROPERTY_FLAGS_COMMON
},
89 { "LinkBox", CHECKBOX_LINK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
90 { "NewFolderButton", TOOLBOXBUTTON_NEW_FOLDER
, PROPERTY_FLAGS_COMMON
},
91 { "OkButton", PUSHBUTTON_OK
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
92 { "PasswordBox", CHECKBOX_PASSWORD
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
93 { "PlayButton", PUSHBUTTON_PLAY
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
94 { "PreviewBox", CHECKBOX_PREVIEW
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
95 { "ReadOnlyBox", CHECKBOX_READONLY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
96 { "SelectionBox", CHECKBOX_SELECTION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
97 { "TemplateList", LISTBOX_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
98 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
},
99 { "VersionList", LISTBOX_VERSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
100 { "VersionListLabel", LISTBOX_VERSION_LABEL
, PROPERTY_FLAGS_COMMON
| PropFlags::Text
}
103 const sal_Int32 s_nControlCount
= SAL_N_ELEMENTS( aDescriptions
);
105 ControlDescIterator s_pControls
= aDescriptions
;
106 ControlDescIterator s_pControlsEnd
= aDescriptions
+ s_nControlCount
;
108 struct ControlDescriptionLookup
110 bool operator()( const ControlDescription
& rDesc1
, const ControlDescription
& rDesc2
)
112 return strcmp(rDesc1
.pControlName
, rDesc2
.pControlName
) < 0;
116 struct ControlProperty
118 const char* pPropertyName
;
119 PropFlags nPropertyId
;
122 typedef const ControlProperty
* ControlPropertyIterator
;
124 const ControlProperty aProperties
[] = {
125 { "Text", PropFlags::Text
},
126 { "Enabled", PropFlags::Enabled
},
127 { "Visible", PropFlags::Visible
},
128 { "HelpURL", PropFlags::HelpUrl
},
129 { "ListItems", PropFlags::ListItems
},
130 { "SelectedItem", PropFlags::SelectedItem
},
131 { "SelectedItemIndex", PropFlags::SelectedItemIndex
},
132 { "Checked", PropFlags::Checked
}
135 const int s_nPropertyCount
= SAL_N_ELEMENTS( aProperties
);
137 ControlPropertyIterator s_pProperties
= aProperties
;
138 ControlPropertyIterator s_pPropertiesEnd
= aProperties
+ s_nPropertyCount
;
141 struct ControlPropertyLookup
144 explicit ControlPropertyLookup(OUString aLookup
)
145 : m_sLookup(std::move(aLookup
))
149 bool operator()(const ControlProperty
& rProp
)
151 return m_sLookup
.equalsAscii(rProp
.pPropertyName
);
156 OControlAccess::OControlAccess(IFilePickerController
* pController
, SvtFileView
* pFileView
)
157 : m_pFilePickerController(pController
)
158 , m_pFileView(pFileView
)
160 DBG_ASSERT( m_pFilePickerController
, "OControlAccess::OControlAccess: invalid control locator!" );
163 bool OControlAccess::IsFileViewWidget(weld::Widget
const * pControl
) const
169 return pControl
== m_pFileView
->identifier();
172 void OControlAccess::setHelpURL(weld::Widget
* pControl
, const OUString
& sHelpURL
)
174 OUString
sHelpID( sHelpURL
);
175 INetURLObject
aHID( sHelpURL
);
176 if (aHID
.GetProtocol() == INetProtocol::Hid
)
177 sHelpID
= aHID
.GetURLPath();
179 // URLs should always be escaped
180 if (IsFileViewWidget(pControl
))
182 // the file view "overrides" the SetHelpId
183 m_pFileView
->set_help_id(sHelpID
);
186 pControl
->set_help_id(sHelpID
);
189 OUString
OControlAccess::getHelpURL(weld::Widget
const * pControl
) const
191 OUString aHelpId
= pControl
->get_help_id();
192 if (IsFileViewWidget(pControl
))
194 // the file view "overrides" the SetHelpId
195 aHelpId
= m_pFileView
->get_help_id();
199 INetURLObject
aHID(aHelpId
);
200 if ( aHID
.GetProtocol() == INetProtocol::NotValid
)
201 sHelpURL
= INET_HID_SCHEME
;
206 Any
OControlAccess::getControlProperty( std::u16string_view rControlName
, const OUString
& rControlProperty
)
208 // look up the control
209 sal_Int16 nControlId
= -1;
210 PropFlags nPropertyMask
= PropFlags::NONE
;
211 weld::Widget
* pControl
= implGetControl( rControlName
, &nControlId
, &nPropertyMask
);
212 // will throw an IllegalArgumentException if the name is not valid
214 // look up the property
215 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( rControlProperty
) );
216 if ( aPropDesc
== s_pPropertiesEnd
)
217 // it's a completely unknown property
218 throw IllegalArgumentException();
220 if ( !( nPropertyMask
& aPropDesc
->nPropertyId
) )
221 // it's a property which is known, but not allowed for this control
222 throw IllegalArgumentException();
224 return implGetControlProperty( pControl
, aPropDesc
->nPropertyId
);
227 weld::Widget
* OControlAccess::implGetControl( std::u16string_view rControlName
, sal_Int16
* _pId
, PropFlags
* _pPropertyMask
) const
229 weld::Widget
* pControl
= nullptr;
230 ControlDescription tmpDesc
;
231 OString aControlName
= OUStringToOString( rControlName
, RTL_TEXTENCODING_UTF8
);
232 tmpDesc
.pControlName
= aControlName
.getStr();
234 // translate the name into an id
235 auto aFoundRange
= ::std::equal_range( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
236 if ( aFoundRange
.first
!= aFoundRange
.second
)
238 // get the VCL control determined by this id
239 pControl
= m_pFilePickerController
->getControl( aFoundRange
.first
->nControlId
);
242 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
244 throw IllegalArgumentException();
246 // out parameters and outta here
248 *_pId
= aFoundRange
.first
->nControlId
;
249 if ( _pPropertyMask
)
250 *_pPropertyMask
= aFoundRange
.first
->nPropertyFlags
;
255 void OControlAccess::setControlProperty( std::u16string_view rControlName
, const OUString
& rControlProperty
, const css::uno::Any
& rValue
)
257 // look up the control
258 sal_Int16 nControlId
= -1;
259 weld::Widget
* pControl
= implGetControl( rControlName
, &nControlId
);
260 // will throw an IllegalArgumentException if the name is not valid
262 // look up the property
263 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( rControlProperty
) );
264 if ( aPropDesc
== s_pPropertiesEnd
)
265 throw IllegalArgumentException();
268 implSetControlProperty( nControlId
, pControl
, aPropDesc
->nPropertyId
, rValue
, false );
271 Sequence
< OUString
> OControlAccess::getSupportedControls( ) const
273 Sequence
< OUString
> aControls( s_nControlCount
);
274 OUString
* pControls
= aControls
.getArray();
276 // collect the names of all _actually_existent_ controls
277 for ( ControlDescIterator aControl
= s_pControls
; aControl
!= s_pControlsEnd
; ++aControl
)
279 if ( m_pFilePickerController
->getControl( aControl
->nControlId
) )
280 *pControls
++ = OUString::createFromAscii( aControl
->pControlName
);
283 aControls
.realloc( pControls
- aControls
.getArray() );
287 Sequence
< OUString
> OControlAccess::getSupportedControlProperties( std::u16string_view rControlName
)
289 sal_Int16 nControlId
= -1;
290 PropFlags nPropertyMask
= PropFlags::NONE
;
291 implGetControl( rControlName
, &nControlId
, &nPropertyMask
);
292 // will throw an IllegalArgumentException if the name is not valid
294 // fill in the property names
295 Sequence
< OUString
> aProps( s_nPropertyCount
);
296 OUString
* pProperty
= aProps
.getArray();
298 for ( ControlPropertyIterator aProp
= s_pProperties
; aProp
!= s_pPropertiesEnd
; ++aProp
)
299 if ( nPropertyMask
& aProp
->nPropertyId
)
300 *pProperty
++ = OUString::createFromAscii( aProp
->pPropertyName
);
302 aProps
.realloc( pProperty
- aProps
.getArray() );
306 bool OControlAccess::isControlSupported( std::u16string_view rControlName
)
308 ControlDescription tmpDesc
;
309 OString aControlName
= OUStringToOString(rControlName
, RTL_TEXTENCODING_UTF8
);
310 tmpDesc
.pControlName
= aControlName
.getStr();
311 return ::std::binary_search( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
314 bool OControlAccess::isControlPropertySupported( std::u16string_view rControlName
, const OUString
& rControlProperty
)
316 // look up the control
317 sal_Int16 nControlId
= -1;
318 PropFlags nPropertyMask
= PropFlags::NONE
;
319 implGetControl( rControlName
, &nControlId
, &nPropertyMask
);
320 // will throw an IllegalArgumentException if the name is not valid
322 // look up the property
323 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( rControlProperty
) );
324 if ( aPropDesc
== s_pPropertiesEnd
)
325 // it's a property which is completely unknown
328 return bool( aPropDesc
->nPropertyId
& nPropertyMask
);
331 void OControlAccess::setValue( sal_Int16 nControlId
, sal_Int16 nControlAction
, const Any
& rValue
)
333 weld::Widget
* pControl
= m_pFilePickerController
->getControl( nControlId
);
334 DBG_ASSERT( pControl
, "OControlAccess::SetValue: don't have this control in the current mode!" );
338 PropFlags nPropertyId
= PropFlags::Unknown
;
339 if ( ControlActions::SET_HELP_URL
== nControlAction
)
341 nPropertyId
= PropFlags::HelpUrl
;
345 switch ( nControlId
)
347 case CHECKBOX_AUTOEXTENSION
:
348 case CHECKBOX_PASSWORD
:
349 case CHECKBOX_FILTEROPTIONS
:
350 case CHECKBOX_READONLY
:
352 case CHECKBOX_PREVIEW
:
353 case CHECKBOX_SELECTION
:
354 nPropertyId
= PropFlags::Checked
;
358 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
361 case LISTBOX_VERSION
:
362 case LISTBOX_TEMPLATE
:
363 case LISTBOX_IMAGE_TEMPLATE
:
364 case LISTBOX_IMAGE_ANCHOR
:
365 if ( ControlActions::SET_SELECT_ITEM
== nControlAction
)
367 nPropertyId
= PropFlags::SelectedItemIndex
;
371 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
372 assert(pComboBox
&& "OControlAccess::SetValue: implGetControl returned nonsense!");
373 implDoListboxAction(pComboBox
, nControlAction
, rValue
);
379 if ( PropFlags::Unknown
!= nPropertyId
)
380 implSetControlProperty( nControlId
, pControl
, nPropertyId
, rValue
);
383 Any
OControlAccess::getValue( sal_Int16 nControlId
, sal_Int16 nControlAction
) const
387 weld::Widget
* pControl
= m_pFilePickerController
->getControl( nControlId
);
388 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
391 PropFlags nPropertyId
= PropFlags::Unknown
;
392 if ( ControlActions::SET_HELP_URL
== nControlAction
)
394 nPropertyId
= PropFlags::HelpUrl
;
398 switch ( nControlId
)
400 case CHECKBOX_AUTOEXTENSION
:
401 case CHECKBOX_PASSWORD
:
402 case CHECKBOX_GPGENCRYPTION
:
403 case CHECKBOX_GPGSIGN
:
404 case CHECKBOX_FILTEROPTIONS
:
405 case CHECKBOX_READONLY
:
407 case CHECKBOX_PREVIEW
:
408 case CHECKBOX_SELECTION
:
409 nPropertyId
= PropFlags::Checked
;
413 if ( ControlActions::GET_SELECTED_ITEM
== nControlAction
)
415 aRet
<<= m_pFilePickerController
->getCurFilter();
419 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
423 case LISTBOX_VERSION
:
424 case LISTBOX_TEMPLATE
:
425 case LISTBOX_IMAGE_TEMPLATE
:
426 case LISTBOX_IMAGE_ANCHOR
:
427 switch ( nControlAction
)
429 case ControlActions::GET_SELECTED_ITEM
:
430 nPropertyId
= PropFlags::SelectedItem
;
432 case ControlActions::GET_SELECTED_ITEM_INDEX
:
433 nPropertyId
= PropFlags::SelectedItemIndex
;
435 case ControlActions::GET_ITEMS
:
436 nPropertyId
= PropFlags::ListItems
;
439 SAL_WARN( "fpicker.office", "OControlAccess::GetValue: invalid control action for the listbox!" );
446 if ( PropFlags::Unknown
!= nPropertyId
)
447 aRet
= implGetControlProperty( pControl
, nPropertyId
);
453 void OControlAccess::setLabel( sal_Int16 nId
, const OUString
&rLabel
)
455 weld::Widget
* pControl
= m_pFilePickerController
->getControl(nId
, true);
456 if (weld::Label
* pLabel
= dynamic_cast<weld::Label
*>(pControl
))
458 pLabel
->set_label(rLabel
);
461 if (weld::Button
* pButton
= dynamic_cast<weld::Button
*>(pControl
))
463 pButton
->set_label(rLabel
);
466 assert(false && "OControlAccess::GetValue: don't have this control in the current mode!");
469 OUString
OControlAccess::getLabel( sal_Int16 nId
) const
471 weld::Widget
* pControl
= m_pFilePickerController
->getControl(nId
, true);
472 if (weld::Label
* pLabel
= dynamic_cast<weld::Label
*>(pControl
))
473 return pLabel
->get_label();
474 if (weld::Button
* pButton
= dynamic_cast<weld::Button
*>(pControl
))
475 return pButton
->get_label();
476 assert(false && "OControlAccess::GetValue: don't have this control in the current mode!");
480 void OControlAccess::enableControl(sal_Int16 nId
, bool bEnable
)
482 m_pFilePickerController
->enableControl(nId
, bEnable
);
485 void OControlAccess::implDoListboxAction(weld::ComboBox
* pListbox
, sal_Int16 nControlAction
, const Any
& rValue
)
487 switch ( nControlAction
)
489 case ControlActions::ADD_ITEM
:
493 if ( !aEntry
.isEmpty() )
494 pListbox
->append_text( aEntry
);
498 case ControlActions::ADD_ITEMS
:
500 Sequence
< OUString
> aTemplateList
;
501 rValue
>>= aTemplateList
;
503 if ( aTemplateList
.hasElements() )
505 for (const OUString
& s
: aTemplateList
)
506 pListbox
->append_text( s
);
511 case ControlActions::DELETE_ITEM
:
514 if ( rValue
>>= nPos
)
515 pListbox
->remove( nPos
);
519 case ControlActions::DELETE_ITEMS
:
524 SAL_WARN( "fpicker.office", "Wrong ControlAction for implDoListboxAction()" );
528 void OControlAccess::implSetControlProperty( sal_Int16 nControlId
, weld::Widget
* pControl
, PropFlags _nProperty
, const Any
& rValue
, bool _bIgnoreIllegalArgument
)
531 pControl
= m_pFilePickerController
->getControl( nControlId
);
532 DBG_ASSERT( pControl
, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
536 DBG_ASSERT( pControl
== m_pFilePickerController
->getControl( nControlId
),
537 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
539 switch ( _nProperty
)
541 case PropFlags::Text
:
544 if (rValue
>>= sText
)
546 weld::Label
* pLabel
= dynamic_cast<weld::Label
*>(pControl
);
548 pLabel
->set_label(sText
);
550 else if ( !_bIgnoreIllegalArgument
)
552 throw IllegalArgumentException();
557 case PropFlags::Enabled
:
559 bool bEnabled
= false;
560 if ( rValue
>>= bEnabled
)
562 m_pFilePickerController
->enableControl( nControlId
, bEnabled
);
564 else if ( !_bIgnoreIllegalArgument
)
566 throw IllegalArgumentException();
571 case PropFlags::Visible
:
573 bool bVisible
= false;
574 if ( rValue
>>= bVisible
)
576 pControl
->set_visible( bVisible
);
578 else if ( !_bIgnoreIllegalArgument
)
580 throw IllegalArgumentException();
585 case PropFlags::HelpUrl
:
588 if ( rValue
>>= sHelpURL
)
590 setHelpURL(pControl
, sHelpURL
);
592 else if ( !_bIgnoreIllegalArgument
)
594 throw IllegalArgumentException();
599 case PropFlags::ListItems
:
601 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
602 assert(pComboBox
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
604 Sequence
< OUString
> aItems
;
605 if ( rValue
>>= aItems
)
607 // remove all previous items
611 for (auto const& item
: aItems
)
613 pComboBox
->append_text(item
);
617 else if ( !_bIgnoreIllegalArgument
)
619 throw IllegalArgumentException();
624 case PropFlags::SelectedItem
:
626 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
627 assert(pComboBox
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
630 if ( rValue
>>= sSelected
)
632 pComboBox
->set_active_text(sSelected
);
634 else if ( !_bIgnoreIllegalArgument
)
636 throw IllegalArgumentException();
641 case PropFlags::SelectedItemIndex
:
643 weld::ComboBox
* pComboBox
= dynamic_cast<weld::ComboBox
*>(pControl
);
644 assert(pComboBox
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
647 if ( rValue
>>= nPos
)
649 pComboBox
->set_active(nPos
);
651 else if ( !_bIgnoreIllegalArgument
)
653 throw IllegalArgumentException();
658 case PropFlags::Checked
:
660 weld::Toggleable
* pToggleButton
= dynamic_cast<weld::Toggleable
*>(pControl
);
661 assert(pToggleButton
&& "OControlAccess::implSetControlProperty: invalid control/property combination!");
663 bool bChecked
= false;
664 if ( rValue
>>= bChecked
)
666 pToggleButton
->set_active(bChecked
);
668 else if ( !_bIgnoreIllegalArgument
)
670 throw IllegalArgumentException();
676 OSL_FAIL( "OControlAccess::implSetControlProperty: invalid property id!" );
680 Any
OControlAccess::implGetControlProperty( weld::Widget
const * pControl
, PropFlags _nProperty
) const
682 assert(pControl
&& "OControlAccess::implGetControlProperty: invalid argument, this will crash!");
685 switch ( _nProperty
)
687 case PropFlags::Text
:
689 const weld::Label
* pLabel
= dynamic_cast<const weld::Label
*>(pControl
);
691 aReturn
<<= pLabel
->get_label();
694 case PropFlags::Enabled
:
695 aReturn
<<= pControl
->get_sensitive();
698 case PropFlags::Visible
:
699 aReturn
<<= pControl
->get_visible();
702 case PropFlags::HelpUrl
:
703 aReturn
<<= getHelpURL(pControl
);
706 case PropFlags::ListItems
:
708 const weld::ComboBox
* pComboBox
= dynamic_cast<const weld::ComboBox
*>(pControl
);
709 assert(pComboBox
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
711 Sequence
< OUString
> aItems(pComboBox
->get_count());
712 OUString
* pItems
= aItems
.getArray();
713 for (sal_Int32 i
= 0; i
< pComboBox
->get_count(); ++i
)
714 *pItems
++ = pComboBox
->get_text(i
);
720 case PropFlags::SelectedItem
:
722 const weld::ComboBox
* pComboBox
= dynamic_cast<const weld::ComboBox
*>(pControl
);
723 assert(pComboBox
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
725 sal_Int32 nSelected
= pComboBox
->get_active();
728 sSelected
= pComboBox
->get_active_text();
729 aReturn
<<= sSelected
;
733 case PropFlags::SelectedItemIndex
:
735 const weld::ComboBox
* pComboBox
= dynamic_cast<const weld::ComboBox
*>(pControl
);
736 assert(pComboBox
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
738 sal_Int32 nSelected
= pComboBox
->get_active();
740 aReturn
<<= nSelected
;
742 aReturn
<<= sal_Int32(-1);
746 case PropFlags::Checked
:
748 const weld::Toggleable
* pToggleButton
= dynamic_cast<const weld::Toggleable
*>(pControl
);
749 assert(pToggleButton
&& "OControlAccess::implGetControlProperty: invalid control/property combination!");
751 aReturn
<<= pToggleButton
->get_active();
756 OSL_FAIL( "OControlAccess::implGetControlProperty: invalid property id!" );
763 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */