1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
31 #include "OfficeControlAccess.hxx"
32 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
33 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
34 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
35 #include <vcl/lstbox.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <tools/urlobj.hxx>
42 //.........................................................................
45 //.........................................................................
47 // helper -------------------------------------------------------------
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::ui::dialogs
;
53 using namespace ExtendedFilePickerElementIds
;
54 using namespace CommonFilePickerElementIds
;
55 using namespace InternalFilePickerElementIds
;
57 // --------------------------------------------------------------------
60 // ----------------------------------------------------------------
61 #define PROPERTY_FLAG_TEXT 0x00000001
62 #define PROPERTY_FLAG_ENDBALED 0x00000002
63 #define PROPERTY_FLAG_VISIBLE 0x00000004
64 #define PROPERTY_FLAG_HELPURL 0x00000008
65 #define PROPERTY_FLAG_LISTITEMS 0x00000010
66 #define PROPERTY_FLAG_SELECTEDITEM 0x00000020
67 #define PROPERTY_FLAG_SELECTEDITEMINDEX 0x00000040
68 #define PROPERTY_FLAG_CHECKED 0x00000080
70 // ----------------------------------------------------------------
71 // ................................................................
72 struct ControlDescription
74 const sal_Char
* pControlName
;
76 sal_Int32 nPropertyFlags
;
79 // ................................................................
80 typedef const ControlDescription
* ControlDescIterator
;
81 typedef ::std::pair
< ControlDescIterator
, ControlDescIterator
> ControlDescRange
;
83 // ......................................................................
84 #define PROPERTY_FLAGS_COMMON ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL )
85 #define PROPERTY_FLAGS_LISTBOX ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX )
86 #define PROPERTY_FLAGS_CHECKBOX ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT )
88 // Note: this array MUST be sorted by name!
89 static const ControlDescription aDescriptions
[] = {
90 { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
91 { "CancelButton", PUSHBUTTON_CANCEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
92 { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
93 { "DefaultLocationButton", TOOLBOXBUTOON_DEFAULT_LOCATION
, PROPERTY_FLAGS_COMMON
},
94 { "FileURLEdit", EDIT_FILEURL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
95 { "FileURLEditLabel", EDIT_FILEURL_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
96 { "FileView", CONTROL_FILEVIEW
, PROPERTY_FLAGS_COMMON
},
97 { "FilterList", LISTBOX_FILTER
, PROPERTY_FLAGS_COMMON
},
98 { "FilterListLabel", LISTBOX_FILTER_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
99 { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
100 { "HelpButton", PUSHBUTTON_HELP
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
101 { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
102 { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
103 { "LevelUpButton", TOOLBOXBUTOON_LEVEL_UP
, PROPERTY_FLAGS_COMMON
},
104 { "LinkBox", CHECKBOX_LINK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
105 { "NewFolderButton", TOOLBOXBUTOON_NEW_FOLDER
, PROPERTY_FLAGS_COMMON
},
106 { "OkButton", PUSHBUTTON_OK
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
107 { "PasswordBox", CHECKBOX_PASSWORD
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
108 { "PlayButton", PUSHBUTTON_PLAY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
109 { "PreviewBox", CHECKBOX_PREVIEW
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
110 { "ReadOnlyBox", CHECKBOX_READONLY
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
111 { "SelectionBox", CHECKBOX_SELECTION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_CHECKBOX
},
112 { "TemplateList", LISTBOX_TEMPLATE
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
113 { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
},
114 { "VersionList", LISTBOX_VERSION
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAGS_LISTBOX
},
115 { "VersionListLabel", LISTBOX_VERSION_LABEL
, PROPERTY_FLAGS_COMMON
| PROPERTY_FLAG_TEXT
}
118 // ................................................................
119 static const sal_Int32 s_nControlCount
= sizeof( aDescriptions
) / sizeof( aDescriptions
[0] );
121 static ControlDescIterator s_pControls
= aDescriptions
;
122 static ControlDescIterator s_pControlsEnd
= aDescriptions
+ s_nControlCount
;
124 // ................................................................
125 struct ControlDescriptionLookup
127 bool operator()( const ::rtl::OUString
& _rLookup
, const ControlDescription
& _rDesc
)
129 return _rLookup
.compareToAscii( _rDesc
.pControlName
) < 0;
131 bool operator()( const ControlDescription
& _rDesc
, const ::rtl::OUString
& _rLookup
)
133 return _rLookup
.compareToAscii( _rDesc
.pControlName
) > 0;
137 // ................................................................
138 struct ExtractControlName
: public ::std::unary_function
< ControlDescription
, ::rtl::OUString
>
140 ::rtl::OUString
operator()( const ControlDescription
& _rDesc
)
142 return ::rtl::OUString::createFromAscii( _rDesc
.pControlName
);
146 // ----------------------------------------------------------------
147 // ................................................................
148 struct ControlProperty
150 const sal_Char
* pPropertyName
;
151 sal_Int16 nPropertyId
;
154 typedef const ControlProperty
* ControlPropertyIterator
;
156 // ................................................................
157 static const ControlProperty aProperties
[] = {
158 { "Text", PROPERTY_FLAG_TEXT
},
159 { "Enabled", PROPERTY_FLAG_ENDBALED
},
160 { "Visible", PROPERTY_FLAG_VISIBLE
},
161 { "HelpURL", PROPERTY_FLAG_HELPURL
},
162 { "ListItems", PROPERTY_FLAG_LISTITEMS
},
163 { "SelectedItem", PROPERTY_FLAG_SELECTEDITEM
},
164 { "SelectedItemIndex", PROPERTY_FLAG_SELECTEDITEMINDEX
},
165 { "Checked", PROPERTY_FLAG_CHECKED
}
168 // ................................................................
169 static const int s_nPropertyCount
= sizeof( aProperties
) / sizeof( aProperties
[0] );
171 static ControlPropertyIterator s_pProperties
= aProperties
;
172 static ControlPropertyIterator s_pPropertiesEnd
= aProperties
+ s_nPropertyCount
;
174 // ................................................................
175 struct ControlPropertyLookup
177 ::rtl::OUString m_sLookup
;
178 ControlPropertyLookup( const ::rtl::OUString
& _rLookup
) : m_sLookup( _rLookup
) { }
180 sal_Bool
operator()( const ControlProperty
& _rProp
)
182 return m_sLookup
.equalsAscii( _rProp
.pPropertyName
);
186 //-----------------------------------------------------------------
187 void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException
) )
189 throw IllegalArgumentException();
190 // TODO: error message in the exception
194 //---------------------------------------------------------------------
195 OControlAccess::OControlAccess( IFilePickerController
* _pController
, SvtFileView
* _pFileView
)
196 :m_pFilePickerController( _pController
)
197 ,m_pFileView( _pFileView
)
199 DBG_ASSERT( m_pFilePickerController
, "OControlAccess::OControlAccess: invalid control locator!" );
202 //---------------------------------------------------------------------
203 void OControlAccess::setHelpURL( Window
* _pControl
, const ::rtl::OUString
& sHelpURL
, sal_Bool _bFileView
)
205 rtl::OUString
sHelpID( sHelpURL
);
206 INetURLObject
aHID( sHelpURL
);
207 if ( aHID
.GetProtocol() == INET_PROT_HID
)
208 sHelpID
= aHID
.GetURLPath();
210 // URLs should always be UTF8 encoded and escaped
211 rtl::OString
sID( rtl::OUStringToOString( sHelpID
, RTL_TEXTENCODING_UTF8
) );
213 // the file view "overloaded" the SetHelpId
214 static_cast< SvtFileView
* >( _pControl
)->SetHelpId( sID
);
216 _pControl
->SetHelpId( sID
);
219 //---------------------------------------------------------------------
220 ::rtl::OUString
OControlAccess::getHelpURL( Window
* _pControl
, sal_Bool _bFileView
)
222 rtl::OString aHelpId
= _pControl
->GetHelpId();
224 // the file view "overloaded" the SetHelpId
225 aHelpId
= static_cast< SvtFileView
* >( _pControl
)->GetHelpId( );
227 ::rtl::OUString sHelpURL
;
228 ::rtl::OUString
aTmp( rtl::OStringToOUString( aHelpId
, RTL_TEXTENCODING_UTF8
) );
229 INetURLObject
aHID( aTmp
);
230 if ( aHID
.GetProtocol() == INET_PROT_NOT_VALID
)
231 sHelpURL
= rtl::OUString::createFromAscii( INET_HID_SCHEME
);
236 // --------------------------------------------------------------------------
237 Any
OControlAccess::getControlProperty( const ::rtl::OUString
& _rControlName
, const ::rtl::OUString
& _rControlProperty
)
239 // look up the control
240 sal_Int16 nControlId
= -1;
241 sal_Int32 nPropertyMask
= 0;
242 Control
* pControl
= implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
243 // will throw an IllegalArgumentException if the name is not valid
245 // look up the property
246 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
247 if ( aPropDesc
== s_pPropertiesEnd
)
248 // it's a completely unknown property
249 lcl_throwIllegalArgumentException();
251 if ( 0 == ( nPropertyMask
& aPropDesc
->nPropertyId
) )
252 // it's a property which is known, but not allowed for this control
253 lcl_throwIllegalArgumentException();
255 return implGetControlProperty( pControl
, aPropDesc
->nPropertyId
);
258 //---------------------------------------------------------------------
259 Control
* OControlAccess::implGetControl( const ::rtl::OUString
& _rControlName
, sal_Int16
* _pId
, sal_Int32
* _pPropertyMask
) const SAL_THROW( (IllegalArgumentException
) )
261 Control
* pControl
= NULL
;
263 // translate the name into an id
264 ControlDescRange aFoundRange
= ::std::equal_range( s_pControls
, s_pControlsEnd
, _rControlName
, ControlDescriptionLookup() );
265 if ( aFoundRange
.first
!= aFoundRange
.second
)
267 // get the VCL control determined by this id
268 pControl
= m_pFilePickerController
->getControl( aFoundRange
.first
->nControlId
);
271 // if not found 'til here, the name is invalid, or we do not have the control in the current mode
273 lcl_throwIllegalArgumentException();
275 // out parameters and outta here
277 *_pId
= aFoundRange
.first
->nControlId
;
278 if ( _pPropertyMask
)
279 *_pPropertyMask
= aFoundRange
.first
->nPropertyFlags
;
284 //---------------------------------------------------------------------
285 void OControlAccess::setControlProperty( const ::rtl::OUString
& _rControlName
, const ::rtl::OUString
& _rControlProperty
, const ::com::sun::star::uno::Any
& _rValue
)
287 // look up the control
288 sal_Int16 nControlId
= -1;
289 Control
* pControl
= implGetControl( _rControlName
, &nControlId
);
290 // will throw an IllegalArgumentException if the name is not valid
292 // look up the property
293 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
294 if ( aPropDesc
== s_pPropertiesEnd
)
295 lcl_throwIllegalArgumentException();
298 implSetControlProperty( nControlId
, pControl
, aPropDesc
->nPropertyId
, _rValue
, sal_False
);
301 // --------------------------------------------------------------------------
302 Sequence
< ::rtl::OUString
> OControlAccess::getSupportedControls( )
304 Sequence
< ::rtl::OUString
> aControls( s_nControlCount
);
305 ::rtl::OUString
* pControls
= aControls
.getArray();
307 // collect the names of all _actually_existent_ controls
308 for ( ControlDescIterator aControl
= s_pControls
; aControl
!= s_pControlsEnd
; ++aControl
)
310 if ( m_pFilePickerController
->getControl( aControl
->nControlId
) )
311 *pControls
++ = ::rtl::OUString::createFromAscii( aControl
->pControlName
);
314 aControls
.realloc( pControls
- aControls
.getArray() );
318 // --------------------------------------------------------------------------
319 Sequence
< ::rtl::OUString
> OControlAccess::getSupportedControlProperties( const ::rtl::OUString
& _rControlName
)
321 sal_Int16 nControlId
= -1;
322 sal_Int32 nPropertyMask
= 0;
323 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
324 // will throw an IllegalArgumentException if the name is not valid
326 // fill in the property names
327 Sequence
< ::rtl::OUString
> aProps( s_nPropertyCount
);
328 ::rtl::OUString
* pProperty
= aProps
.getArray();
330 for ( ControlPropertyIterator aProp
= s_pProperties
; aProp
!= s_pPropertiesEnd
; ++aProp
)
331 if ( 0 != ( nPropertyMask
& aProp
->nPropertyId
) )
332 *pProperty
++ = ::rtl::OUString::createFromAscii( aProp
->pPropertyName
);
334 aProps
.realloc( pProperty
- aProps
.getArray() );
338 // --------------------------------------------------------------------------
339 sal_Bool
OControlAccess::isControlSupported( const ::rtl::OUString
& _rControlName
)
341 return ::std::binary_search( s_pControls
, s_pControlsEnd
, _rControlName
, ControlDescriptionLookup() );
344 // --------------------------------------------------------------------------
345 sal_Bool
OControlAccess::isControlPropertySupported( const ::rtl::OUString
& _rControlName
, const ::rtl::OUString
& _rControlProperty
)
347 // look up the control
348 sal_Int16 nControlId
= -1;
349 sal_Int32 nPropertyMask
= 0;
350 implGetControl( _rControlName
, &nControlId
, &nPropertyMask
);
351 // will throw an IllegalArgumentException if the name is not valid
353 // look up the property
354 ControlPropertyIterator aPropDesc
= ::std::find_if( s_pProperties
, s_pPropertiesEnd
, ControlPropertyLookup( _rControlProperty
) );
355 if ( aPropDesc
== s_pPropertiesEnd
)
356 // it's a property which is completely unknown
359 return 0 != ( aPropDesc
->nPropertyId
& nPropertyMask
);
362 //-----------------------------------------------------------------------------
363 void OControlAccess::setValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
, const Any
& _rValue
)
365 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
);
366 DBG_ASSERT( pControl
, "OControlAccess::SetValue: don't have this control in the current mode!" );
369 sal_Int16 nPropertyId
= -1;
370 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
372 nPropertyId
= PROPERTY_FLAG_HELPURL
;
376 switch ( _nControlId
)
378 case CHECKBOX_AUTOEXTENSION
:
379 case CHECKBOX_PASSWORD
:
380 case CHECKBOX_FILTEROPTIONS
:
381 case CHECKBOX_READONLY
:
383 case CHECKBOX_PREVIEW
:
384 case CHECKBOX_SELECTION
:
385 nPropertyId
= PROPERTY_FLAG_CHECKED
;
389 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
392 case LISTBOX_VERSION
:
393 case LISTBOX_TEMPLATE
:
394 case LISTBOX_IMAGE_TEMPLATE
:
395 if ( ControlActions::SET_SELECT_ITEM
== _nControlAction
)
397 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
401 DBG_ASSERT( WINDOW_LISTBOX
== pControl
->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" );
402 implDoListboxAction( static_cast< ListBox
* >( pControl
), _nControlAction
, _rValue
);
408 if ( -1 != nPropertyId
)
409 implSetControlProperty( _nControlId
, pControl
, nPropertyId
, _rValue
);
413 //-----------------------------------------------------------------------------
414 Any
OControlAccess::getValue( sal_Int16 _nControlId
, sal_Int16 _nControlAction
) const
418 Control
* pControl
= m_pFilePickerController
->getControl( _nControlId
, sal_False
);
419 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
422 sal_Int16 nPropertyId
= -1;
423 if ( ControlActions::SET_HELP_URL
== _nControlAction
)
425 nPropertyId
= PROPERTY_FLAG_HELPURL
;
429 switch ( _nControlId
)
431 case CHECKBOX_AUTOEXTENSION
:
432 case CHECKBOX_PASSWORD
:
433 case CHECKBOX_FILTEROPTIONS
:
434 case CHECKBOX_READONLY
:
436 case CHECKBOX_PREVIEW
:
437 case CHECKBOX_SELECTION
:
438 nPropertyId
= PROPERTY_FLAG_CHECKED
;
442 if ( ControlActions::GET_SELECTED_ITEM
== _nControlAction
)
444 aRet
<<= ::rtl::OUString( m_pFilePickerController
->getCurFilter() );;
448 DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
452 case LISTBOX_VERSION
:
453 case LISTBOX_TEMPLATE
:
454 case LISTBOX_IMAGE_TEMPLATE
:
455 switch ( _nControlAction
)
457 case ControlActions::GET_SELECTED_ITEM
:
458 nPropertyId
= PROPERTY_FLAG_SELECTEDITEM
;
460 case ControlActions::GET_SELECTED_ITEM_INDEX
:
461 nPropertyId
= PROPERTY_FLAG_SELECTEDITEMINDEX
;
463 case ControlActions::GET_ITEMS
:
464 nPropertyId
= PROPERTY_FLAG_LISTITEMS
;
467 DBG_ERRORFILE( "OControlAccess::GetValue: invalid control action for the listbox!" );
474 if ( -1 != nPropertyId
)
475 aRet
= implGetControlProperty( pControl
, nPropertyId
);
481 //-----------------------------------------------------------------------------
482 void OControlAccess::setLabel( sal_Int16 nId
, const ::rtl::OUString
&rLabel
)
484 Control
* pControl
= m_pFilePickerController
->getControl( nId
, sal_True
);
485 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
487 pControl
->SetText( rLabel
);
490 //-----------------------------------------------------------------------------
491 ::rtl::OUString
OControlAccess::getLabel( sal_Int16 nId
) const
493 ::rtl::OUString sLabel
;
495 Control
* pControl
= m_pFilePickerController
->getControl( nId
, sal_True
);
496 DBG_ASSERT( pControl
, "OControlAccess::GetValue: don't have this control in the current mode!" );
498 sLabel
= pControl
->GetText();
503 //-----------------------------------------------------------------------------
504 void OControlAccess::enableControl( sal_Int16 _nId
, sal_Bool _bEnable
)
506 m_pFilePickerController
->enableControl( _nId
, _bEnable
);
509 // -----------------------------------------------------------------------
510 void OControlAccess::implDoListboxAction( ListBox
* _pListbox
, sal_Int16 _nControlAction
, const Any
& _rValue
)
512 switch ( _nControlAction
)
514 case ControlActions::ADD_ITEM
:
516 ::rtl::OUString aEntry
;
518 if ( aEntry
.getLength() )
519 _pListbox
->InsertEntry( aEntry
);
523 case ControlActions::ADD_ITEMS
:
525 Sequence
< ::rtl::OUString
> aTemplateList
;
526 _rValue
>>= aTemplateList
;
528 if ( aTemplateList
.getLength() )
530 for ( long i
=0; i
< aTemplateList
.getLength(); i
++ )
531 _pListbox
->InsertEntry( aTemplateList
[i
] );
536 case ControlActions::DELETE_ITEM
:
539 if ( _rValue
>>= nPos
)
540 _pListbox
->RemoveEntry( (sal_uInt16
) nPos
);
544 case ControlActions::DELETE_ITEMS
:
549 DBG_ERRORFILE( "Wrong ControlAction for implDoListboxAction()" );
553 //-----------------------------------------------------------------------------
554 void OControlAccess::implSetControlProperty( sal_Int16 _nControlId
, Control
* _pControl
, sal_Int16 _nProperty
, const Any
& _rValue
, sal_Bool _bIgnoreIllegalArgument
)
557 _pControl
= m_pFilePickerController
->getControl( _nControlId
);
558 DBG_ASSERT( _pControl
, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
562 DBG_ASSERT( _pControl
== m_pFilePickerController
->getControl( _nControlId
),
563 "OControlAccess::implSetControlProperty: inconsistent parameters!" );
565 switch ( _nProperty
)
567 case PROPERTY_FLAG_TEXT
:
569 ::rtl::OUString sText
;
570 if ( _rValue
>>= sText
)
572 _pControl
->SetText( sText
);
574 else if ( !_bIgnoreIllegalArgument
)
576 lcl_throwIllegalArgumentException();
581 case PROPERTY_FLAG_ENDBALED
:
583 sal_Bool bEnabled
= sal_False
;
584 if ( _rValue
>>= bEnabled
)
586 m_pFilePickerController
->enableControl( _nControlId
, bEnabled
);
588 else if ( !_bIgnoreIllegalArgument
)
590 lcl_throwIllegalArgumentException();
595 case PROPERTY_FLAG_VISIBLE
:
597 sal_Bool bVisible
= sal_False
;
598 if ( _rValue
>>= bVisible
)
600 _pControl
->Show( bVisible
);
602 else if ( !_bIgnoreIllegalArgument
)
604 lcl_throwIllegalArgumentException();
609 case PROPERTY_FLAG_HELPURL
:
611 ::rtl::OUString sHelpURL
;
612 if ( _rValue
>>= sHelpURL
)
614 setHelpURL( _pControl
, sHelpURL
, m_pFileView
== _pControl
);
616 else if ( !_bIgnoreIllegalArgument
)
618 lcl_throwIllegalArgumentException();
623 case PROPERTY_FLAG_LISTITEMS
:
625 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
626 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
628 Sequence
< ::rtl::OUString
> aItems
;
629 if ( _rValue
>>= aItems
)
631 // remove all previous items
632 static_cast< ListBox
* >( _pControl
)->Clear();
635 const ::rtl::OUString
* pItems
= aItems
.getConstArray();
636 const ::rtl::OUString
* pItemsEnd
= aItems
.getConstArray() + aItems
.getLength();
637 for ( const ::rtl::OUString
* pItem
= pItems
;
642 static_cast< ListBox
* >( _pControl
)->InsertEntry( *pItem
);
646 else if ( !_bIgnoreIllegalArgument
)
648 lcl_throwIllegalArgumentException();
653 case PROPERTY_FLAG_SELECTEDITEM
:
655 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
656 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
658 ::rtl::OUString sSelected
;
659 if ( _rValue
>>= sSelected
)
661 static_cast< ListBox
* >( _pControl
)->SelectEntry( sSelected
);
663 else if ( !_bIgnoreIllegalArgument
)
665 lcl_throwIllegalArgumentException();
670 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
672 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
673 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
676 if ( _rValue
>>= nPos
)
678 static_cast< ListBox
* >( _pControl
)->SelectEntryPos( (sal_uInt16
) nPos
);
680 else if ( !_bIgnoreIllegalArgument
)
682 lcl_throwIllegalArgumentException();
687 case PROPERTY_FLAG_CHECKED
:
689 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
690 "OControlAccess::implSetControlProperty: invalid control/property combination!" );
692 sal_Bool bChecked
= sal_False
;
693 if ( _rValue
>>= bChecked
)
695 static_cast< CheckBox
* >( _pControl
)->Check( bChecked
);
697 else if ( !_bIgnoreIllegalArgument
)
699 lcl_throwIllegalArgumentException();
705 DBG_ERROR( "OControlAccess::implSetControlProperty: invalid property id!" );
709 //-----------------------------------------------------------------------------
710 Any
OControlAccess::implGetControlProperty( Control
* _pControl
, sal_Int16 _nProperty
) const
712 DBG_ASSERT( _pControl
, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" );
715 switch ( _nProperty
)
717 case PROPERTY_FLAG_TEXT
:
718 aReturn
<<= ::rtl::OUString( _pControl
->GetText() );
721 case PROPERTY_FLAG_ENDBALED
:
722 aReturn
<<= (sal_Bool
)_pControl
->IsEnabled();
725 case PROPERTY_FLAG_VISIBLE
:
726 aReturn
<<= (sal_Bool
)_pControl
->IsVisible();
729 case PROPERTY_FLAG_HELPURL
:
730 aReturn
<<= getHelpURL( _pControl
, m_pFileView
== _pControl
);
733 case PROPERTY_FLAG_LISTITEMS
:
735 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
736 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
738 Sequence
< ::rtl::OUString
> aItems( static_cast< ListBox
* >( _pControl
)->GetEntryCount() );
739 ::rtl::OUString
* pItems
= aItems
.getArray();
740 for ( sal_uInt16 i
=0; i
<static_cast< ListBox
* >( _pControl
)->GetEntryCount(); ++i
)
741 *pItems
++ = static_cast< ListBox
* >( _pControl
)->GetEntry( i
);
747 case PROPERTY_FLAG_SELECTEDITEM
:
749 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
750 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
752 sal_uInt16 nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
753 ::rtl::OUString sSelected
;
754 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
755 sSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntry();
756 aReturn
<<= sSelected
;
760 case PROPERTY_FLAG_SELECTEDITEMINDEX
:
762 DBG_ASSERT( WINDOW_LISTBOX
== _pControl
->GetType(),
763 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
765 sal_uInt16 nSelected
= static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
766 if ( LISTBOX_ENTRY_NOTFOUND
!= nSelected
)
767 aReturn
<<= (sal_Int32
)static_cast< ListBox
* >( _pControl
)->GetSelectEntryPos();
769 aReturn
<<= (sal_Int32
)-1;
773 case PROPERTY_FLAG_CHECKED
:
774 DBG_ASSERT( WINDOW_CHECKBOX
== _pControl
->GetType(),
775 "OControlAccess::implGetControlProperty: invalid control/property combination!" );
777 aReturn
<<= (sal_Bool
)static_cast< CheckBox
* >( _pControl
)->IsChecked( );
781 DBG_ERROR( "OControlAccess::implGetControlProperty: invalid property id!" );
786 //.........................................................................
788 //.........................................................................