LibreOffice Module fpicker (master) 1
OfficeControlAccess.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <sal/macros.h>
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>
32
33#include <algorithm>
34#include <utility>
35
36
37namespace svt
38{
39
40
41 // helper -------------------------------------------------------------
42
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::ui::dialogs;
46
47 using namespace ExtendedFilePickerElementIds;
48 using namespace CommonFilePickerElementIds;
49 using namespace InternalFilePickerElementIds;
50
51
52 namespace
53 {
54
55 struct ControlDescription
56 {
57 const char* pControlName;
58 sal_Int16 nControlId;
60 };
61
62
63 typedef const ControlDescription* ControlDescIterator;
64
65
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 )
69
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 },
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 },
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 },
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 }
100 };
101
102 const sal_Int32 s_nControlCount = SAL_N_ELEMENTS( aDescriptions );
103
104 ControlDescIterator s_pControls = aDescriptions;
105 ControlDescIterator s_pControlsEnd = aDescriptions + s_nControlCount;
106
107 struct ControlDescriptionLookup
108 {
109 bool operator()( const ControlDescription& rDesc1, const ControlDescription& rDesc2 )
110 {
111 return strcmp(rDesc1.pControlName, rDesc2.pControlName) < 0;
112 }
113 };
114
115 struct ControlProperty
116 {
117 const char* pPropertyName;
119 };
120
121 typedef const ControlProperty* ControlPropertyIterator;
122
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 }
132 };
133
134 const int s_nPropertyCount = SAL_N_ELEMENTS( aProperties );
135
136 ControlPropertyIterator s_pProperties = aProperties;
137 ControlPropertyIterator s_pPropertiesEnd = aProperties + s_nPropertyCount;
138
139
140 struct ControlPropertyLookup
141 {
142 OUString m_sLookup;
143 explicit ControlPropertyLookup(OUString aLookup)
144 : m_sLookup(std::move(aLookup))
145 {
146 }
147
148 bool operator()(const ControlProperty& rProp)
149 {
150 return m_sLookup.equalsAscii(rProp.pPropertyName);
151 }
152 };
153
154
155 void lcl_throwIllegalArgumentException( )
156 {
157 throw IllegalArgumentException();
158 // TODO: error message in the exception
159 }
160 }
161
163 : m_pFilePickerController(pController)
164 , m_pFileView(pFileView)
165 {
166 DBG_ASSERT( m_pFilePickerController, "OControlAccess::OControlAccess: invalid control locator!" );
167 }
168
170 {
171 if (!pControl)
172 return false;
173 if (!m_pFileView)
174 return false;
175 return pControl == m_pFileView->identifier();
176 }
177
178 void OControlAccess::setHelpURL(weld::Widget* pControl, const OUString& sHelpURL)
179 {
180 OUString sHelpID( sHelpURL );
181 INetURLObject aHID( sHelpURL );
182 if (aHID.GetProtocol() == INetProtocol::Hid)
183 sHelpID = aHID.GetURLPath();
184
185 // URLs should always be escaped
186 if (IsFileViewWidget(pControl))
187 {
188 // the file view "overrides" the SetHelpId
189 m_pFileView->set_help_id(sHelpID);
190 }
191 else
192 pControl->set_help_id(sHelpID);
193 }
194
195 OUString OControlAccess::getHelpURL(weld::Widget const * pControl) const
196 {
197 OUString aHelpId = pControl->get_help_id();
198 if (IsFileViewWidget(pControl))
199 {
200 // the file view "overrides" the SetHelpId
201 aHelpId = m_pFileView->get_help_id();
202 }
203
204 OUString sHelpURL;
205 INetURLObject aHID(aHelpId);
206 if ( aHID.GetProtocol() == INetProtocol::NotValid )
207 sHelpURL = INET_HID_SCHEME;
208 sHelpURL += aHelpId;
209 return sHelpURL;
210 }
211
212 Any OControlAccess::getControlProperty( std::u16string_view rControlName, const OUString& rControlProperty )
213 {
214 // look up the control
215 sal_Int16 nControlId = -1;
216 PropFlags nPropertyMask = PropFlags::NONE;
217 weld::Widget* pControl = implGetControl( rControlName, &nControlId, &nPropertyMask );
218 // will throw an IllegalArgumentException if the name is not valid
219
220 // look up the property
221 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( rControlProperty ) );
222 if ( aPropDesc == s_pPropertiesEnd )
223 // it's a completely unknown property
224 lcl_throwIllegalArgumentException();
225
226 if ( !( nPropertyMask & aPropDesc->nPropertyId ) )
227 // it's a property which is known, but not allowed for this control
228 lcl_throwIllegalArgumentException();
229
230 return implGetControlProperty( pControl, aPropDesc->nPropertyId );
231 }
232
233 weld::Widget* OControlAccess::implGetControl( std::u16string_view rControlName, sal_Int16* _pId, PropFlags* _pPropertyMask ) const
234 {
235 weld::Widget* pControl = nullptr;
236 ControlDescription tmpDesc;
237 OString aControlName = OUStringToOString( rControlName, RTL_TEXTENCODING_UTF8 );
238 tmpDesc.pControlName = aControlName.getStr();
239
240 // translate the name into an id
241 auto aFoundRange = ::std::equal_range( s_pControls, s_pControlsEnd, tmpDesc, ControlDescriptionLookup() );
242 if ( aFoundRange.first != aFoundRange.second )
243 {
244 // get the VCL control determined by this id
245 pControl = m_pFilePickerController->getControl( aFoundRange.first->nControlId );
246 }
247
248 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
249 if ( !pControl )
250 lcl_throwIllegalArgumentException();
251
252 // out parameters and outta here
253 if ( _pId )
254 *_pId = aFoundRange.first->nControlId;
255 if ( _pPropertyMask )
256 *_pPropertyMask = aFoundRange.first->nPropertyFlags;
257
258 return pControl;
259 }
260
261 void OControlAccess::setControlProperty( std::u16string_view rControlName, const OUString& rControlProperty, const css::uno::Any& rValue )
262 {
263 // look up the control
264 sal_Int16 nControlId = -1;
265 weld::Widget* pControl = implGetControl( rControlName, &nControlId );
266 // will throw an IllegalArgumentException if the name is not valid
267
268 // look up the property
269 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( rControlProperty ) );
270 if ( aPropDesc == s_pPropertiesEnd )
271 lcl_throwIllegalArgumentException();
272
273 // set the property
274 implSetControlProperty( nControlId, pControl, aPropDesc->nPropertyId, rValue, false );
275 }
276
277 Sequence< OUString > OControlAccess::getSupportedControls( ) const
278 {
279 Sequence< OUString > aControls( s_nControlCount );
280 OUString* pControls = aControls.getArray();
281
282 // collect the names of all _actually_existent_ controls
283 for ( ControlDescIterator aControl = s_pControls; aControl != s_pControlsEnd; ++aControl )
284 {
285 if ( m_pFilePickerController->getControl( aControl->nControlId ) )
286 *pControls++ = OUString::createFromAscii( aControl->pControlName );
287 }
288
289 aControls.realloc( pControls - aControls.getArray() );
290 return aControls;
291 }
292
293 Sequence< OUString > OControlAccess::getSupportedControlProperties( std::u16string_view rControlName )
294 {
295 sal_Int16 nControlId = -1;
296 PropFlags nPropertyMask = PropFlags::NONE;
297 implGetControl( rControlName, &nControlId, &nPropertyMask );
298 // will throw an IllegalArgumentException if the name is not valid
299
300 // fill in the property names
301 Sequence< OUString > aProps( s_nPropertyCount );
302 OUString* pProperty = aProps.getArray();
303
304 for ( ControlPropertyIterator aProp = s_pProperties; aProp != s_pPropertiesEnd; ++aProp )
305 if ( nPropertyMask & aProp->nPropertyId )
306 *pProperty++ = OUString::createFromAscii( aProp->pPropertyName );
307
308 aProps.realloc( pProperty - aProps.getArray() );
309 return aProps;
310 }
311
312 bool OControlAccess::isControlSupported( std::u16string_view rControlName )
313 {
314 ControlDescription tmpDesc;
315 OString aControlName = OUStringToOString(rControlName, RTL_TEXTENCODING_UTF8);
316 tmpDesc.pControlName = aControlName.getStr();
317 return ::std::binary_search( s_pControls, s_pControlsEnd, tmpDesc, ControlDescriptionLookup() );
318 }
319
320 bool OControlAccess::isControlPropertySupported( std::u16string_view rControlName, const OUString& rControlProperty )
321 {
322 // look up the control
323 sal_Int16 nControlId = -1;
324 PropFlags nPropertyMask = PropFlags::NONE;
325 implGetControl( rControlName, &nControlId, &nPropertyMask );
326 // will throw an IllegalArgumentException if the name is not valid
327
328 // look up the property
329 ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( rControlProperty ) );
330 if ( aPropDesc == s_pPropertiesEnd )
331 // it's a property which is completely unknown
332 return false;
333
334 return bool( aPropDesc->nPropertyId & nPropertyMask );
335 }
336
337 void OControlAccess::setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const Any& rValue )
338 {
340 DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" );
341 if ( !pControl )
342 return;
343
345 if ( ControlActions::SET_HELP_URL == nControlAction )
346 {
348 }
349 else
350 {
351 switch ( nControlId )
352 {
353 case CHECKBOX_AUTOEXTENSION:
354 case CHECKBOX_PASSWORD:
355 case CHECKBOX_FILTEROPTIONS:
356 case CHECKBOX_READONLY:
357 case CHECKBOX_LINK:
358 case CHECKBOX_PREVIEW:
359 case CHECKBOX_SELECTION:
361 break;
362
363 case LISTBOX_FILTER:
364 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
365 break;
366
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 )
372 {
374 }
375 else
376 {
377 weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
378 assert(pComboBox && "OControlAccess::SetValue: implGetControl returned nonsense!");
379 implDoListboxAction(pComboBox, nControlAction, rValue);
380 }
381 break;
382 }
383 }
384
386 implSetControlProperty( nControlId, pControl, nPropertyId, rValue );
387 }
388
389 Any OControlAccess::getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) const
390 {
391 Any aRet;
392
394 DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
395 if ( pControl )
396 {
398 if ( ControlActions::SET_HELP_URL == nControlAction )
399 {
401 }
402 else
403 {
404 switch ( nControlId )
405 {
406 case CHECKBOX_AUTOEXTENSION:
407 case CHECKBOX_PASSWORD:
408 case CHECKBOX_GPGENCRYPTION:
409 case CHECKBOX_FILTEROPTIONS:
410 case CHECKBOX_READONLY:
411 case CHECKBOX_LINK:
412 case CHECKBOX_PREVIEW:
413 case CHECKBOX_SELECTION:
415 break;
416
417 case LISTBOX_FILTER:
418 if ( ControlActions::GET_SELECTED_ITEM == nControlAction )
419 {
421 }
422 else
423 {
424 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
425 }
426 break;
427
428 case LISTBOX_VERSION:
429 case LISTBOX_TEMPLATE:
430 case LISTBOX_IMAGE_TEMPLATE:
431 case LISTBOX_IMAGE_ANCHOR:
432 switch ( nControlAction )
433 {
434 case ControlActions::GET_SELECTED_ITEM:
436 break;
437 case ControlActions::GET_SELECTED_ITEM_INDEX:
439 break;
440 case ControlActions::GET_ITEMS:
442 break;
443 default:
444 SAL_WARN( "fpicker.office", "OControlAccess::GetValue: invalid control action for the listbox!" );
445 break;
446 }
447 break;
448 }
449 }
450
452 aRet = implGetControlProperty( pControl, nPropertyId );
453 }
454
455 return aRet;
456 }
457
458 void OControlAccess::setLabel( sal_Int16 nId, const OUString &rLabel )
459 {
461 if (weld::Label* pLabel = dynamic_cast<weld::Label*>(pControl))
462 {
463 pLabel->set_label(rLabel);
464 return;
465 }
466 if (weld::Button* pButton = dynamic_cast<weld::Button*>(pControl))
467 {
468 pButton->set_label(rLabel);
469 return;
470 }
471 assert(false && "OControlAccess::GetValue: don't have this control in the current mode!");
472 }
473
474 OUString OControlAccess::getLabel( sal_Int16 nId ) const
475 {
477 if (weld::Label* pLabel = dynamic_cast<weld::Label*>(pControl))
478 return pLabel->get_label();
479 if (weld::Button* pButton = dynamic_cast<weld::Button*>(pControl))
480 return pButton->get_label();
481 assert(false && "OControlAccess::GetValue: don't have this control in the current mode!");
482 return OUString();
483 }
484
485 void OControlAccess::enableControl(sal_Int16 nId, bool bEnable)
486 {
488 }
489
490 void OControlAccess::implDoListboxAction(weld::ComboBox* pListbox, sal_Int16 nControlAction, const Any& rValue)
491 {
492 switch ( nControlAction )
493 {
494 case ControlActions::ADD_ITEM:
495 {
496 OUString aEntry;
497 rValue >>= aEntry;
498 if ( !aEntry.isEmpty() )
499 pListbox->append_text( aEntry );
500 }
501 break;
502
503 case ControlActions::ADD_ITEMS:
504 {
505 Sequence < OUString > aTemplateList;
506 rValue >>= aTemplateList;
507
508 if ( aTemplateList.hasElements() )
509 {
510 for ( const OUString& s : std::as_const(aTemplateList) )
511 pListbox->append_text( s );
512 }
513 }
514 break;
515
516 case ControlActions::DELETE_ITEM:
517 {
518 sal_Int32 nPos = 0;
519 if ( rValue >>= nPos )
520 pListbox->remove( nPos );
521 }
522 break;
523
524 case ControlActions::DELETE_ITEMS:
525 pListbox->clear();
526 break;
527
528 default:
529 SAL_WARN( "fpicker.office", "Wrong ControlAction for implDoListboxAction()" );
530 }
531 }
532
533 void OControlAccess::implSetControlProperty( sal_Int16 nControlId, weld::Widget* pControl, PropFlags _nProperty, const Any& rValue, bool _bIgnoreIllegalArgument )
534 {
535 if ( !pControl )
537 DBG_ASSERT( pControl, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
538 if ( !pControl )
539 return;
540
542 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
543
544 switch ( _nProperty )
545 {
546 case PropFlags::Text:
547 {
548 OUString sText;
549 if (rValue >>= sText)
550 {
551 weld::Label* pLabel = dynamic_cast<weld::Label*>(pControl);
552 assert(pLabel);
553 pLabel->set_label(sText);
554 }
555 else if ( !_bIgnoreIllegalArgument )
556 {
557 lcl_throwIllegalArgumentException();
558 }
559 }
560 break;
561
563 {
564 bool bEnabled = false;
565 if ( rValue >>= bEnabled )
566 {
568 }
569 else if ( !_bIgnoreIllegalArgument )
570 {
571 lcl_throwIllegalArgumentException();
572 }
573 }
574 break;
575
577 {
578 bool bVisible = false;
579 if ( rValue >>= bVisible )
580 {
581 pControl->set_visible( bVisible );
582 }
583 else if ( !_bIgnoreIllegalArgument )
584 {
585 lcl_throwIllegalArgumentException();
586 }
587 }
588 break;
589
591 {
592 OUString sHelpURL;
593 if ( rValue >>= sHelpURL )
594 {
595 setHelpURL(pControl, sHelpURL);
596 }
597 else if ( !_bIgnoreIllegalArgument )
598 {
599 lcl_throwIllegalArgumentException();
600 }
601 }
602 break;
603
605 {
606 weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
607 assert(pComboBox && "OControlAccess::implSetControlProperty: invalid control/property combination!");
608
609 Sequence< OUString > aItems;
610 if ( rValue >>= aItems )
611 {
612 // remove all previous items
613 pComboBox->clear();
614
615 // add the new ones
616 for (auto const & item : std::as_const(aItems))
617 {
618 pComboBox->append_text(item);
619 }
620
621 }
622 else if ( !_bIgnoreIllegalArgument )
623 {
624 lcl_throwIllegalArgumentException();
625 }
626 }
627 break;
628
630 {
631 weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
632 assert(pComboBox && "OControlAccess::implSetControlProperty: invalid control/property combination!");
633
634 OUString sSelected;
635 if ( rValue >>= sSelected )
636 {
637 pComboBox->set_active_text(sSelected);
638 }
639 else if ( !_bIgnoreIllegalArgument )
640 {
641 lcl_throwIllegalArgumentException();
642 }
643 }
644 break;
645
647 {
648 weld::ComboBox* pComboBox = dynamic_cast<weld::ComboBox*>(pControl);
649 assert(pComboBox && "OControlAccess::implSetControlProperty: invalid control/property combination!");
650
651 sal_Int32 nPos = 0;
652 if ( rValue >>= nPos )
653 {
654 pComboBox->set_active(nPos);
655 }
656 else if ( !_bIgnoreIllegalArgument )
657 {
658 lcl_throwIllegalArgumentException();
659 }
660 }
661 break;
662
664 {
665 weld::Toggleable* pToggleButton = dynamic_cast<weld::Toggleable*>(pControl);
666 assert(pToggleButton && "OControlAccess::implSetControlProperty: invalid control/property combination!");
667
668 bool bChecked = false;
669 if ( rValue >>= bChecked )
670 {
671 pToggleButton->set_active(bChecked);
672 }
673 else if ( !_bIgnoreIllegalArgument )
674 {
675 lcl_throwIllegalArgumentException();
676 }
677 }
678 break;
679
680 default:
681 OSL_FAIL( "OControlAccess::implSetControlProperty: invalid property id!" );
682 }
683 }
684
686 {
687 assert(pControl && "OControlAccess::implGetControlProperty: invalid argument, this will crash!");
688
689 Any aReturn;
690 switch ( _nProperty )
691 {
692 case PropFlags::Text:
693 {
694 const weld::Label* pLabel = dynamic_cast<const weld::Label*>(pControl);
695 assert(pLabel);
696 aReturn <<= pLabel->get_label();
697 break;
698 }
700 aReturn <<= pControl->get_sensitive();
701 break;
702
704 aReturn <<= pControl->get_visible();
705 break;
706
708 aReturn <<= getHelpURL(pControl);
709 break;
710
712 {
713 const weld::ComboBox* pComboBox = dynamic_cast<const weld::ComboBox*>(pControl);
714 assert(pComboBox && "OControlAccess::implGetControlProperty: invalid control/property combination!");
715
716 Sequence< OUString > aItems(pComboBox->get_count());
717 OUString* pItems = aItems.getArray();
718 for (sal_Int32 i = 0; i < pComboBox->get_count(); ++i)
719 *pItems++ = pComboBox->get_text(i);
720
721 aReturn <<= aItems;
722 break;
723 }
724
726 {
727 const weld::ComboBox* pComboBox = dynamic_cast<const weld::ComboBox*>(pControl);
728 assert(pComboBox && "OControlAccess::implGetControlProperty: invalid control/property combination!");
729
730 sal_Int32 nSelected = pComboBox->get_active();
731 OUString sSelected;
732 if (nSelected != -1)
733 sSelected = pComboBox->get_active_text();
734 aReturn <<= sSelected;
735 break;
736 }
737
739 {
740 const weld::ComboBox* pComboBox = dynamic_cast<const weld::ComboBox*>(pControl);
741 assert(pComboBox && "OControlAccess::implGetControlProperty: invalid control/property combination!");
742
743 sal_Int32 nSelected = pComboBox->get_active();
744 if (nSelected != -1)
745 aReturn <<= nSelected;
746 else
747 aReturn <<= sal_Int32(-1);
748 break;
749 }
750
752 {
753 const weld::Toggleable* pToggleButton = dynamic_cast<const weld::Toggleable*>(pControl);
754 assert(pToggleButton && "OControlAccess::implGetControlProperty: invalid control/property combination!");
755
756 aReturn <<= pToggleButton->get_active();
757 break;
758 }
759
760 default:
761 OSL_FAIL( "OControlAccess::implGetControlProperty: invalid property id!" );
762 }
763 return aReturn;
764 }
765
766} // namespace svt
767
768/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString m_sLookup
PropFlags nPropertyId
const char * pControlName
#define PROPERTY_FLAGS_LISTBOX
#define PROPERTY_FLAGS_CHECKBOX
PropFlags nPropertyFlags
#define PROPERTY_FLAGS_COMMON
const char * pPropertyName
sal_Int16 nControlId
@ SelectedItemIndex
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)
Definition: fileview.cxx:923
OUString get_help_id() const
Definition: fileview.cxx:918
weld::Widget * identifier() const
Definition: fileview.cxx:1803
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)
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 clear()=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
virtual void set_help_id(const OUString &rName)=0
virtual void set_visible(bool visible)
virtual bool get_visible() const=0
virtual OUString get_help_id() const=0
virtual bool get_sensitive() const=0
#define DBG_ASSERT(sCon, aError)
sal_uInt16 nPos
#define SAL_WARN(area, stream)
#define SAL_N_ELEMENTS(arr)
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
sal_Int16 nId
bool bVisible
constexpr OUStringLiteral INET_HID_SCHEME