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>
33 //.........................................................................
36 //.........................................................................
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
;
48 // --------------------------------------------------------------------
51 // ----------------------------------------------------------------
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
61 // ----------------------------------------------------------------
62 // ................................................................
63 struct ControlDescription
65 const sal_Char
* pControlName
;
67 sal_Int32 nPropertyFlags
;
70 // ................................................................
71 typedef const ControlDescription
* ControlDescIterator
;
72 typedef ::std::pair
< ControlDescIterator
, ControlDescIterator
> ControlDescRange
;
74 // ......................................................................
75 #define PROPERTY_FLAGS_COMMON ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL )
76 #define PROPERTY_FLAGS_LISTBOX ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX )
77 #define PROPERTY_FLAGS_CHECKBOX ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT )
79 // Note: this array MUST be sorted by name!
80 static const ControlDescription aDescriptions
[] = {
81 { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
82 { "CancelButton", PUSHBUTTON_CANCEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
83 { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
84 { "DefaultLocationButton", TOOLBOXBUTOON_DEFAULT_LOCATION
, PROPERTY_FLAGS_COMMON
},
85 { "FileURLEdit", EDIT_FILEURL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
86 { "FileURLEditLabel", EDIT_FILEURL_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
87 { "FileView", CONTROL_FILEVIEW
, PROPERTY_FLAGS_COMMON
},
88 { "FilterList", LISTBOX_FILTER
, PROPERTY_FLAGS_COMMON
},
89 { "FilterListLabel", LISTBOX_FILTER_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
90 { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
91 { "HelpButton", PUSHBUTTON_HELP
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
92 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
93 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
94 { "LevelUpButton", TOOLBOXBUTOON_LEVEL_UP
, PROPERTY_FLAGS_COMMON
},
95 { "LinkBox", CHECKBOX_LINK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
96 { "NewFolderButton", TOOLBOXBUTOON_NEW_FOLDER
, PROPERTY_FLAGS_COMMON
},
97 { "OkButton", PUSHBUTTON_OK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
98 { "PasswordBox", CHECKBOX_PASSWORD
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
99 { "PlayButton", PUSHBUTTON_PLAY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
100 { "PreviewBox", CHECKBOX_PREVIEW
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
101 { "ReadOnlyBox", CHECKBOX_READONLY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
102 { "SelectionBox", CHECKBOX_SELECTION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
103 { "TemplateList", LISTBOX_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
104 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
105 { "VersionList", LISTBOX_VERSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
106 { "VersionListLabel", LISTBOX_VERSION_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
}
109 // ................................................................
110 static const sal_Int32 s_nControlCount
= sizeof( aDescriptions
) / sizeof( aDescriptions
[0] );
112 static ControlDescIterator s_pControls
= aDescriptions
;
113 static ControlDescIterator s_pControlsEnd
= aDescriptions
+ s_nControlCount
;
115 // ................................................................
116 struct ControlDescriptionLookup
118 bool operator()( const ControlDescription
& _rDesc1
, const ControlDescription
& _rDesc2
)
120 return strcmp(_rDesc1
.pControlName
, _rDesc2
.pControlName
) < 0;
124 // ................................................................
125 struct ExtractControlName
: public ::std::unary_function
< ControlDescription
, OUString
>
127 OUString
operator()( const ControlDescription
& _rDesc
)
129 return OUString::createFromAscii( _rDesc
.pControlName
);
133 // ----------------------------------------------------------------
134 // ................................................................
135 struct ControlProperty
137 const sal_Char
* pPropertyName
;
138 sal_Int16 nPropertyId
;
141 typedef const ControlProperty
* ControlPropertyIterator
;
143 // ................................................................
144 static const ControlProperty aProperties
[] = {
145 { "Text", PROPERTY_FLAG_TEXT
},
146 { "Enabled", PROPERTY_FLAG_ENDBALED
},
147 { "Visible", PROPERTY_FLAG_VISIBLE
},
148 { "HelpURL", PROPERTY_FLAG_HELPURL
},
149 { "ListItems", PROPERTY_FLAG_LISTITEMS
},
150 { "SelectedItem", PROPERTY_FLAG_SELECTEDITEM
},
151 { "SelectedItemIndex", PROPERTY_FLAG_SELECTEDITEMINDEX
},
152 { "Checked", PROPERTY_FLAG_CHECKED
}
155 // ................................................................
156 static const int s_nPropertyCount
= sizeof( aProperties
) / sizeof( aProperties
[0] );
158 static ControlPropertyIterator s_pProperties
= aProperties
;
159 static ControlPropertyIterator s_pPropertiesEnd
= aProperties
+ s_nPropertyCount
;
161 // ................................................................
162 struct ControlPropertyLookup
165 ControlPropertyLookup( const OUString
& _rLookup
) : m_sLookup( _rLookup
) { }
167 sal_Bool
operator()( const ControlProperty
& _rProp
)
169 return m_sLookup
.equalsAscii( _rProp
.pPropertyName
);
173 //-----------------------------------------------------------------
174 void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException
) )
176 throw IllegalArgumentException();
177 // TODO: error message in the exception
181 //---------------------------------------------------------------------
182 OControlAccess::OControlAccess( IFilePickerController
* _pController
, SvtFileView
* _pFileView
)
183 :m_pFilePickerController( _pController
)
184 ,m_pFileView( _pFileView
)
186 DBG_ASSERT( m_pFilePickerController
, "OControlAccess::OControlAccess: invalid control locator!" );
189 //---------------------------------------------------------------------
190 void OControlAccess::setHelpURL( Window
* _pControl
, const OUString
& sHelpURL
, sal_Bool _bFileView
)
192 OUString
sHelpID( sHelpURL
);
193 INetURLObject
aHID( sHelpURL
);
194 if ( aHID
.GetProtocol() == INET_PROT_HID
)
195 sHelpID
= aHID
.GetURLPath();
197 // URLs should always be UTF8 encoded and escaped
198 OString
sID( OUStringToOString( sHelpID
, RTL_TEXTENCODING_UTF8
) );
200 // the file view "overloaded" the SetHelpId
201 static_cast< SvtFileView
* >( _pControl
)->SetHelpId( sID
);
203 _pControl
->SetHelpId( sID
);
206 //---------------------------------------------------------------------
207 OUString
OControlAccess::getHelpURL( Window
* _pControl
, sal_Bool _bFileView
)
209 OString aHelpId
= _pControl
->GetHelpId();
211 // the file view "overloaded" the SetHelpId
212 aHelpId
= static_cast< SvtFileView
* >( _pControl
)->GetHelpId( );
215 OUString
aTmp( OStringToOUString( aHelpId
, RTL_TEXTENCODING_UTF8
) );
216 INetURLObject
aHID( aTmp
);
217 if ( aHID
.GetProtocol() == INET_PROT_NOT_VALID
)
218 sHelpURL
= OUString::createFromAscii( INET_HID_SCHEME
);
223 // --------------------------------------------------------------------------
224 Any
OControlAccess::getControlProperty( const OUString
& _rControlName
, const OUString
& _rControlProperty
)
226 // look up the control
227 sal_Int16 nControlId
= -1;
228 sal_Int32 nPropertyMask
= 0;
229 Control
* pControl
= implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
230 // will throw an IllegalArgumentException if the name is not valid
232 // look up the property
233 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
234 if ( aPropDesc
== s_pPropertiesEnd
)
235 // it's a completely unknown property
236 lcl_throwIllegalArgumentException();
238 if ( 0 == ( nPropertyMask
& aPropDesc
->nPropertyId
) )
239 // it's a property which is known, but not allowed for this control
240 lcl_throwIllegalArgumentException();
242 return implGetControlProperty( pControl
, aPropDesc
->nPropertyId
);
245 //---------------------------------------------------------------------
246 Control
* OControlAccess::implGetControl( const OUString
& _rControlName
, sal_Int16
* _pId
, sal_Int32
* _pPropertyMask
) const SAL_THROW( (IllegalArgumentException
) )
248 Control
* pControl
= NULL
;
249 ControlDescription tmpDesc
;
250 tmpDesc
.pControlName
= OUStringToOString(_rControlName
, RTL_TEXTENCODING_UTF8
).getStr();
252 // translate the name into an id
253 ControlDescRange aFoundRange
= ::std::equal_range( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
254 if ( aFoundRange
.first
!= aFoundRange
.second
)
256 // get the VCL control determined by this id
257 pControl
= m_pFilePickerController
->getControl( aFoundRange
.first
->nControlId
);
260 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
262 lcl_throwIllegalArgumentException();
264 // out parameters and outta here
266 *_pId
= aFoundRange
.first
->nControlId
;
267 if ( _pPropertyMask
)
268 *_pPropertyMask
= aFoundRange
.first
->nPropertyFlags
;
273 //---------------------------------------------------------------------
274 void OControlAccess::setControlProperty( const OUString
& _rControlName
, const OUString
& _rControlProperty
, const ::com::sun::star::uno::Any
& _rValue
)
276 // look up the control
277 sal_Int16 nControlId
= -1;
278 Control
* pControl
= implGetControl( _rControlName
, &nControlId
);
279 // will throw an IllegalArgumentException if the name is not valid
281 // look up the property
282 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
283 if ( aPropDesc
== s_pPropertiesEnd
)
284 lcl_throwIllegalArgumentException();
287 implSetControlProperty( nControlId
, pControl
, aPropDesc
->nPropertyId
, _rValue
, sal_False
);
290 // --------------------------------------------------------------------------
291 Sequence
< OUString
> OControlAccess::getSupportedControls( )
293 Sequence
< OUString
> aControls( s_nControlCount
);
294 OUString
* pControls
= aControls
.getArray();
296 // collect the names of all _actually_existent_ controls
297 for ( ControlDescIterator aControl
= s_pControls
; aControl
!= s_pControlsEnd
; ++aControl
)
299 if ( m_pFilePickerController
->getControl( aControl
->nControlId
) )
300 *pControls
++ = OUString::createFromAscii( aControl
->pControlName
);
303 aControls
.realloc( pControls
- aControls
.getArray() );
307 // --------------------------------------------------------------------------
308 Sequence
< OUString
> OControlAccess::getSupportedControlProperties( const OUString
& _rControlName
)
310 sal_Int16 nControlId
= -1;
311 sal_Int32 nPropertyMask
= 0;
312 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
313 // will throw an IllegalArgumentException if the name is not valid
315 // fill in the property names
316 Sequence
< OUString
> aProps( s_nPropertyCount
);
317 OUString
* pProperty
= aProps
.getArray();
319 for ( ControlPropertyIterator aProp
= s_pProperties
; aProp
!= s_pPropertiesEnd
; ++aProp
)
320 if ( 0 != ( nPropertyMask
& aProp
->nPropertyId
) )
321 *pProperty
++ = OUString::createFromAscii( aProp
->pPropertyName
);
323 aProps
.realloc( pProperty
- aProps
.getArray() );
327 // --------------------------------------------------------------------------
328 sal_Bool
OControlAccess::isControlSupported( const OUString
& _rControlName
)
330 ControlDescription tmpDesc
;
331 tmpDesc
.pControlName
= OUStringToOString(_rControlName
, RTL_TEXTENCODING_UTF8
).getStr();
332 return ::std::binary_search( s_pControls
, s_pControlsEnd
, tmpDesc
, ControlDescriptionLookup() );
335 // --------------------------------------------------------------------------
336 sal_Bool
OControlAccess::isControlPropertySupported( const OUString
& _rControlName
, const OUString
& _rControlProperty
)
338 // look up the control
339 sal_Int16 nControlId
= -1;
340 sal_Int32 nPropertyMask
= 0;
341 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
342 // will throw an IllegalArgumentException if the name is not valid
344 // look up the property
345 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
346 if ( aPropDesc
== s_pPropertiesEnd
)
347 // it's a property which is completely unknown
350 return 0 != ( aPropDesc
->nPropertyId
& nPropertyMask
);
353 //-----------------------------------------------------------------------------
354 void OControlAccess::setValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
, const Any
& _rValue
)
356 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
);
357 DBG_ASSERT( pControl
, "OControlAccess::SetValue: don't have this control in the current mode!" );
360 sal_Int16 nPropertyId
= -1;
361 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
363 nPropertyId
= PROPERTY_FLAG_HELPURL
;
367 switch ( _nControlId
)
369 case CHECKBOX_AUTOEXTENSION
:
370 case CHECKBOX_PASSWORD
:
371 case CHECKBOX_FILTEROPTIONS
:
372 case CHECKBOX_READONLY
:
374 case CHECKBOX_PREVIEW
:
375 case CHECKBOX_SELECTION
:
376 nPropertyId
= PROPERTY_FLAG_CHECKED
;
380 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
383 case LISTBOX_VERSION
:
384 case LISTBOX_TEMPLATE
:
385 case LISTBOX_IMAGE_TEMPLATE
:
386 if ( ControlActions::SET_SELECT_ITEM
== _nControlAction
)
388 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
392 DBG_ASSERT( WINDOW_LISTBOX
== pControl
->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" );
393 implDoListboxAction( static_cast< ListBox
* >( pControl
), _nControlAction
, _rValue
);
399 if ( -1 != nPropertyId
)
400 implSetControlProperty( _nControlId
, pControl
, nPropertyId
, _rValue
);
404 //-----------------------------------------------------------------------------
405 Any
OControlAccess::getValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
) const
409 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
, sal_False
);
410 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
413 sal_Int16 nPropertyId
= -1;
414 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
416 nPropertyId
= PROPERTY_FLAG_HELPURL
;
420 switch ( _nControlId
)
422 case CHECKBOX_AUTOEXTENSION
:
423 case CHECKBOX_PASSWORD
:
424 case CHECKBOX_FILTEROPTIONS
:
425 case CHECKBOX_READONLY
:
427 case CHECKBOX_PREVIEW
:
428 case CHECKBOX_SELECTION
:
429 nPropertyId
= PROPERTY_FLAG_CHECKED
;
433 if ( ControlActions::GET_SELECTED_ITEM
== _nControlAction
)
435 aRet
<<= OUString( m_pFilePickerController
->getCurFilter() );;
439 SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
443 case LISTBOX_VERSION
:
444 case LISTBOX_TEMPLATE
:
445 case LISTBOX_IMAGE_TEMPLATE
:
446 switch ( _nControlAction
)
448 case ControlActions::GET_SELECTED_ITEM
:
449 nPropertyId
= PROPERTY_FLAG_SELECTEDITEM
;
451 case ControlActions::GET_SELECTED_ITEM_INDEX
:
452 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
454 case ControlActions::GET_ITEMS
:
455 nPropertyId
= PROPERTY_FLAG_LISTITEMS
;
458 SAL_WARN( "fpicker.office", "OControlAccess::GetValue: invalid control action for the listbox!" );
465 if ( -1 != nPropertyId
)
466 aRet
= implGetControlProperty( pControl
, nPropertyId
);
472 //-----------------------------------------------------------------------------
473 void OControlAccess::setLabel( sal_Int16 nId
, const OUString
&rLabel
)
475 Control
* pControl
= m_pFilePickerController
->getControl( nId
, sal_True
);
476 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
478 pControl
->SetText( rLabel
);
481 //-----------------------------------------------------------------------------
482 OUString
OControlAccess::getLabel( sal_Int16 nId
) const
486 Control
* pControl
= m_pFilePickerController
->getControl( nId
, sal_True
);
487 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
489 sLabel
= pControl
->GetText();
494 //-----------------------------------------------------------------------------
495 void OControlAccess::enableControl( sal_Int16 _nId
, sal_Bool _bEnable
)
497 m_pFilePickerController
->enableControl( _nId
, _bEnable
);
500 // -----------------------------------------------------------------------
501 void OControlAccess::implDoListboxAction( ListBox
* _pListbox
, sal_Int16 _nControlAction
, const Any
& _rValue
)
503 switch ( _nControlAction
)
505 case ControlActions::ADD_ITEM
:
509 if ( !aEntry
.isEmpty() )
510 _pListbox
->InsertEntry( aEntry
);
514 case ControlActions::ADD_ITEMS
:
516 Sequence
< OUString
> aTemplateList
;
517 _rValue
>>= aTemplateList
;
519 if ( aTemplateList
.getLength() )
521 for ( long i
=0; i
< aTemplateList
.getLength(); i
++ )
522 _pListbox
->InsertEntry( aTemplateList
[i
] );
527 case ControlActions::DELETE_ITEM
:
530 if ( _rValue
>>= nPos
)
531 _pListbox
->RemoveEntry( (sal_uInt16
) nPos
);
535 case ControlActions::DELETE_ITEMS
:
540 SAL_WARN( "fpicker.office", "Wrong ControlAction for implDoListboxAction()" );
544 //-----------------------------------------------------------------------------
545 void OControlAccess::implSetControlProperty( sal_Int16 _nControlId
, Control
* _pControl
, sal_Int16 _nProperty
, const Any
& _rValue
, sal_Bool _bIgnoreIllegalArgument
)
548 _pControl
= m_pFilePickerController
->getControl( _nControlId
);
549 DBG_ASSERT( _pControl
, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
553 DBG_ASSERT( _pControl
== m_pFilePickerController
->getControl( _nControlId
),
554 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
556 switch ( _nProperty
)
558 case PROPERTY_FLAG_TEXT
:
561 if ( _rValue
>>= sText
)
563 _pControl
->SetText( sText
);
565 else if ( !_bIgnoreIllegalArgument
)
567 lcl_throwIllegalArgumentException();
572 case PROPERTY_FLAG_ENDBALED
:
574 sal_Bool bEnabled
= sal_False
;
575 if ( _rValue
>>= bEnabled
)
577 m_pFilePickerController
->enableControl( _nControlId
, bEnabled
);
579 else if ( !_bIgnoreIllegalArgument
)
581 lcl_throwIllegalArgumentException();
586 case PROPERTY_FLAG_VISIBLE
:
588 sal_Bool bVisible
= sal_False
;
589 if ( _rValue
>>= bVisible
)
591 _pControl
->Show( bVisible
);
593 else if ( !_bIgnoreIllegalArgument
)
595 lcl_throwIllegalArgumentException();
600 case PROPERTY_FLAG_HELPURL
:
603 if ( _rValue
>>= sHelpURL
)
605 setHelpURL( _pControl
, sHelpURL
, m_pFileView
== _pControl
);
607 else if ( !_bIgnoreIllegalArgument
)
609 lcl_throwIllegalArgumentException();
614 case PROPERTY_FLAG_LISTITEMS
:
616 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
617 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
619 Sequence
< OUString
> aItems
;
620 if ( _rValue
>>= aItems
)
622 // remove all previous items
623 static_cast< ListBox
* >( _pControl
)->Clear();
626 const OUString
* pItems
= aItems
.getConstArray();
627 const OUString
* pItemsEnd
= aItems
.getConstArray() + aItems
.getLength();
628 for ( const OUString
* pItem
= pItems
;
633 static_cast< ListBox
* >( _pControl
)->InsertEntry( *pItem
);
637 else if ( !_bIgnoreIllegalArgument
)
639 lcl_throwIllegalArgumentException();
644 case PROPERTY_FLAG_SELECTEDITEM
:
646 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
647 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
650 if ( _rValue
>>= sSelected
)
652 static_cast< ListBox
* >( _pControl
)->SelectEntry( sSelected
);
654 else if ( !_bIgnoreIllegalArgument
)
656 lcl_throwIllegalArgumentException();
661 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
663 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
664 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
667 if ( _rValue
>>= nPos
)
669 static_cast< ListBox
* >( _pControl
)->SelectEntryPos( (sal_uInt16
) nPos
);
671 else if ( !_bIgnoreIllegalArgument
)
673 lcl_throwIllegalArgumentException();
678 case PROPERTY_FLAG_CHECKED
:
680 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
681 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
683 sal_Bool bChecked
= sal_False
;
684 if ( _rValue
>>= bChecked
)
686 static_cast< CheckBox
* >( _pControl
)->Check( bChecked
);
688 else if ( !_bIgnoreIllegalArgument
)
690 lcl_throwIllegalArgumentException();
696 OSL_FAIL( "OControlAccess::implSetControlProperty: invalid property id!" );
700 //-----------------------------------------------------------------------------
701 Any
OControlAccess::implGetControlProperty( Control
* _pControl
, sal_Int16 _nProperty
) const
703 DBG_ASSERT( _pControl
, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" );
706 switch ( _nProperty
)
708 case PROPERTY_FLAG_TEXT
:
709 aReturn
<<= OUString( _pControl
->GetText() );
712 case PROPERTY_FLAG_ENDBALED
:
713 aReturn
<<= (sal_Bool
)_pControl
->IsEnabled();
716 case PROPERTY_FLAG_VISIBLE
:
717 aReturn
<<= (sal_Bool
)_pControl
->IsVisible();
720 case PROPERTY_FLAG_HELPURL
:
721 aReturn
<<= getHelpURL( _pControl
, m_pFileView
== _pControl
);
724 case PROPERTY_FLAG_LISTITEMS
:
726 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
727 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
729 Sequence
< OUString
> aItems( static_cast< ListBox
* >( _pControl
)->GetEntryCount() );
730 OUString
* pItems
= aItems
.getArray();
731 for ( sal_uInt16 i
=0; i
<static_cast< ListBox
* >( _pControl
)->GetEntryCount(); ++i
)
732 *pItems
++ = static_cast< ListBox
* >( _pControl
)->GetEntry( i
);
738 case PROPERTY_FLAG_SELECTEDITEM
:
740 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
741 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
743 sal_uInt16 nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
745 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
746 sSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntry();
747 aReturn
<<= sSelected
;
751 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
753 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
754 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
756 sal_uInt16 nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
757 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
758 aReturn
<<= (sal_Int32
)static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
760 aReturn
<<= (sal_Int32
)-1;
764 case PROPERTY_FLAG_CHECKED
:
765 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
766 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
768 aReturn
<<= (sal_Bool
)static_cast< CheckBox
* >( _pControl
)->IsChecked( );
772 OSL_FAIL( "OControlAccess::implGetControlProperty: invalid property id!" );
777 //.........................................................................
779 //.........................................................................
781 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */