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>
28#include <osl/diagnose.h>
29#include <com/sun/star/uno/Sequence.hxx>
47 using namespace ExtendedFilePickerElementIds;
48 using namespace CommonFilePickerElementIds;
49 using namespace InternalFilePickerElementIds;
55 struct ControlDescription
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 )
71 const ControlDescription aDescriptions[] = {
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
121 typedef const ControlProperty* ControlPropertyIterator;
136 ControlPropertyIterator s_pProperties =
aProperties;
137 ControlPropertyIterator s_pPropertiesEnd =
aProperties + s_nPropertyCount;
140 struct ControlPropertyLookup
143 explicit ControlPropertyLookup(OUString aLookup)
148 bool operator()(
const ControlProperty& rProp)
150 return m_sLookup.equalsAscii(rProp.pPropertyName);
155 void lcl_throwIllegalArgumentException( )
157 throw IllegalArgumentException();
163 : m_pFilePickerController(pController)
164 , m_pFileView(pFileView)
180 OUString sHelpID( sHelpURL );
206 if ( aHID.
GetProtocol() == INetProtocol::NotValid )
221 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( rControlProperty ) );
222 if ( aPropDesc == s_pPropertiesEnd )
224 lcl_throwIllegalArgumentException();
226 if ( !( nPropertyMask & aPropDesc->nPropertyId ) )
228 lcl_throwIllegalArgumentException();
236 ControlDescription tmpDesc;
238 tmpDesc.pControlName = aControlName.getStr();
241 auto aFoundRange = ::std::equal_range( s_pControls, s_pControlsEnd, tmpDesc, ControlDescriptionLookup() );
242 if ( aFoundRange.first != aFoundRange.second )
250 lcl_throwIllegalArgumentException();
254 *_pId = aFoundRange.first->nControlId;
255 if ( _pPropertyMask )
256 *_pPropertyMask = aFoundRange.first->nPropertyFlags;
269 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( rControlProperty ) );
270 if ( aPropDesc == s_pPropertiesEnd )
271 lcl_throwIllegalArgumentException();
279 Sequence< OUString > aControls( s_nControlCount );
280 OUString* pControls = aControls.getArray();
283 for ( ControlDescIterator aControl = s_pControls; aControl != s_pControlsEnd; ++aControl )
286 *pControls++ = OUString::createFromAscii( aControl->pControlName );
289 aControls.realloc( pControls - aControls.getArray() );
301 Sequence< OUString > aProps( s_nPropertyCount );
302 OUString* pProperty = aProps.getArray();
304 for ( ControlPropertyIterator aProp = s_pProperties; aProp != s_pPropertiesEnd; ++aProp )
305 if ( nPropertyMask & aProp->nPropertyId )
306 *pProperty++ = OUString::createFromAscii( aProp->pPropertyName );
308 aProps.realloc( pProperty - aProps.getArray() );
314 ControlDescription tmpDesc;
316 tmpDesc.pControlName = aControlName.getStr();
317 return ::std::binary_search( s_pControls, s_pControlsEnd, tmpDesc, ControlDescriptionLookup() );
329 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( rControlProperty ) );
330 if ( aPropDesc == s_pPropertiesEnd )
334 return bool( aPropDesc->nPropertyId & nPropertyMask );
340 DBG_ASSERT( pControl,
"OControlAccess::SetValue: don't have this control in the current mode!" );
345 if ( ControlActions::SET_HELP_URL == nControlAction )
353 case CHECKBOX_AUTOEXTENSION:
354 case CHECKBOX_PASSWORD:
355 case CHECKBOX_FILTEROPTIONS:
356 case CHECKBOX_READONLY:
358 case CHECKBOX_PREVIEW:
359 case CHECKBOX_SELECTION:
364 SAL_WARN(
"fpicker.office",
"Use the XFilterManager to access the filter listbox" );
367 case LISTBOX_VERSION:
368 case LISTBOX_TEMPLATE:
369 case LISTBOX_IMAGE_TEMPLATE:
370 case LISTBOX_IMAGE_ANCHOR:
371 if ( ControlActions::SET_SELECT_ITEM == nControlAction )
378 assert(pComboBox &&
"OControlAccess::SetValue: implGetControl returned nonsense!");
394 DBG_ASSERT( pControl,
"OControlAccess::GetValue: don't have this control in the current mode!" );
398 if ( ControlActions::SET_HELP_URL == nControlAction )
406 case CHECKBOX_AUTOEXTENSION:
407 case CHECKBOX_PASSWORD:
408 case CHECKBOX_GPGENCRYPTION:
409 case CHECKBOX_FILTEROPTIONS:
410 case CHECKBOX_READONLY:
412 case CHECKBOX_PREVIEW:
413 case CHECKBOX_SELECTION:
418 if ( ControlActions::GET_SELECTED_ITEM == nControlAction )
424 SAL_WARN(
"fpicker.office",
"Use the XFilterManager to access the filter listbox" );
428 case LISTBOX_VERSION:
429 case LISTBOX_TEMPLATE:
430 case LISTBOX_IMAGE_TEMPLATE:
431 case LISTBOX_IMAGE_ANCHOR:
432 switch ( nControlAction )
434 case ControlActions::GET_SELECTED_ITEM:
437 case ControlActions::GET_SELECTED_ITEM_INDEX:
440 case ControlActions::GET_ITEMS:
444 SAL_WARN(
"fpicker.office",
"OControlAccess::GetValue: invalid control action for the listbox!" );
463 pLabel->set_label(rLabel);
468 pButton->set_label(rLabel);
471 assert(
false &&
"OControlAccess::GetValue: don't have this control in the current mode!");
478 return pLabel->get_label();
480 return pButton->get_label();
481 assert(
false &&
"OControlAccess::GetValue: don't have this control in the current mode!");
492 switch ( nControlAction )
494 case ControlActions::ADD_ITEM:
498 if ( !aEntry.isEmpty() )
503 case ControlActions::ADD_ITEMS:
505 Sequence < OUString > aTemplateList;
506 rValue >>= aTemplateList;
508 if ( aTemplateList.hasElements() )
510 for (
const OUString& s : std::as_const(aTemplateList) )
516 case ControlActions::DELETE_ITEM:
519 if ( rValue >>=
nPos )
524 case ControlActions::DELETE_ITEMS:
529 SAL_WARN(
"fpicker.office",
"Wrong ControlAction for implDoListboxAction()" );
537 DBG_ASSERT( pControl,
"OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
542 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
544 switch ( _nProperty )
549 if (rValue >>= sText)
555 else if ( !_bIgnoreIllegalArgument )
557 lcl_throwIllegalArgumentException();
564 bool bEnabled =
false;
565 if ( rValue >>= bEnabled )
569 else if ( !_bIgnoreIllegalArgument )
571 lcl_throwIllegalArgumentException();
583 else if ( !_bIgnoreIllegalArgument )
585 lcl_throwIllegalArgumentException();
593 if ( rValue >>= sHelpURL )
597 else if ( !_bIgnoreIllegalArgument )
599 lcl_throwIllegalArgumentException();
607 assert(pComboBox &&
"OControlAccess::implSetControlProperty: invalid control/property combination!");
609 Sequence< OUString > aItems;
610 if ( rValue >>= aItems )
616 for (
auto const & item : std::as_const(aItems))
622 else if ( !_bIgnoreIllegalArgument )
624 lcl_throwIllegalArgumentException();
632 assert(pComboBox &&
"OControlAccess::implSetControlProperty: invalid control/property combination!");
635 if ( rValue >>= sSelected )
639 else if ( !_bIgnoreIllegalArgument )
641 lcl_throwIllegalArgumentException();
649 assert(pComboBox &&
"OControlAccess::implSetControlProperty: invalid control/property combination!");
652 if ( rValue >>=
nPos )
656 else if ( !_bIgnoreIllegalArgument )
658 lcl_throwIllegalArgumentException();
666 assert(pToggleButton &&
"OControlAccess::implSetControlProperty: invalid control/property combination!");
668 bool bChecked =
false;
669 if ( rValue >>= bChecked )
673 else if ( !_bIgnoreIllegalArgument )
675 lcl_throwIllegalArgumentException();
681 OSL_FAIL(
"OControlAccess::implSetControlProperty: invalid property id!" );
687 assert(pControl &&
"OControlAccess::implGetControlProperty: invalid argument, this will crash!");
690 switch ( _nProperty )
714 assert(pComboBox &&
"OControlAccess::implGetControlProperty: invalid control/property combination!");
716 Sequence< OUString > aItems(pComboBox->
get_count());
717 OUString* pItems = aItems.getArray();
728 assert(pComboBox &&
"OControlAccess::implGetControlProperty: invalid control/property combination!");
730 sal_Int32 nSelected = pComboBox->
get_active();
734 aReturn <<= sSelected;
741 assert(pComboBox &&
"OControlAccess::implGetControlProperty: invalid control/property combination!");
743 sal_Int32 nSelected = pComboBox->
get_active();
745 aReturn <<= nSelected;
747 aReturn <<= sal_Int32(-1);
754 assert(pToggleButton &&
"OControlAccess::implGetControlProperty: invalid control/property combination!");
761 OSL_FAIL(
"OControlAccess::implGetControlProperty: invalid property id!" );
const char * pControlName
#define PROPERTY_FLAGS_LISTBOX
#define PROPERTY_FLAGS_CHECKBOX
#define PROPERTY_FLAGS_COMMON
const char * pPropertyName
PropertiesInfo aProperties
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
void set_help_id(const OUString &rHelpId)
OUString get_help_id() const
weld::Widget * identifier() const
virtual void enableControl(sal_Int16 nControlId, bool bEnable)=0
virtual weld::Widget * getControl(sal_Int16 nControlId, bool bLabelControl=false) const =0
virtual OUString getCurFilter() const =0
void setValue(sal_Int16 nId, sal_Int16 nCtrlAction, const css::uno::Any &rValue)
void enableControl(sal_Int16 nId, bool bEnable)
static void implDoListboxAction(weld::ComboBox *pListbox, sal_Int16 nCtrlAction, const css::uno::Any &rValue)
css::uno::Any getValue(sal_Int16 nId, sal_Int16 nCtrlAction) const
void implSetControlProperty(sal_Int16 nControlId, weld::Widget *pControl, PropFlags nProperty, const css::uno::Any &rValue, bool bIgnoreIllegalArgument=true)
implements the various methods for setting properties on controls
OControlAccess(IFilePickerController *pController, SvtFileView *pFileView)
css::uno::Sequence< OUString > getSupportedControlProperties(std::u16string_view rControlName)
SvtFileView * m_pFileView
void setLabel(sal_Int16 nId, const OUString &rValue)
bool IsFileViewWidget(weld::Widget const *pControl) const
static bool isControlSupported(std::u16string_view rControlName)
css::uno::Any implGetControlProperty(weld::Widget const *pControl, PropFlags nProperty) const
implements the various methods for retrieving properties from controls
weld::Widget * implGetControl(std::u16string_view rControlName, sal_Int16 *pId, PropFlags *pPropertyMask=nullptr) const
void setHelpURL(weld::Widget *pControl, const OUString &rURL)
css::uno::Sequence< OUString > getSupportedControls() const
OUString getHelpURL(weld::Widget const *pControl) const
IFilePickerController * m_pFilePickerController
OUString getLabel(sal_Int16 nId) const
css::uno::Any getControlProperty(std::u16string_view rControlName, const OUString &rControlProperty)
void setControlProperty(std::u16string_view rControlName, const OUString &rControlProperty, const css::uno::Any &rValue)
bool isControlPropertySupported(std::u16string_view rControlName, const OUString &rControlProperty)
virtual OUString get_active_text() const=0
virtual void set_active(int pos)=0
virtual OUString get_text(int pos) const=0
void append_text(const OUString &rStr)
virtual void remove(int pos)=0
virtual int get_active() const=0
virtual int get_count() const=0
void set_active_text(const OUString &rStr)
virtual void set_label(const OUString &rText)=0
virtual OUString get_label() const=0
virtual bool get_active() const=0
virtual void set_active(bool active)=0
#define DBG_ASSERT(sCon, aError)
#define SAL_WARN(area, stream)
#define SAL_N_ELEMENTS(arr)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
const sal_Int16 TOOLBOXBUTTON_NEW_FOLDER
const sal_Int16 FIXEDTEXT_CURRENTFOLDER
const sal_Int16 PUSHBUTTON_HELP
const sal_Int16 TOOLBOXBUTTON_LEVEL_UP
constexpr OUStringLiteral INET_HID_SCHEME