1*b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b557fc96SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b557fc96SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b557fc96SAndrew Rist  * distributed with this work for additional information
6*b557fc96SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b557fc96SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b557fc96SAndrew Rist  * "License"); you may not use this file except in compliance
9*b557fc96SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b557fc96SAndrew Rist  *
11*b557fc96SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b557fc96SAndrew Rist  *
13*b557fc96SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b557fc96SAndrew Rist  * software distributed under the License is distributed on an
15*b557fc96SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b557fc96SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b557fc96SAndrew Rist  * specific language governing permissions and limitations
18*b557fc96SAndrew Rist  * under the License.
19*b557fc96SAndrew Rist  *
20*b557fc96SAndrew Rist  *************************************************************/
21*b557fc96SAndrew Rist 
22*b557fc96SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "OfficeControlAccess.hxx"
28cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
29cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ControlActions.hpp>
31cdf0e10cSrcweir #include <vcl/lstbox.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
33cdf0e10cSrcweir #include <tools/urlobj.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <algorithm>
36cdf0e10cSrcweir #include <functional>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //.........................................................................
39cdf0e10cSrcweir namespace svt
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //.........................................................................
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 	// helper -------------------------------------------------------------
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
46cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
47cdf0e10cSrcweir 	using namespace ::com::sun::star::ui::dialogs;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	using namespace ExtendedFilePickerElementIds;
50cdf0e10cSrcweir 	using namespace CommonFilePickerElementIds;
51cdf0e10cSrcweir 	using namespace InternalFilePickerElementIds;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	// --------------------------------------------------------------------
54cdf0e10cSrcweir 	namespace
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir 		// ----------------------------------------------------------------
57cdf0e10cSrcweir 		#define PROPERTY_FLAG_TEXT					0x00000001
58cdf0e10cSrcweir 		#define PROPERTY_FLAG_ENDBALED				0x00000002
59cdf0e10cSrcweir 		#define PROPERTY_FLAG_VISIBLE				0x00000004
60cdf0e10cSrcweir 		#define PROPERTY_FLAG_HELPURL				0x00000008
61cdf0e10cSrcweir 		#define PROPERTY_FLAG_LISTITEMS				0x00000010
62cdf0e10cSrcweir 		#define PROPERTY_FLAG_SELECTEDITEM			0x00000020
63cdf0e10cSrcweir 		#define PROPERTY_FLAG_SELECTEDITEMINDEX		0x00000040
64cdf0e10cSrcweir 		#define PROPERTY_FLAG_CHECKED				0x00000080
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 		// ----------------------------------------------------------------
67cdf0e10cSrcweir 		// ................................................................
68cdf0e10cSrcweir 		struct ControlDescription
69cdf0e10cSrcweir 		{
70cdf0e10cSrcweir 			const sal_Char*	pControlName;
71cdf0e10cSrcweir 			sal_Int16		nControlId;
72cdf0e10cSrcweir 			sal_Int32		nPropertyFlags;
73cdf0e10cSrcweir 		};
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 		// ................................................................
76cdf0e10cSrcweir 		typedef const ControlDescription* ControlDescIterator;
77cdf0e10cSrcweir 		typedef ::std::pair< ControlDescIterator, ControlDescIterator >	ControlDescRange;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 		// ......................................................................
80cdf0e10cSrcweir 		#define PROPERTY_FLAGS_COMMON		( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL )
81cdf0e10cSrcweir 		#define PROPERTY_FLAGS_LISTBOX		( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX )
82cdf0e10cSrcweir 		#define PROPERTY_FLAGS_CHECKBOX		( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT )
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		// Note: this array MUST be sorted by name!
85cdf0e10cSrcweir 		static const ControlDescription aDescriptions[] =  {
86cdf0e10cSrcweir 			{ "AutoExtensionBox",		CHECKBOX_AUTOEXTENSION,			PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX		},
87cdf0e10cSrcweir 			{ "CancelButton",			PUSHBUTTON_CANCEL,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
88cdf0e10cSrcweir 			{ "CurrentFolderText",		FIXEDTEXT_CURRENTFOLDER,		PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
89cdf0e10cSrcweir 			{ "DefaultLocationButton",	TOOLBOXBUTOON_DEFAULT_LOCATION,	PROPERTY_FLAGS_COMMON								},
90cdf0e10cSrcweir 			{ "FileURLEdit",			EDIT_FILEURL,					PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
91cdf0e10cSrcweir 			{ "FileURLEditLabel",		EDIT_FILEURL_LABEL,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
92cdf0e10cSrcweir 			{ "FileView",				CONTROL_FILEVIEW,				PROPERTY_FLAGS_COMMON								},
93cdf0e10cSrcweir 			{ "FilterList",				LISTBOX_FILTER,					PROPERTY_FLAGS_COMMON								},
94cdf0e10cSrcweir 			{ "FilterListLabel",		LISTBOX_FILTER_LABEL,			PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
95cdf0e10cSrcweir 			{ "FilterOptionsBox",		CHECKBOX_FILTEROPTIONS,			PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX		},
96cdf0e10cSrcweir 			{ "HelpButton",				PUSHBUTTON_HELP,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
97cdf0e10cSrcweir 			{ "ImageTemplateList",		LISTBOX_IMAGE_TEMPLATE,			PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX		},
98cdf0e10cSrcweir 			{ "ImageTemplateListLabel",	LISTBOX_IMAGE_TEMPLATE_LABEL,	PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
99cdf0e10cSrcweir 			{ "LevelUpButton",			TOOLBOXBUTOON_LEVEL_UP,			PROPERTY_FLAGS_COMMON								},
100cdf0e10cSrcweir 			{ "LinkBox",				CHECKBOX_LINK,					PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX		},
101cdf0e10cSrcweir 			{ "NewFolderButton",		TOOLBOXBUTOON_NEW_FOLDER,		PROPERTY_FLAGS_COMMON								},
102cdf0e10cSrcweir 			{ "OkButton",				PUSHBUTTON_OK ,					PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
103cdf0e10cSrcweir 			{ "PasswordBox",			CHECKBOX_PASSWORD,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX		},
104cdf0e10cSrcweir 			{ "PlayButton",				PUSHBUTTON_PLAY,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
105cdf0e10cSrcweir 			{ "PreviewBox",				CHECKBOX_PREVIEW,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX		},
106cdf0e10cSrcweir 			{ "ReadOnlyBox",			CHECKBOX_READONLY,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX		},
107cdf0e10cSrcweir 			{ "SelectionBox",			CHECKBOX_SELECTION,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX		},
108cdf0e10cSrcweir 			{ "TemplateList",			LISTBOX_TEMPLATE,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX		},
109cdf0e10cSrcweir 			{ "TemplateListLabel",		LISTBOX_TEMPLATE_LABEL,			PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			},
110cdf0e10cSrcweir 			{ "VersionList",			LISTBOX_VERSION,				PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX		},
111cdf0e10cSrcweir 			{ "VersionListLabel",		LISTBOX_VERSION_LABEL,			PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT			}
112cdf0e10cSrcweir 		};
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 		// ................................................................
115cdf0e10cSrcweir 		static const sal_Int32 s_nControlCount = sizeof( aDescriptions ) / sizeof( aDescriptions[0] );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		static ControlDescIterator s_pControls = aDescriptions;
118cdf0e10cSrcweir 		static ControlDescIterator s_pControlsEnd = aDescriptions + s_nControlCount;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		// ................................................................
121cdf0e10cSrcweir 		struct ControlDescriptionLookup
122cdf0e10cSrcweir 		{
operator ()svt::__anon304dad440111::ControlDescriptionLookup123cdf0e10cSrcweir 			bool operator()( const ::rtl::OUString& _rLookup, const ControlDescription& _rDesc )
124cdf0e10cSrcweir 			{
125cdf0e10cSrcweir 				return _rLookup.compareToAscii( _rDesc.pControlName ) < 0;
126cdf0e10cSrcweir 			}
operator ()svt::__anon304dad440111::ControlDescriptionLookup127cdf0e10cSrcweir 			bool operator()( const ControlDescription& _rDesc, const ::rtl::OUString& _rLookup )
128cdf0e10cSrcweir 			{
129cdf0e10cSrcweir 				return _rLookup.compareToAscii( _rDesc.pControlName ) > 0;
130cdf0e10cSrcweir 			}
131cdf0e10cSrcweir 		};
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		// ................................................................
134cdf0e10cSrcweir 		struct ExtractControlName : public ::std::unary_function< ControlDescription, ::rtl::OUString >
135cdf0e10cSrcweir 		{
operator ()svt::__anon304dad440111::ExtractControlName136cdf0e10cSrcweir 			::rtl::OUString operator()( const ControlDescription& _rDesc )
137cdf0e10cSrcweir 			{
138cdf0e10cSrcweir 				return ::rtl::OUString::createFromAscii( _rDesc.pControlName );
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 		};
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		// ----------------------------------------------------------------
143cdf0e10cSrcweir 		// ................................................................
144cdf0e10cSrcweir 		struct ControlProperty
145cdf0e10cSrcweir 		{
146cdf0e10cSrcweir 			const sal_Char* pPropertyName;
147cdf0e10cSrcweir 			sal_Int16		nPropertyId;
148cdf0e10cSrcweir 		};
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		typedef const ControlProperty* ControlPropertyIterator;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 		// ................................................................
153cdf0e10cSrcweir 		static const ControlProperty aProperties[] =  {
154cdf0e10cSrcweir 			{ "Text",				PROPERTY_FLAG_TEXT				},
155cdf0e10cSrcweir 			{ "Enabled",			PROPERTY_FLAG_ENDBALED			},
156cdf0e10cSrcweir 			{ "Visible",			PROPERTY_FLAG_VISIBLE			},
157cdf0e10cSrcweir 			{ "HelpURL",			PROPERTY_FLAG_HELPURL			},
158cdf0e10cSrcweir 			{ "ListItems",			PROPERTY_FLAG_LISTITEMS			},
159cdf0e10cSrcweir 			{ "SelectedItem",		PROPERTY_FLAG_SELECTEDITEM		},
160cdf0e10cSrcweir 			{ "SelectedItemIndex",	PROPERTY_FLAG_SELECTEDITEMINDEX	},
161cdf0e10cSrcweir 			{ "Checked",			PROPERTY_FLAG_CHECKED			}
162cdf0e10cSrcweir 		};
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		// ................................................................
165cdf0e10cSrcweir 		static const int s_nPropertyCount = sizeof( aProperties ) / sizeof( aProperties[0] );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		static ControlPropertyIterator s_pProperties = aProperties;
168cdf0e10cSrcweir 		static ControlPropertyIterator s_pPropertiesEnd = aProperties + s_nPropertyCount;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 		// ................................................................
171cdf0e10cSrcweir 		struct ControlPropertyLookup
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			::rtl::OUString	m_sLookup;
ControlPropertyLookupsvt::__anon304dad440111::ControlPropertyLookup174cdf0e10cSrcweir 			ControlPropertyLookup( const ::rtl::OUString& _rLookup ) : m_sLookup( _rLookup ) { }
175cdf0e10cSrcweir 
operator ()svt::__anon304dad440111::ControlPropertyLookup176cdf0e10cSrcweir 			sal_Bool operator()( const ControlProperty& _rProp )
177cdf0e10cSrcweir 			{
178cdf0e10cSrcweir 				return m_sLookup.equalsAscii( _rProp.pPropertyName );
179cdf0e10cSrcweir 			}
180cdf0e10cSrcweir 		};
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		//-----------------------------------------------------------------
lcl_throwIllegalArgumentException()183cdf0e10cSrcweir 		void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException) )
184cdf0e10cSrcweir 		{
185cdf0e10cSrcweir 			throw IllegalArgumentException();
186cdf0e10cSrcweir 			// TODO: error message in the exception
187cdf0e10cSrcweir 		}
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	//---------------------------------------------------------------------
OControlAccess(IFilePickerController * _pController,SvtFileView * _pFileView)191cdf0e10cSrcweir 	OControlAccess::OControlAccess( IFilePickerController* _pController, SvtFileView* _pFileView )
192cdf0e10cSrcweir 		:m_pFilePickerController( _pController )
193cdf0e10cSrcweir 		,m_pFileView( _pFileView )
194cdf0e10cSrcweir 	{
195cdf0e10cSrcweir 		DBG_ASSERT( m_pFilePickerController, "OControlAccess::OControlAccess: invalid control locator!" );
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	//---------------------------------------------------------------------
setHelpURL(Window * _pControl,const::rtl::OUString & sHelpURL,sal_Bool _bFileView)199cdf0e10cSrcweir 	void OControlAccess::setHelpURL( Window* _pControl, const ::rtl::OUString& sHelpURL, sal_Bool _bFileView )
200cdf0e10cSrcweir 	{
201cdf0e10cSrcweir         rtl::OUString sHelpID( sHelpURL );
202cdf0e10cSrcweir         INetURLObject aHID( sHelpURL );
203cdf0e10cSrcweir         if ( aHID.GetProtocol() == INET_PROT_HID )
204cdf0e10cSrcweir       	    sHelpID = aHID.GetURLPath();
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         // URLs should always be UTF8 encoded and escaped
207cdf0e10cSrcweir 	    rtl::OString sID( rtl::OUStringToOString( sHelpID, RTL_TEXTENCODING_UTF8 ) );
208cdf0e10cSrcweir 		if ( _bFileView )
209cdf0e10cSrcweir 			// the file view "overloaded" the SetHelpId
210cdf0e10cSrcweir 			static_cast< SvtFileView* >( _pControl )->SetHelpId( sID );
211cdf0e10cSrcweir 		else
212cdf0e10cSrcweir 			_pControl->SetHelpId( sID );
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 	//---------------------------------------------------------------------
getHelpURL(Window * _pControl,sal_Bool _bFileView)216cdf0e10cSrcweir 	::rtl::OUString	OControlAccess::getHelpURL( Window* _pControl, sal_Bool _bFileView )
217cdf0e10cSrcweir 	{
218cdf0e10cSrcweir 	    rtl::OString aHelpId = _pControl->GetHelpId();
219cdf0e10cSrcweir 		if ( _bFileView )
220cdf0e10cSrcweir 			// the file view "overloaded" the SetHelpId
221cdf0e10cSrcweir 			aHelpId = static_cast< SvtFileView* >( _pControl )->GetHelpId( );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         ::rtl::OUString sHelpURL;
224cdf0e10cSrcweir         ::rtl::OUString aTmp( rtl::OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ) );
225cdf0e10cSrcweir         INetURLObject aHID( aTmp );
226cdf0e10cSrcweir         if ( aHID.GetProtocol() == INET_PROT_NOT_VALID )
227cdf0e10cSrcweir             sHelpURL = rtl::OUString::createFromAscii( INET_HID_SCHEME );
228cdf0e10cSrcweir 		sHelpURL += aTmp;
229cdf0e10cSrcweir 		return sHelpURL;
230cdf0e10cSrcweir 	}
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	// --------------------------------------------------------------------------
getControlProperty(const::rtl::OUString & _rControlName,const::rtl::OUString & _rControlProperty)233cdf0e10cSrcweir 	Any	OControlAccess::getControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty )
234cdf0e10cSrcweir 	{
235cdf0e10cSrcweir 		// look up the control
236cdf0e10cSrcweir 		sal_Int16 nControlId = -1;
237cdf0e10cSrcweir 		sal_Int32 nPropertyMask = 0;
238cdf0e10cSrcweir 		Control* pControl = implGetControl( _rControlName, &nControlId, &nPropertyMask );
239cdf0e10cSrcweir 			// will throw an IllegalArgumentException if the name is not valid
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		// look up the property
242cdf0e10cSrcweir 		ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
243cdf0e10cSrcweir 		if ( aPropDesc == s_pPropertiesEnd )
244cdf0e10cSrcweir 			// it's a completely unknown property
245cdf0e10cSrcweir 			lcl_throwIllegalArgumentException();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 		if ( 0 == ( nPropertyMask & aPropDesc->nPropertyId ) )
248cdf0e10cSrcweir 			// it's a property which is known, but not allowed for this control
249cdf0e10cSrcweir 			lcl_throwIllegalArgumentException();
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 		return implGetControlProperty( pControl, aPropDesc->nPropertyId );
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	//---------------------------------------------------------------------
implGetControl(const::rtl::OUString & _rControlName,sal_Int16 * _pId,sal_Int32 * _pPropertyMask) const255cdf0e10cSrcweir 	Control* OControlAccess::implGetControl( const ::rtl::OUString& _rControlName, sal_Int16* _pId, sal_Int32* _pPropertyMask ) const SAL_THROW( (IllegalArgumentException) )
256cdf0e10cSrcweir 	{
257cdf0e10cSrcweir 		Control* pControl = NULL;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 		// translate the name into an id
260cdf0e10cSrcweir 		ControlDescRange aFoundRange = ::std::equal_range( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() );
261cdf0e10cSrcweir 		if ( aFoundRange.first != aFoundRange.second )
262cdf0e10cSrcweir 		{
263cdf0e10cSrcweir 			// get the VCL control determined by this id
264cdf0e10cSrcweir 			pControl = m_pFilePickerController->getControl( aFoundRange.first->nControlId );
265cdf0e10cSrcweir 		}
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 		// if not found 'til here, the name is invalid, or we do not have the control in the current mode
268cdf0e10cSrcweir 		if ( !pControl )
269cdf0e10cSrcweir 			lcl_throwIllegalArgumentException();
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 		// out parameters and outta here
272cdf0e10cSrcweir 		if ( _pId )
273cdf0e10cSrcweir 			*_pId = aFoundRange.first->nControlId;
274cdf0e10cSrcweir 		if ( _pPropertyMask )
275cdf0e10cSrcweir 			*_pPropertyMask = aFoundRange.first->nPropertyFlags;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 		return pControl;
278cdf0e10cSrcweir 	}
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 	//---------------------------------------------------------------------
setControlProperty(const::rtl::OUString & _rControlName,const::rtl::OUString & _rControlProperty,const::com::sun::star::uno::Any & _rValue)281cdf0e10cSrcweir 	void OControlAccess::setControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty, const ::com::sun::star::uno::Any& _rValue )
282cdf0e10cSrcweir 	{
283cdf0e10cSrcweir 		// look up the control
284cdf0e10cSrcweir         sal_Int16 nControlId = -1;
285cdf0e10cSrcweir 		Control* pControl = implGetControl( _rControlName, &nControlId );
286cdf0e10cSrcweir 			// will throw an IllegalArgumentException if the name is not valid
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 		// look up the property
289cdf0e10cSrcweir 		ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
290cdf0e10cSrcweir 		if ( aPropDesc == s_pPropertiesEnd )
291cdf0e10cSrcweir 			lcl_throwIllegalArgumentException();
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 		// set the property
294cdf0e10cSrcweir 		implSetControlProperty( nControlId, pControl, aPropDesc->nPropertyId, _rValue, sal_False );
295cdf0e10cSrcweir 	}
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	// --------------------------------------------------------------------------
getSupportedControls()298cdf0e10cSrcweir 	Sequence< ::rtl::OUString > OControlAccess::getSupportedControls(  )
299cdf0e10cSrcweir 	{
300cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aControls( s_nControlCount );
301cdf0e10cSrcweir 		::rtl::OUString* pControls = aControls.getArray();
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 		// collect the names of all _actually_existent_ controls
304cdf0e10cSrcweir 		for ( ControlDescIterator aControl = s_pControls; aControl != s_pControlsEnd; ++aControl )
305cdf0e10cSrcweir 		{
306cdf0e10cSrcweir 			if ( m_pFilePickerController->getControl( aControl->nControlId ) )
307cdf0e10cSrcweir 				*pControls++ = ::rtl::OUString::createFromAscii( aControl->pControlName );
308cdf0e10cSrcweir 		}
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 		aControls.realloc( pControls - aControls.getArray() );
311cdf0e10cSrcweir 		return aControls;
312cdf0e10cSrcweir 	}
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 	// --------------------------------------------------------------------------
getSupportedControlProperties(const::rtl::OUString & _rControlName)315cdf0e10cSrcweir 	Sequence< ::rtl::OUString > OControlAccess::getSupportedControlProperties( const ::rtl::OUString& _rControlName )
316cdf0e10cSrcweir 	{
317cdf0e10cSrcweir 		sal_Int16 nControlId = -1;
318cdf0e10cSrcweir 		sal_Int32 nPropertyMask = 0;
319cdf0e10cSrcweir 		implGetControl( _rControlName, &nControlId, &nPropertyMask );
320cdf0e10cSrcweir 			// will throw an IllegalArgumentException if the name is not valid
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 		// fill in the property names
323cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aProps( s_nPropertyCount );
324cdf0e10cSrcweir 		::rtl::OUString* pProperty = aProps.getArray();
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 		for ( ControlPropertyIterator aProp = s_pProperties; aProp != s_pPropertiesEnd; ++aProp )
327cdf0e10cSrcweir 			if ( 0 != ( nPropertyMask & aProp->nPropertyId ) )
328cdf0e10cSrcweir 				*pProperty++ = ::rtl::OUString::createFromAscii( aProp->pPropertyName );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 		aProps.realloc( pProperty - aProps.getArray() );
331cdf0e10cSrcweir 		return aProps;
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 	// --------------------------------------------------------------------------
isControlSupported(const::rtl::OUString & _rControlName)335cdf0e10cSrcweir 	sal_Bool OControlAccess::isControlSupported( const ::rtl::OUString& _rControlName )
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		return ::std::binary_search( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() );
338cdf0e10cSrcweir 	}
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	// --------------------------------------------------------------------------
isControlPropertySupported(const::rtl::OUString & _rControlName,const::rtl::OUString & _rControlProperty)341cdf0e10cSrcweir 	sal_Bool OControlAccess::isControlPropertySupported( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty )
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		// look up the control
344cdf0e10cSrcweir 		sal_Int16 nControlId = -1;
345cdf0e10cSrcweir 		sal_Int32 nPropertyMask = 0;
346cdf0e10cSrcweir 		implGetControl( _rControlName, &nControlId, &nPropertyMask );
347cdf0e10cSrcweir 			// will throw an IllegalArgumentException if the name is not valid
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 		// look up the property
350cdf0e10cSrcweir 		ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
351cdf0e10cSrcweir 		if ( aPropDesc == s_pPropertiesEnd )
352cdf0e10cSrcweir 			// it's a property which is completely unknown
353cdf0e10cSrcweir 			return sal_False;
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 		return 0 != ( aPropDesc->nPropertyId & nPropertyMask );
356cdf0e10cSrcweir 	}
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 	//-----------------------------------------------------------------------------
setValue(sal_Int16 _nControlId,sal_Int16 _nControlAction,const Any & _rValue)359cdf0e10cSrcweir 	void OControlAccess::setValue( sal_Int16 _nControlId, sal_Int16 _nControlAction, const Any& _rValue )
360cdf0e10cSrcweir 	{
361cdf0e10cSrcweir 		Control* pControl = m_pFilePickerController->getControl( _nControlId );
362cdf0e10cSrcweir 		DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" );
363cdf0e10cSrcweir 		if ( pControl )
364cdf0e10cSrcweir 		{
365cdf0e10cSrcweir 			sal_Int16 nPropertyId = -1;
366cdf0e10cSrcweir 			if ( ControlActions::SET_HELP_URL == _nControlAction )
367cdf0e10cSrcweir 			{
368cdf0e10cSrcweir 				nPropertyId = PROPERTY_FLAG_HELPURL;
369cdf0e10cSrcweir 			}
370cdf0e10cSrcweir 			else
371cdf0e10cSrcweir 			{
372cdf0e10cSrcweir 				switch ( _nControlId )
373cdf0e10cSrcweir 				{
374cdf0e10cSrcweir 					case CHECKBOX_AUTOEXTENSION:
375cdf0e10cSrcweir 					case CHECKBOX_PASSWORD:
376cdf0e10cSrcweir 					case CHECKBOX_FILTEROPTIONS:
377cdf0e10cSrcweir 					case CHECKBOX_READONLY:
378cdf0e10cSrcweir 					case CHECKBOX_LINK:
379cdf0e10cSrcweir 					case CHECKBOX_PREVIEW:
380cdf0e10cSrcweir 					case CHECKBOX_SELECTION:
381cdf0e10cSrcweir 						nPropertyId = PROPERTY_FLAG_CHECKED;
382cdf0e10cSrcweir 						break;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 					case LISTBOX_FILTER:
385cdf0e10cSrcweir 						DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
386cdf0e10cSrcweir 						break;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 					case LISTBOX_VERSION:
389cdf0e10cSrcweir 					case LISTBOX_TEMPLATE:
390cdf0e10cSrcweir 					case LISTBOX_IMAGE_TEMPLATE:
391cdf0e10cSrcweir 						if ( ControlActions::SET_SELECT_ITEM == _nControlAction )
392cdf0e10cSrcweir 						{
393cdf0e10cSrcweir 							nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX;
394cdf0e10cSrcweir 						}
395cdf0e10cSrcweir 						else
396cdf0e10cSrcweir 						{
397cdf0e10cSrcweir 							DBG_ASSERT( WINDOW_LISTBOX == pControl->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" );
398cdf0e10cSrcweir 							implDoListboxAction( static_cast< ListBox* >( pControl ), _nControlAction, _rValue );
399cdf0e10cSrcweir 						}
400cdf0e10cSrcweir 						break;
401cdf0e10cSrcweir 				}
402cdf0e10cSrcweir 			}
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 			if ( -1 != nPropertyId )
405cdf0e10cSrcweir 				implSetControlProperty( _nControlId, pControl, nPropertyId, _rValue );
406cdf0e10cSrcweir 		}
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 	//-----------------------------------------------------------------------------
getValue(sal_Int16 _nControlId,sal_Int16 _nControlAction) const410cdf0e10cSrcweir 	Any OControlAccess::getValue( sal_Int16 _nControlId, sal_Int16 _nControlAction ) const
411cdf0e10cSrcweir 	{
412cdf0e10cSrcweir 		Any aRet;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 		Control* pControl = m_pFilePickerController->getControl( _nControlId, sal_False );
415cdf0e10cSrcweir 		DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
416cdf0e10cSrcweir 		if ( pControl )
417cdf0e10cSrcweir 		{
418cdf0e10cSrcweir 			sal_Int16 nPropertyId = -1;
419cdf0e10cSrcweir 			if ( ControlActions::SET_HELP_URL == _nControlAction )
420cdf0e10cSrcweir 			{
421cdf0e10cSrcweir 				nPropertyId = PROPERTY_FLAG_HELPURL;
422cdf0e10cSrcweir 			}
423cdf0e10cSrcweir 			else
424cdf0e10cSrcweir 			{
425cdf0e10cSrcweir 				switch ( _nControlId )
426cdf0e10cSrcweir 				{
427cdf0e10cSrcweir 					case CHECKBOX_AUTOEXTENSION:
428cdf0e10cSrcweir 					case CHECKBOX_PASSWORD:
429cdf0e10cSrcweir 					case CHECKBOX_FILTEROPTIONS:
430cdf0e10cSrcweir 					case CHECKBOX_READONLY:
431cdf0e10cSrcweir 					case CHECKBOX_LINK:
432cdf0e10cSrcweir 					case CHECKBOX_PREVIEW:
433cdf0e10cSrcweir 					case CHECKBOX_SELECTION:
434cdf0e10cSrcweir 						nPropertyId = PROPERTY_FLAG_CHECKED;
435cdf0e10cSrcweir 						break;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 					case LISTBOX_FILTER:
438cdf0e10cSrcweir 						if ( ControlActions::GET_SELECTED_ITEM == _nControlAction )
439cdf0e10cSrcweir 						{
440cdf0e10cSrcweir 							aRet <<= ::rtl::OUString( m_pFilePickerController->getCurFilter() );;
441cdf0e10cSrcweir 						}
442cdf0e10cSrcweir 						else
443cdf0e10cSrcweir 						{
444cdf0e10cSrcweir 							DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" );
445cdf0e10cSrcweir                         }
446cdf0e10cSrcweir 						break;
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 					case LISTBOX_VERSION:
449cdf0e10cSrcweir 					case LISTBOX_TEMPLATE:
450cdf0e10cSrcweir 					case LISTBOX_IMAGE_TEMPLATE:
451cdf0e10cSrcweir 						switch ( _nControlAction )
452cdf0e10cSrcweir 						{
453cdf0e10cSrcweir 							case ControlActions::GET_SELECTED_ITEM:
454cdf0e10cSrcweir 								nPropertyId = PROPERTY_FLAG_SELECTEDITEM;
455cdf0e10cSrcweir 								break;
456cdf0e10cSrcweir 							case ControlActions::GET_SELECTED_ITEM_INDEX:
457cdf0e10cSrcweir 								nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX;
458cdf0e10cSrcweir 								break;
459cdf0e10cSrcweir 							case ControlActions::GET_ITEMS:
460cdf0e10cSrcweir 								nPropertyId = PROPERTY_FLAG_LISTITEMS;
461cdf0e10cSrcweir 								break;
462cdf0e10cSrcweir 							default:
463cdf0e10cSrcweir 								DBG_ERRORFILE( "OControlAccess::GetValue: invalid control action for the listbox!" );
464cdf0e10cSrcweir 								break;
465cdf0e10cSrcweir 						}
466cdf0e10cSrcweir 						break;
467cdf0e10cSrcweir 				}
468cdf0e10cSrcweir 			}
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 			if ( -1 != nPropertyId )
471cdf0e10cSrcweir 				aRet = implGetControlProperty( pControl, nPropertyId );
472cdf0e10cSrcweir 		}
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 		return aRet;
475cdf0e10cSrcweir 	}
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 	//-----------------------------------------------------------------------------
setLabel(sal_Int16 nId,const::rtl::OUString & rLabel)478cdf0e10cSrcweir 	void OControlAccess::setLabel( sal_Int16 nId, const ::rtl::OUString &rLabel )
479cdf0e10cSrcweir 	{
480cdf0e10cSrcweir 		Control* pControl = m_pFilePickerController->getControl( nId, sal_True );
481cdf0e10cSrcweir 		DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
482cdf0e10cSrcweir 		if ( pControl )
483cdf0e10cSrcweir 			pControl->SetText( rLabel );
484cdf0e10cSrcweir 	}
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 	//-----------------------------------------------------------------------------
getLabel(sal_Int16 nId) const487cdf0e10cSrcweir 	::rtl::OUString OControlAccess::getLabel( sal_Int16 nId ) const
488cdf0e10cSrcweir 	{
489cdf0e10cSrcweir 		::rtl::OUString sLabel;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 		Control* pControl = m_pFilePickerController->getControl( nId, sal_True );
492cdf0e10cSrcweir 		DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
493cdf0e10cSrcweir 		if ( pControl )
494cdf0e10cSrcweir 			sLabel = pControl->GetText();
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 		return sLabel;
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 	//-----------------------------------------------------------------------------
enableControl(sal_Int16 _nId,sal_Bool _bEnable)500cdf0e10cSrcweir 	void OControlAccess::enableControl( sal_Int16 _nId, sal_Bool _bEnable )
501cdf0e10cSrcweir 	{
502cdf0e10cSrcweir         m_pFilePickerController->enableControl( _nId, _bEnable );
503cdf0e10cSrcweir 	}
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 	// -----------------------------------------------------------------------
implDoListboxAction(ListBox * _pListbox,sal_Int16 _nControlAction,const Any & _rValue)506cdf0e10cSrcweir 	void OControlAccess::implDoListboxAction( ListBox* _pListbox, sal_Int16 _nControlAction, const Any& _rValue )
507cdf0e10cSrcweir 	{
508cdf0e10cSrcweir 		switch ( _nControlAction )
509cdf0e10cSrcweir 		{
510cdf0e10cSrcweir 			case ControlActions::ADD_ITEM:
511cdf0e10cSrcweir 			{
512cdf0e10cSrcweir 				::rtl::OUString aEntry;
513cdf0e10cSrcweir 				_rValue >>= aEntry;
514cdf0e10cSrcweir 				if ( aEntry.getLength() )
515cdf0e10cSrcweir 					_pListbox->InsertEntry( aEntry );
516cdf0e10cSrcweir 			}
517cdf0e10cSrcweir 			break;
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 			case ControlActions::ADD_ITEMS:
520cdf0e10cSrcweir 			{
521cdf0e10cSrcweir 				Sequence < ::rtl::OUString > aTemplateList;
522cdf0e10cSrcweir 				_rValue >>= aTemplateList;
523cdf0e10cSrcweir 
524cdf0e10cSrcweir 				if ( aTemplateList.getLength() )
525cdf0e10cSrcweir 				{
526cdf0e10cSrcweir 					for ( long i=0; i < aTemplateList.getLength(); i++ )
527cdf0e10cSrcweir 						_pListbox->InsertEntry( aTemplateList[i] );
528cdf0e10cSrcweir 				}
529cdf0e10cSrcweir 			}
530cdf0e10cSrcweir 			break;
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 			case ControlActions::DELETE_ITEM:
533cdf0e10cSrcweir 			{
534cdf0e10cSrcweir 				sal_Int32 nPos = 0;
535cdf0e10cSrcweir 				if ( _rValue >>= nPos )
536cdf0e10cSrcweir 					_pListbox->RemoveEntry( (sal_uInt16) nPos );
537cdf0e10cSrcweir 			}
538cdf0e10cSrcweir 			break;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 			case ControlActions::DELETE_ITEMS:
541cdf0e10cSrcweir 				_pListbox->Clear();
542cdf0e10cSrcweir 				break;
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 			default:
545cdf0e10cSrcweir 				DBG_ERRORFILE( "Wrong ControlAction for implDoListboxAction()" );
546cdf0e10cSrcweir 		}
547cdf0e10cSrcweir 	}
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 	//-----------------------------------------------------------------------------
implSetControlProperty(sal_Int16 _nControlId,Control * _pControl,sal_Int16 _nProperty,const Any & _rValue,sal_Bool _bIgnoreIllegalArgument)550cdf0e10cSrcweir 	void OControlAccess::implSetControlProperty( sal_Int16 _nControlId, Control* _pControl, sal_Int16 _nProperty, const Any& _rValue, sal_Bool _bIgnoreIllegalArgument )
551cdf0e10cSrcweir 	{
552cdf0e10cSrcweir         if ( !_pControl )
553cdf0e10cSrcweir             _pControl = m_pFilePickerController->getControl( _nControlId );
554cdf0e10cSrcweir 		DBG_ASSERT( _pControl, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
555cdf0e10cSrcweir         if ( !_pControl )
556cdf0e10cSrcweir             return;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir         DBG_ASSERT( _pControl == m_pFilePickerController->getControl( _nControlId ),
559cdf0e10cSrcweir             "OControlAccess::implSetControlProperty: inconsistent parameters!" );
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 		switch ( _nProperty )
562cdf0e10cSrcweir 		{
563cdf0e10cSrcweir 			case PROPERTY_FLAG_TEXT:
564cdf0e10cSrcweir 			{
565cdf0e10cSrcweir 				::rtl::OUString sText;
566cdf0e10cSrcweir 				if ( _rValue >>= sText )
567cdf0e10cSrcweir 				{
568cdf0e10cSrcweir 					_pControl->SetText( sText );
569cdf0e10cSrcweir 				}
570cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
571cdf0e10cSrcweir 				{
572cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
573cdf0e10cSrcweir 				}
574cdf0e10cSrcweir 			}
575cdf0e10cSrcweir 			break;
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 			case PROPERTY_FLAG_ENDBALED:
578cdf0e10cSrcweir 			{
579cdf0e10cSrcweir 				sal_Bool bEnabled = sal_False;
580cdf0e10cSrcweir 				if ( _rValue >>= bEnabled )
581cdf0e10cSrcweir 				{
582cdf0e10cSrcweir                     m_pFilePickerController->enableControl( _nControlId, bEnabled );
583cdf0e10cSrcweir 				}
584cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
585cdf0e10cSrcweir 				{
586cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
587cdf0e10cSrcweir 				}
588cdf0e10cSrcweir 			}
589cdf0e10cSrcweir 			break;
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 			case PROPERTY_FLAG_VISIBLE:
592cdf0e10cSrcweir 			{
593cdf0e10cSrcweir 				sal_Bool bVisible = sal_False;
594cdf0e10cSrcweir 				if ( _rValue >>= bVisible )
595cdf0e10cSrcweir 				{
596cdf0e10cSrcweir 					_pControl->Show( bVisible );
597cdf0e10cSrcweir 				}
598cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
599cdf0e10cSrcweir 				{
600cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
601cdf0e10cSrcweir 				}
602cdf0e10cSrcweir 			}
603cdf0e10cSrcweir 			break;
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 			case PROPERTY_FLAG_HELPURL:
606cdf0e10cSrcweir 			{
607cdf0e10cSrcweir 				::rtl::OUString sHelpURL;
608cdf0e10cSrcweir 				if ( _rValue >>= sHelpURL )
609cdf0e10cSrcweir 				{
610cdf0e10cSrcweir 					setHelpURL( _pControl, sHelpURL, m_pFileView == _pControl );
611cdf0e10cSrcweir 				}
612cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
613cdf0e10cSrcweir 				{
614cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
615cdf0e10cSrcweir 				}
616cdf0e10cSrcweir 			}
617cdf0e10cSrcweir 			break;
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 			case PROPERTY_FLAG_LISTITEMS:
620cdf0e10cSrcweir 			{
621cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
622cdf0e10cSrcweir 					"OControlAccess::implSetControlProperty: invalid control/property combination!" );
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 				Sequence< ::rtl::OUString > aItems;
625cdf0e10cSrcweir 				if ( _rValue >>= aItems )
626cdf0e10cSrcweir 				{
627cdf0e10cSrcweir 					// remove all previous items
628cdf0e10cSrcweir 					static_cast< ListBox* >( _pControl )->Clear();
629cdf0e10cSrcweir 
630cdf0e10cSrcweir 					// add the new ones
631cdf0e10cSrcweir 					const ::rtl::OUString* pItems		= aItems.getConstArray();
632cdf0e10cSrcweir 					const ::rtl::OUString* pItemsEnd	= aItems.getConstArray() + aItems.getLength();
633cdf0e10cSrcweir 					for	(	const ::rtl::OUString* pItem = pItems;
634cdf0e10cSrcweir 							pItem != pItemsEnd;
635cdf0e10cSrcweir 							++pItem
636cdf0e10cSrcweir 						)
637cdf0e10cSrcweir 					{
638cdf0e10cSrcweir 						static_cast< ListBox* >( _pControl )->InsertEntry( *pItem );
639cdf0e10cSrcweir 					}
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 				}
642cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
643cdf0e10cSrcweir 				{
644cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
645cdf0e10cSrcweir 				}
646cdf0e10cSrcweir 			}
647cdf0e10cSrcweir 			break;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 			case PROPERTY_FLAG_SELECTEDITEM:
650cdf0e10cSrcweir 			{
651cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
652cdf0e10cSrcweir 					"OControlAccess::implSetControlProperty: invalid control/property combination!" );
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 				::rtl::OUString sSelected;
655cdf0e10cSrcweir 				if ( _rValue >>= sSelected )
656cdf0e10cSrcweir 				{
657cdf0e10cSrcweir 					static_cast< ListBox* >( _pControl )->SelectEntry( sSelected );
658cdf0e10cSrcweir 				}
659cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
660cdf0e10cSrcweir 				{
661cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
662cdf0e10cSrcweir 				}
663cdf0e10cSrcweir 			}
664cdf0e10cSrcweir 			break;
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 			case PROPERTY_FLAG_SELECTEDITEMINDEX:
667cdf0e10cSrcweir 			{
668cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
669cdf0e10cSrcweir 					"OControlAccess::implSetControlProperty: invalid control/property combination!" );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 				sal_Int32 nPos = 0;
672cdf0e10cSrcweir 				if ( _rValue >>= nPos )
673cdf0e10cSrcweir 				{
674cdf0e10cSrcweir 					static_cast< ListBox* >( _pControl )->SelectEntryPos( (sal_uInt16) nPos );
675cdf0e10cSrcweir 				}
676cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
677cdf0e10cSrcweir 				{
678cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
679cdf0e10cSrcweir 				}
680cdf0e10cSrcweir 			}
681cdf0e10cSrcweir 			break;
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 			case PROPERTY_FLAG_CHECKED:
684cdf0e10cSrcweir 			{
685cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(),
686cdf0e10cSrcweir 					"OControlAccess::implSetControlProperty: invalid control/property combination!" );
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 				sal_Bool bChecked = sal_False;
689cdf0e10cSrcweir 				if ( _rValue >>= bChecked )
690cdf0e10cSrcweir 				{
691cdf0e10cSrcweir 					static_cast< CheckBox* >( _pControl )->Check( bChecked );
692cdf0e10cSrcweir 				}
693cdf0e10cSrcweir 				else if ( !_bIgnoreIllegalArgument )
694cdf0e10cSrcweir 				{
695cdf0e10cSrcweir 					lcl_throwIllegalArgumentException();
696cdf0e10cSrcweir 				}
697cdf0e10cSrcweir 			}
698cdf0e10cSrcweir 			break;
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 			default:
701cdf0e10cSrcweir 				DBG_ERROR( "OControlAccess::implSetControlProperty: invalid property id!" );
702cdf0e10cSrcweir 		}
703cdf0e10cSrcweir 	}
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	//-----------------------------------------------------------------------------
implGetControlProperty(Control * _pControl,sal_Int16 _nProperty) const706cdf0e10cSrcweir 	Any	OControlAccess::implGetControlProperty( Control* _pControl, sal_Int16 _nProperty ) const
707cdf0e10cSrcweir 	{
708cdf0e10cSrcweir 		DBG_ASSERT( _pControl, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" );
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 		Any aReturn;
711cdf0e10cSrcweir 		switch ( _nProperty )
712cdf0e10cSrcweir 		{
713cdf0e10cSrcweir 			case PROPERTY_FLAG_TEXT:
714cdf0e10cSrcweir 				aReturn <<= ::rtl::OUString( _pControl->GetText() );
715cdf0e10cSrcweir 				break;
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 			case PROPERTY_FLAG_ENDBALED:
718cdf0e10cSrcweir 				aReturn <<= (sal_Bool)_pControl->IsEnabled();
719cdf0e10cSrcweir 				break;
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 			case PROPERTY_FLAG_VISIBLE:
722cdf0e10cSrcweir 				aReturn <<= (sal_Bool)_pControl->IsVisible();
723cdf0e10cSrcweir 				break;
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 			case PROPERTY_FLAG_HELPURL:
726cdf0e10cSrcweir 				aReturn <<= getHelpURL( _pControl, m_pFileView == _pControl );
727cdf0e10cSrcweir 				break;
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 			case PROPERTY_FLAG_LISTITEMS:
730cdf0e10cSrcweir 			{
731cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
732cdf0e10cSrcweir 					"OControlAccess::implGetControlProperty: invalid control/property combination!" );
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 				Sequence< ::rtl::OUString > aItems( static_cast< ListBox* >( _pControl )->GetEntryCount() );
735cdf0e10cSrcweir 				::rtl::OUString* pItems = aItems.getArray();
736cdf0e10cSrcweir 				for ( sal_uInt16 i=0; i<static_cast< ListBox* >( _pControl )->GetEntryCount(); ++i )
737cdf0e10cSrcweir 					*pItems++ = static_cast< ListBox* >( _pControl )->GetEntry( i );
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 				aReturn <<= aItems;
740cdf0e10cSrcweir 			}
741cdf0e10cSrcweir 			break;
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 			case PROPERTY_FLAG_SELECTEDITEM:
744cdf0e10cSrcweir 			{
745cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
746cdf0e10cSrcweir 					"OControlAccess::implGetControlProperty: invalid control/property combination!" );
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 				sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
749cdf0e10cSrcweir 				::rtl::OUString sSelected;
750cdf0e10cSrcweir 				if ( LISTBOX_ENTRY_NOTFOUND != nSelected )
751cdf0e10cSrcweir 					sSelected = static_cast< ListBox* >( _pControl )->GetSelectEntry();
752cdf0e10cSrcweir 				aReturn <<= sSelected;
753cdf0e10cSrcweir 			}
754cdf0e10cSrcweir 			break;
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 			case PROPERTY_FLAG_SELECTEDITEMINDEX:
757cdf0e10cSrcweir 			{
758cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
759cdf0e10cSrcweir 					"OControlAccess::implGetControlProperty: invalid control/property combination!" );
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 				sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
762cdf0e10cSrcweir 				if ( LISTBOX_ENTRY_NOTFOUND != nSelected )
763cdf0e10cSrcweir 					aReturn <<= (sal_Int32)static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
764cdf0e10cSrcweir 				else
765cdf0e10cSrcweir 					aReturn <<= (sal_Int32)-1;
766cdf0e10cSrcweir 			}
767cdf0e10cSrcweir 			break;
768cdf0e10cSrcweir 
769cdf0e10cSrcweir 			case PROPERTY_FLAG_CHECKED:
770cdf0e10cSrcweir 				DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(),
771cdf0e10cSrcweir 					"OControlAccess::implGetControlProperty: invalid control/property combination!" );
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 				aReturn <<= (sal_Bool)static_cast< CheckBox* >( _pControl )->IsChecked( );
774cdf0e10cSrcweir 				break;
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 			default:
777cdf0e10cSrcweir 				DBG_ERROR( "OControlAccess::implGetControlProperty: invalid property id!" );
778cdf0e10cSrcweir 		}
779cdf0e10cSrcweir 		return aReturn;
780cdf0e10cSrcweir 	}
781cdf0e10cSrcweir 
782cdf0e10cSrcweir //.........................................................................
783cdf0e10cSrcweir }	// namespace svt
784cdf0e10cSrcweir //.........................................................................
785cdf0e10cSrcweir 
786