1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #include <svtools/addresstemplate.hxx>
29cdf0e10cSrcweir #include "addresstemplate.hrc"
30cdf0e10cSrcweir #include <svtools/svtools.hrc>
31cdf0e10cSrcweir #include <svtools/helpid.hrc>
32cdf0e10cSrcweir #include <svtools/svtdata.hxx>
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
35cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
36cdf0e10cSrcweir #include <vcl/stdtext.hxx>
37cdf0e10cSrcweir #include <vcl/waitobj.hxx>
38cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
40cdf0e10cSrcweir #include <comphelper/extract.hxx>
41cdf0e10cSrcweir #include <comphelper/interaction.hxx>
42cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
43cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
44cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
45cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
50cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
52cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
53cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
54cdf0e10cSrcweir #include <svtools/localresaccess.hxx>
55cdf0e10cSrcweir #include "svl/filenotation.hxx"
56cdf0e10cSrcweir #include <tools/urlobj.hxx>
57cdf0e10cSrcweir #include <algorithm>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // .......................................................................
60cdf0e10cSrcweir namespace svt
61cdf0e10cSrcweir {
62cdf0e10cSrcweir // .......................................................................
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
65cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
66cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
67cdf0e10cSrcweir 	using namespace ::com::sun::star::ui::dialogs;
68cdf0e10cSrcweir 	using namespace ::com::sun::star::util;
69cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
70cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
71cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
72cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
73cdf0e10cSrcweir 	using namespace ::com::sun::star::task;
74cdf0e10cSrcweir 	using namespace ::comphelper;
75cdf0e10cSrcweir 	using namespace ::utl;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	DECLARE_STL_VECTOR( String, StringArray );
78cdf0e10cSrcweir 	DECLARE_STL_STDKEY_SET( ::rtl::OUString, StringBag );
79cdf0e10cSrcweir 	DECLARE_STL_USTRINGACCESS_MAP( ::rtl::OUString, MapString2String );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     namespace
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         String lcl_getSelectedDataSource( const ComboBox& _dataSourceCombo )
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             String selectedDataSource = _dataSourceCombo.GetText();
86cdf0e10cSrcweir             if ( _dataSourceCombo.GetEntryPos( selectedDataSource ) == LISTBOX_ENTRY_NOTFOUND )
87cdf0e10cSrcweir             {
88cdf0e10cSrcweir                 // none of the pre-selected entries -> assume a path to a database document
89cdf0e10cSrcweir 	            OFileNotation aFileNotation( selectedDataSource, OFileNotation::N_SYSTEM );
90cdf0e10cSrcweir 	            selectedDataSource = aFileNotation.get( OFileNotation::N_URL );
91cdf0e10cSrcweir             }
92cdf0e10cSrcweir             return selectedDataSource;
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     // ===================================================================
97cdf0e10cSrcweir 	// = IAssigmentData
98cdf0e10cSrcweir 	// ===================================================================
99cdf0e10cSrcweir 	class IAssigmentData
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 	public:
102cdf0e10cSrcweir 		virtual ~IAssigmentData();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		/// the data source to use for the address book
105cdf0e10cSrcweir 		virtual ::rtl::OUString getDatasourceName() const = 0;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		/// the command to use for the address book
108cdf0e10cSrcweir 		virtual ::rtl::OUString getCommand() const = 0;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		/** the command type to use for the address book
111cdf0e10cSrcweir 			@return
112cdf0e10cSrcweir 				a <type scope="com.sun.star.sdb">CommandType</type> value
113cdf0e10cSrcweir 		*/
114cdf0e10cSrcweir 		virtual sal_Int32		getCommandType() const = 0;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		/// checks whether or not there is an assignment for a given logical field
117cdf0e10cSrcweir 		virtual sal_Bool		hasFieldAssignment(const ::rtl::OUString& _rLogicalName) = 0;
118cdf0e10cSrcweir 		/// retrieves the assignment for a given logical field
119cdf0e10cSrcweir 		virtual ::rtl::OUString getFieldAssignment(const ::rtl::OUString& _rLogicalName) = 0;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 		/// set the assignment for a given logical field
122cdf0e10cSrcweir 		virtual void			setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment) = 0;
123cdf0e10cSrcweir 		/// clear the assignment for a given logical field
124cdf0e10cSrcweir 		virtual void			clearFieldAssignment(const ::rtl::OUString& _rLogicalName) = 0;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 		virtual void	setDatasourceName(const ::rtl::OUString& _rName) = 0;
127cdf0e10cSrcweir 		virtual void	setCommand(const ::rtl::OUString& _rCommand) = 0;
128cdf0e10cSrcweir 	};
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	// -------------------------------------------------------------------
131cdf0e10cSrcweir 	IAssigmentData::~IAssigmentData()
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	// ===================================================================
136cdf0e10cSrcweir 	// = AssigmentTransientData
137cdf0e10cSrcweir 	// ===================================================================
138cdf0e10cSrcweir 	class AssigmentTransientData : public IAssigmentData
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 	protected:
141cdf0e10cSrcweir         Reference< XDataSource >    m_xDataSource;
142cdf0e10cSrcweir 		::rtl::OUString			    m_sDSName;
143cdf0e10cSrcweir 		::rtl::OUString			    m_sTableName;
144cdf0e10cSrcweir 		MapString2String		    m_aAliases;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir public:
147cdf0e10cSrcweir 		AssigmentTransientData(
148cdf0e10cSrcweir 			const Reference< XDataSource >& _rxDataSource,
149cdf0e10cSrcweir 			const ::rtl::OUString& _rDataSourceName,
150cdf0e10cSrcweir 			const ::rtl::OUString& _rTableName,
151cdf0e10cSrcweir 			const Sequence< AliasProgrammaticPair >& _rFields
152cdf0e10cSrcweir 		);
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 		// IAssigmentData overridables
155cdf0e10cSrcweir 		virtual ::rtl::OUString getDatasourceName() const;
156cdf0e10cSrcweir 		virtual ::rtl::OUString getCommand() const;
157cdf0e10cSrcweir 		virtual sal_Int32		getCommandType() const;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		virtual sal_Bool		hasFieldAssignment(const ::rtl::OUString& _rLogicalName);
160cdf0e10cSrcweir 		virtual ::rtl::OUString getFieldAssignment(const ::rtl::OUString& _rLogicalName);
161cdf0e10cSrcweir 		virtual void			setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment);
162cdf0e10cSrcweir 		virtual void			clearFieldAssignment(const ::rtl::OUString& _rLogicalName);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		virtual void	setDatasourceName(const ::rtl::OUString& _rName);
165cdf0e10cSrcweir 		virtual void	setCommand(const ::rtl::OUString& _rCommand);
166cdf0e10cSrcweir 	};
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	// -------------------------------------------------------------------
169cdf0e10cSrcweir 	AssigmentTransientData::AssigmentTransientData( const Reference< XDataSource >& _rxDataSource,
170cdf0e10cSrcweir 			const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rTableName,
171cdf0e10cSrcweir             const Sequence< AliasProgrammaticPair >& _rFields )
172cdf0e10cSrcweir 		:m_xDataSource( _rxDataSource )
173cdf0e10cSrcweir         ,m_sDSName( _rDataSourceName )
174cdf0e10cSrcweir         ,m_sTableName( _rTableName )
175cdf0e10cSrcweir 	{
176cdf0e10cSrcweir         // fill our aliaes structure
177cdf0e10cSrcweir 		// first collect all known programmatic names
178cdf0e10cSrcweir 		StringBag aKnownNames;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		String sLogicalFieldNames( SvtResId( STR_LOCAGICAL_FIELD_NAMES ) );
181cdf0e10cSrcweir 		sal_Int32 nTokenCount = sLogicalFieldNames.GetTokenCount(';');
182cdf0e10cSrcweir 		for (sal_Int32 i = 0; i<nTokenCount; ++i)
183cdf0e10cSrcweir 			aKnownNames.insert(sLogicalFieldNames.GetToken((sal_uInt16)i, ';'));
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 		// loop throuzh the given names
186cdf0e10cSrcweir 		const AliasProgrammaticPair* pFields = _rFields.getConstArray();
187cdf0e10cSrcweir 		for (;pFields != pFields; ++pFields)
188cdf0e10cSrcweir 		{
189cdf0e10cSrcweir 			StringBagIterator aKnownPos = aKnownNames.find( pFields->ProgrammaticName );
190cdf0e10cSrcweir 			if ( aKnownNames.end() != aKnownPos )
191cdf0e10cSrcweir 			{
192cdf0e10cSrcweir 				m_aAliases[ pFields->ProgrammaticName ] = pFields->Alias;
193cdf0e10cSrcweir 			}
194cdf0e10cSrcweir 			else
195cdf0e10cSrcweir 			{
196cdf0e10cSrcweir 				DBG_ERROR	(	(	::rtl::OString("AssigmentTransientData::AssigmentTransientData: unknown programmatic name (")
197cdf0e10cSrcweir 								+=	::rtl::OString(pFields->ProgrammaticName.getStr(), pFields->ProgrammaticName.getLength(), RTL_TEXTENCODING_ASCII_US)
198cdf0e10cSrcweir 								+=	::rtl::OString(")!")
199cdf0e10cSrcweir 								).getStr()
200cdf0e10cSrcweir 							);
201cdf0e10cSrcweir 			}
202cdf0e10cSrcweir 		}
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	// -------------------------------------------------------------------
206cdf0e10cSrcweir 	::rtl::OUString AssigmentTransientData::getDatasourceName() const
207cdf0e10cSrcweir 	{
208cdf0e10cSrcweir 		return m_sDSName;
209cdf0e10cSrcweir 	}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	// -------------------------------------------------------------------
212cdf0e10cSrcweir 	::rtl::OUString AssigmentTransientData::getCommand() const
213cdf0e10cSrcweir 	{
214cdf0e10cSrcweir 		return m_sTableName;
215cdf0e10cSrcweir 	}
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	// -------------------------------------------------------------------
218cdf0e10cSrcweir 	sal_Int32 AssigmentTransientData::getCommandType() const
219cdf0e10cSrcweir 	{
220cdf0e10cSrcweir 		return CommandType::TABLE;
221cdf0e10cSrcweir 	}
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	// -------------------------------------------------------------------
224cdf0e10cSrcweir 	sal_Bool AssigmentTransientData::hasFieldAssignment(const ::rtl::OUString& _rLogicalName)
225cdf0e10cSrcweir 	{
226cdf0e10cSrcweir 		ConstMapString2StringIterator aPos = m_aAliases.find( _rLogicalName );
227cdf0e10cSrcweir 		return	( m_aAliases.end() != aPos )
228cdf0e10cSrcweir 			&&	( aPos->second.getLength() );
229cdf0e10cSrcweir 	}
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	// -------------------------------------------------------------------
232cdf0e10cSrcweir 	::rtl::OUString AssigmentTransientData::getFieldAssignment(const ::rtl::OUString& _rLogicalName)
233cdf0e10cSrcweir 	{
234cdf0e10cSrcweir 		::rtl::OUString sReturn;
235cdf0e10cSrcweir 		ConstMapString2StringIterator aPos = m_aAliases.find( _rLogicalName );
236cdf0e10cSrcweir 		if ( m_aAliases.end() != aPos )
237cdf0e10cSrcweir 			sReturn = aPos->second;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 		return sReturn;
240cdf0e10cSrcweir 	}
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	// -------------------------------------------------------------------
243cdf0e10cSrcweir 	void AssigmentTransientData::setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment)
244cdf0e10cSrcweir 	{
245cdf0e10cSrcweir 		m_aAliases[ _rLogicalName ] = _rAssignment;
246cdf0e10cSrcweir 	}
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 	// -------------------------------------------------------------------
249cdf0e10cSrcweir 	void AssigmentTransientData::clearFieldAssignment(const ::rtl::OUString& _rLogicalName)
250cdf0e10cSrcweir 	{
251cdf0e10cSrcweir 		MapString2StringIterator aPos = m_aAliases.find( _rLogicalName );
252cdf0e10cSrcweir 		if ( m_aAliases.end() != aPos )
253cdf0e10cSrcweir 			m_aAliases.erase( aPos );
254cdf0e10cSrcweir 	}
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	// -------------------------------------------------------------------
257cdf0e10cSrcweir 	void AssigmentTransientData::setDatasourceName(const ::rtl::OUString&)
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir         DBG_ERROR( "AssigmentTransientData::setDatasourceName: cannot be implemented for transient data!" );
260cdf0e10cSrcweir 	}
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 	// -------------------------------------------------------------------
263cdf0e10cSrcweir 	void AssigmentTransientData::setCommand(const ::rtl::OUString&)
264cdf0e10cSrcweir 	{
265cdf0e10cSrcweir         DBG_ERROR( "AssigmentTransientData::setCommand: cannot be implemented for transient data!" );
266cdf0e10cSrcweir 	}
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 	// ===================================================================
269cdf0e10cSrcweir 	// = AssignmentPersistentData
270cdf0e10cSrcweir 	// ===================================================================
271cdf0e10cSrcweir 	class AssignmentPersistentData
272cdf0e10cSrcweir 			:public ::utl::ConfigItem
273cdf0e10cSrcweir 			,public IAssigmentData
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 	protected:
276cdf0e10cSrcweir 		StringBag		m_aStoredFields;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 	protected:
279cdf0e10cSrcweir 		::com::sun::star::uno::Any
280cdf0e10cSrcweir 						getProperty(const ::rtl::OUString& _rLocalName) const;
281cdf0e10cSrcweir 		::com::sun::star::uno::Any
282cdf0e10cSrcweir 						getProperty(const sal_Char* _pLocalName) const;
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 		::rtl::OUString	getStringProperty(const sal_Char* _pLocalName) const;
285cdf0e10cSrcweir 		sal_Int32		getInt32Property(const sal_Char* _pLocalName) const;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 		::rtl::OUString	getStringProperty(const ::rtl::OUString& _rLocalName) const;
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 		void			setStringProperty(const sal_Char* _pLocalName, const ::rtl::OUString& _rValue);
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 	public:
292cdf0e10cSrcweir 		AssignmentPersistentData();
293cdf0e10cSrcweir 		~AssignmentPersistentData();
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 		// IAssigmentData overridables
296cdf0e10cSrcweir 		virtual ::rtl::OUString getDatasourceName() const;
297cdf0e10cSrcweir 		virtual ::rtl::OUString getCommand() const;
298cdf0e10cSrcweir 		virtual sal_Int32		getCommandType() const;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 		virtual sal_Bool		hasFieldAssignment(const ::rtl::OUString& _rLogicalName);
301cdf0e10cSrcweir 		virtual ::rtl::OUString getFieldAssignment(const ::rtl::OUString& _rLogicalName);
302cdf0e10cSrcweir 		virtual void			setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment);
303cdf0e10cSrcweir 		virtual void			clearFieldAssignment(const ::rtl::OUString& _rLogicalName);
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 		virtual void	setDatasourceName(const ::rtl::OUString& _rName);
306cdf0e10cSrcweir 		virtual void	setCommand(const ::rtl::OUString& _rCommand);
307cdf0e10cSrcweir 
308cdf0e10cSrcweir         virtual void    Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames);
309cdf0e10cSrcweir 		virtual void	Commit();
310cdf0e10cSrcweir 	};
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 
313cdf0e10cSrcweir void AssignmentPersistentData::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir void AssignmentPersistentData::Commit()
318cdf0e10cSrcweir {
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	// -------------------------------------------------------------------
322cdf0e10cSrcweir 	AssignmentPersistentData::AssignmentPersistentData()
323cdf0e10cSrcweir 		:ConfigItem( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.DataAccess/AddressBook" )))
324cdf0e10cSrcweir 	{
325cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aStoredNames = GetNodeNames(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fields")));
326cdf0e10cSrcweir 		const ::rtl::OUString* pStoredNames = aStoredNames.getConstArray();
327cdf0e10cSrcweir 		for (sal_Int32 i=0; i<aStoredNames.getLength(); ++i, ++pStoredNames)
328cdf0e10cSrcweir 			m_aStoredFields.insert(*pStoredNames);
329cdf0e10cSrcweir 	}
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	// -------------------------------------------------------------------
332cdf0e10cSrcweir 	AssignmentPersistentData::~AssignmentPersistentData()
333cdf0e10cSrcweir 	{
334cdf0e10cSrcweir 	}
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	// -------------------------------------------------------------------
337cdf0e10cSrcweir 	sal_Bool AssignmentPersistentData::hasFieldAssignment(const ::rtl::OUString& _rLogicalName)
338cdf0e10cSrcweir 	{
339cdf0e10cSrcweir 		return (m_aStoredFields.end() != m_aStoredFields.find(_rLogicalName));
340cdf0e10cSrcweir 	}
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	// -------------------------------------------------------------------
343cdf0e10cSrcweir 	::rtl::OUString AssignmentPersistentData::getFieldAssignment(const ::rtl::OUString& _rLogicalName)
344cdf0e10cSrcweir 	{
345cdf0e10cSrcweir 		::rtl::OUString sAssignment;
346cdf0e10cSrcweir 		if (hasFieldAssignment(_rLogicalName))
347cdf0e10cSrcweir 		{
348cdf0e10cSrcweir 			::rtl::OUString sFieldPath(RTL_CONSTASCII_USTRINGPARAM("Fields/"));
349cdf0e10cSrcweir 			sFieldPath += _rLogicalName;
350cdf0e10cSrcweir 			sFieldPath += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/AssignedFieldName"));
351cdf0e10cSrcweir 			sAssignment = getStringProperty(sFieldPath);
352cdf0e10cSrcweir 		}
353cdf0e10cSrcweir 		return sAssignment;
354cdf0e10cSrcweir 	}
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	// -------------------------------------------------------------------
357cdf0e10cSrcweir 	Any AssignmentPersistentData::getProperty(const sal_Char* _pLocalName) const
358cdf0e10cSrcweir 	{
359cdf0e10cSrcweir 		return getProperty(::rtl::OUString::createFromAscii(_pLocalName));
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 	// -------------------------------------------------------------------
363cdf0e10cSrcweir 	Any AssignmentPersistentData::getProperty(const ::rtl::OUString& _rLocalName) const
364cdf0e10cSrcweir 	{
365cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aProperties(&_rLocalName, 1);
366cdf0e10cSrcweir 		Sequence< Any > aValues = const_cast<AssignmentPersistentData*>(this)->GetProperties(aProperties);
367cdf0e10cSrcweir 		DBG_ASSERT(aValues.getLength() == 1, "AssignmentPersistentData::getProperty: invalid sequence length!");
368cdf0e10cSrcweir 		return aValues[0];
369cdf0e10cSrcweir 	}
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	// -------------------------------------------------------------------
372cdf0e10cSrcweir 	::rtl::OUString	AssignmentPersistentData::getStringProperty(const ::rtl::OUString& _rLocalName) const
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir 		::rtl::OUString sReturn;
375cdf0e10cSrcweir 		getProperty( _rLocalName ) >>= sReturn;
376cdf0e10cSrcweir 		return sReturn;
377cdf0e10cSrcweir 	}
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 	// -------------------------------------------------------------------
380cdf0e10cSrcweir 	::rtl::OUString	AssignmentPersistentData::getStringProperty(const sal_Char* _pLocalName) const
381cdf0e10cSrcweir 	{
382cdf0e10cSrcweir 		::rtl::OUString sReturn;
383cdf0e10cSrcweir 		getProperty( _pLocalName ) >>= sReturn;
384cdf0e10cSrcweir 		return sReturn;
385cdf0e10cSrcweir 	}
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 	// -------------------------------------------------------------------
388cdf0e10cSrcweir 	sal_Int32 AssignmentPersistentData::getInt32Property(const sal_Char* _pLocalName) const
389cdf0e10cSrcweir 	{
390cdf0e10cSrcweir 		sal_Int32 nReturn = 0;
391cdf0e10cSrcweir 		getProperty( _pLocalName ) >>= nReturn;
392cdf0e10cSrcweir 		return nReturn;
393cdf0e10cSrcweir 	}
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	// -------------------------------------------------------------------
396cdf0e10cSrcweir 	void AssignmentPersistentData::setStringProperty(const sal_Char* _pLocalName, const ::rtl::OUString& _rValue)
397cdf0e10cSrcweir 	{
398cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aNames(1);
399cdf0e10cSrcweir 		Sequence< Any > aValues(1);
400cdf0e10cSrcweir 		aNames[0] = ::rtl::OUString::createFromAscii(_pLocalName);
401cdf0e10cSrcweir 		aValues[0] <<= _rValue;
402cdf0e10cSrcweir 		PutProperties(aNames, aValues);
403cdf0e10cSrcweir 	}
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 	// -------------------------------------------------------------------
406cdf0e10cSrcweir 	void AssignmentPersistentData::setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment)
407cdf0e10cSrcweir 	{
408cdf0e10cSrcweir 		if (!_rAssignment.getLength())
409cdf0e10cSrcweir 		{
410cdf0e10cSrcweir 			if (hasFieldAssignment(_rLogicalName))
411cdf0e10cSrcweir 				// the assignment exists but it should be reset
412cdf0e10cSrcweir 				clearFieldAssignment(_rLogicalName);
413cdf0e10cSrcweir 				return;
414cdf0e10cSrcweir 		}
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 		// Fields
417cdf0e10cSrcweir 		::rtl::OUString sDescriptionNodePath(RTL_CONSTASCII_USTRINGPARAM("Fields"));
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 		// Fields/<field>
420cdf0e10cSrcweir 		::rtl::OUString sFieldElementNodePath(sDescriptionNodePath);
421cdf0e10cSrcweir 		sFieldElementNodePath += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
422cdf0e10cSrcweir 		sFieldElementNodePath += _rLogicalName;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 		Sequence< PropertyValue > aNewFieldDescription(2);
425cdf0e10cSrcweir 		// Fields/<field>/ProgrammaticFieldName
426cdf0e10cSrcweir 		aNewFieldDescription[0].Name = sFieldElementNodePath;
427cdf0e10cSrcweir 		aNewFieldDescription[0].Name += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/ProgrammaticFieldName"));
428cdf0e10cSrcweir 		aNewFieldDescription[0].Value <<= _rLogicalName;
429cdf0e10cSrcweir 		// Fields/<field>/AssignedFieldName
430cdf0e10cSrcweir 		aNewFieldDescription[1].Name = sFieldElementNodePath;
431cdf0e10cSrcweir 		aNewFieldDescription[1].Name += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/AssignedFieldName"));
432cdf0e10cSrcweir 		aNewFieldDescription[1].Value <<= _rAssignment;
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 		// just set the new value
435cdf0e10cSrcweir #ifdef DBG_UTIL
436cdf0e10cSrcweir 		sal_Bool bSuccess =
437cdf0e10cSrcweir #endif
438cdf0e10cSrcweir 		SetSetProperties(sDescriptionNodePath, aNewFieldDescription);
439cdf0e10cSrcweir 		DBG_ASSERT(bSuccess, "AssignmentPersistentData::setFieldAssignment: could not commit the changes a field!");
440cdf0e10cSrcweir 	}
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 	// -------------------------------------------------------------------
443cdf0e10cSrcweir 	void AssignmentPersistentData::clearFieldAssignment(const ::rtl::OUString& _rLogicalName)
444cdf0e10cSrcweir 	{
445cdf0e10cSrcweir 		if (!hasFieldAssignment(_rLogicalName))
446cdf0e10cSrcweir 			// nothing to do
447cdf0e10cSrcweir 			return;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 		::rtl::OUString sDescriptionNodePath(RTL_CONSTASCII_USTRINGPARAM("Fields"));
450cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aNames(&_rLogicalName, 1);
451cdf0e10cSrcweir 		ClearNodeElements(sDescriptionNodePath, aNames);
452cdf0e10cSrcweir 	}
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 	// -------------------------------------------------------------------
455cdf0e10cSrcweir 	::rtl::OUString AssignmentPersistentData::getDatasourceName() const
456cdf0e10cSrcweir 	{
457cdf0e10cSrcweir 		return getStringProperty( "DataSourceName" );
458cdf0e10cSrcweir 	}
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	// -------------------------------------------------------------------
461cdf0e10cSrcweir 	::rtl::OUString AssignmentPersistentData::getCommand() const
462cdf0e10cSrcweir 	{
463cdf0e10cSrcweir 		return getStringProperty( "Command" );
464cdf0e10cSrcweir 	}
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	// -------------------------------------------------------------------
467cdf0e10cSrcweir 	void AssignmentPersistentData::setDatasourceName(const ::rtl::OUString& _rName)
468cdf0e10cSrcweir 	{
469cdf0e10cSrcweir 		setStringProperty( "DataSourceName", _rName );
470cdf0e10cSrcweir 	}
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 	// -------------------------------------------------------------------
473cdf0e10cSrcweir 	void AssignmentPersistentData::setCommand(const ::rtl::OUString& _rCommand)
474cdf0e10cSrcweir 	{
475cdf0e10cSrcweir 		setStringProperty( "Command", _rCommand );
476cdf0e10cSrcweir 	}
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 	// -------------------------------------------------------------------
479cdf0e10cSrcweir 	sal_Int32 AssignmentPersistentData::getCommandType() const
480cdf0e10cSrcweir 	{
481cdf0e10cSrcweir 		return getInt32Property( "CommandType" );
482cdf0e10cSrcweir 	}
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 	// ===================================================================
485cdf0e10cSrcweir 	// = AddressBookSourceDialogData
486cdf0e10cSrcweir 	// ===================================================================
487cdf0e10cSrcweir 	struct AddressBookSourceDialogData
488cdf0e10cSrcweir 	{
489cdf0e10cSrcweir 		FixedText*		pFieldLabels[FIELD_PAIRS_VISIBLE * 2];
490cdf0e10cSrcweir 		ListBox*		pFields[FIELD_PAIRS_VISIBLE * 2];
491cdf0e10cSrcweir 
492cdf0e10cSrcweir         /// when working transient, we need the data source
493cdf0e10cSrcweir         Reference< XDataSource >
494cdf0e10cSrcweir                         m_xTransientDataSource;
495cdf0e10cSrcweir 		/// current scroll pos in the field list
496cdf0e10cSrcweir 		sal_Int32		nFieldScrollPos;
497cdf0e10cSrcweir 		/// the index within m_pFields of the last visible list box. This is redundant, it could be extracted from other members
498cdf0e10cSrcweir 		sal_Int32		nLastVisibleListIndex;
499cdf0e10cSrcweir 		/// indicates that we've an odd field number. This member is for efficiency only, it's redundant.
500cdf0e10cSrcweir 		sal_Bool		bOddFieldNumber : 1;
501cdf0e10cSrcweir 		/// indicates that we're working with the real persistent configuration
502cdf0e10cSrcweir 		sal_Bool		bWorkingPersistent : 1;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 		/// the strings to use as labels for the field selection listboxes
505cdf0e10cSrcweir 		StringArray		aFieldLabels;
506cdf0e10cSrcweir 		// the current field assignment
507cdf0e10cSrcweir 		StringArray		aFieldAssignments;
508cdf0e10cSrcweir 		/// the logical field names
509cdf0e10cSrcweir 		StringArray		aLogicalFieldNames;
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 		IAssigmentData*	pConfigData;
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 		// ................................................................
514cdf0e10cSrcweir 		AddressBookSourceDialogData( )
515cdf0e10cSrcweir 			:nFieldScrollPos(0)
516cdf0e10cSrcweir 			,nLastVisibleListIndex(0)
517cdf0e10cSrcweir 			,bOddFieldNumber(sal_False)
518cdf0e10cSrcweir 			,bWorkingPersistent( sal_True )
519cdf0e10cSrcweir 			,pConfigData( new AssignmentPersistentData )
520cdf0e10cSrcweir 		{
521cdf0e10cSrcweir 		}
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 		// ................................................................
524cdf0e10cSrcweir 		AddressBookSourceDialogData( const Reference< XDataSource >& _rxTransientDS, const ::rtl::OUString& _rDataSourceName,
525cdf0e10cSrcweir             const ::rtl::OUString& _rTableName, const Sequence< AliasProgrammaticPair >& _rFields )
526cdf0e10cSrcweir 			:m_xTransientDataSource( _rxTransientDS )
527cdf0e10cSrcweir             ,nFieldScrollPos(0)
528cdf0e10cSrcweir 			,nLastVisibleListIndex(0)
529cdf0e10cSrcweir 			,bOddFieldNumber(sal_False)
530cdf0e10cSrcweir 			,bWorkingPersistent( sal_False )
531cdf0e10cSrcweir 			,pConfigData( new AssigmentTransientData( m_xTransientDataSource, _rDataSourceName, _rTableName, _rFields ) )
532cdf0e10cSrcweir 		{
533cdf0e10cSrcweir 		}
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 		~AddressBookSourceDialogData()
536cdf0e10cSrcweir 		{
537cdf0e10cSrcweir 			delete pConfigData;
538cdf0e10cSrcweir 		}
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 	};
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 	// ===================================================================
543cdf0e10cSrcweir 	// = AddressBookSourceDialog
544cdf0e10cSrcweir 	// ===================================================================
545cdf0e10cSrcweir #define INIT_FIELDS()	\
546cdf0e10cSrcweir 		 ModalDialog(_pParent, SvtResId( DLG_ADDRESSBOOKSOURCE ))\
547cdf0e10cSrcweir 		,m_aDatasourceFrame			(this, SvtResId(FL_DATASOURCEFRAME))\
548cdf0e10cSrcweir 		,m_aDatasourceLabel			(this, SvtResId(FT_DATASOURCE))\
549cdf0e10cSrcweir 		,m_aDatasource				(this, SvtResId(CB_DATASOURCE))\
550cdf0e10cSrcweir 		,m_aAdministrateDatasources	(this, SvtResId(PB_ADMINISTATE_DATASOURCES))\
551cdf0e10cSrcweir 		,m_aTableLabel				(this, SvtResId(FT_TABLE))\
552cdf0e10cSrcweir 		,m_aTable					(this, SvtResId(CB_TABLE))\
553cdf0e10cSrcweir 		,m_aFieldsTitle				(this, SvtResId(FT_FIELDS))\
554cdf0e10cSrcweir 		,m_aFieldsFrame				(this, SvtResId(CT_BORDER))\
555cdf0e10cSrcweir 		,m_aFieldScroller			(&m_aFieldsFrame, SvtResId(SB_FIELDSCROLLER))\
556cdf0e10cSrcweir 		,m_aOK						(this, SvtResId(PB_OK))\
557cdf0e10cSrcweir 		,m_aCancel					(this, SvtResId(PB_CANCEL))\
558cdf0e10cSrcweir 		,m_aHelp					(this, SvtResId(PB_HELP))\
559cdf0e10cSrcweir 		,m_sNoFieldSelection(SvtResId(STR_NO_FIELD_SELECTION))\
560cdf0e10cSrcweir 		,m_xORB(_rxORB)
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 	// -------------------------------------------------------------------
563cdf0e10cSrcweir 	AddressBookSourceDialog::AddressBookSourceDialog(Window* _pParent,
564cdf0e10cSrcweir 			const Reference< XMultiServiceFactory >& _rxORB )
565cdf0e10cSrcweir 		:INIT_FIELDS()
566cdf0e10cSrcweir 		,m_pImpl( new AddressBookSourceDialogData )
567cdf0e10cSrcweir 	{
568cdf0e10cSrcweir 		implConstruct();
569cdf0e10cSrcweir 	}
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 	// -------------------------------------------------------------------
572cdf0e10cSrcweir 	AddressBookSourceDialog::AddressBookSourceDialog( Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB,
573cdf0e10cSrcweir 		const Reference< XDataSource >& _rxTransientDS, const ::rtl::OUString& _rDataSourceName,
574cdf0e10cSrcweir         const ::rtl::OUString& _rTable, const Sequence< AliasProgrammaticPair >& _rMapping )
575cdf0e10cSrcweir 		:INIT_FIELDS()
576cdf0e10cSrcweir 		,m_pImpl( new AddressBookSourceDialogData( _rxTransientDS, _rDataSourceName, _rTable, _rMapping ) )
577cdf0e10cSrcweir 	{
578cdf0e10cSrcweir 		implConstruct();
579cdf0e10cSrcweir 	}
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 	// -------------------------------------------------------------------
582cdf0e10cSrcweir 	void AddressBookSourceDialog::implConstruct()
583cdf0e10cSrcweir 	{
584cdf0e10cSrcweir 		for (sal_Int32 row=0; row<FIELD_PAIRS_VISIBLE; ++row)
585cdf0e10cSrcweir 		{
586cdf0e10cSrcweir 			for (sal_Int32 column=0; column<2; ++column)
587cdf0e10cSrcweir 			{
588cdf0e10cSrcweir 				// the label
589cdf0e10cSrcweir 				m_pImpl->pFieldLabels[row * 2 + column] = new FixedText(&m_aFieldsFrame, SvtResId((sal_uInt16)(FT_FIELD_BASE + row * 2 + column)));
590cdf0e10cSrcweir 				// the listbox
591cdf0e10cSrcweir 				m_pImpl->pFields[row * 2 + column] = new ListBox(&m_aFieldsFrame, SvtResId((sal_uInt16)(LB_FIELD_BASE + row * 2 + column)));
592cdf0e10cSrcweir 				m_pImpl->pFields[row * 2 + column]->SetDropDownLineCount(15);
593cdf0e10cSrcweir 				m_pImpl->pFields[row * 2 + column]->SetSelectHdl(LINK(this, AddressBookSourceDialog, OnFieldSelect));
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 				m_pImpl->pFields[row * 2 + column]->SetHelpId(HID_ADDRTEMPL_FIELD_ASSIGNMENT);
596cdf0e10cSrcweir 			}
597cdf0e10cSrcweir 		}
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 		m_aFieldsFrame.SetStyle((m_aFieldsFrame.GetStyle() | WB_TABSTOP | WB_DIALOGCONTROL) & ~WB_NODIALOGCONTROL);
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 		// correct the z-order
602cdf0e10cSrcweir 		m_aFieldScroller.SetZOrder(m_pImpl->pFields[FIELD_CONTROLS_VISIBLE - 1], WINDOW_ZORDER_BEHIND);
603cdf0e10cSrcweir 		m_aOK.SetZOrder(&m_aFieldsFrame, WINDOW_ZORDER_BEHIND);
604cdf0e10cSrcweir 		m_aCancel.SetZOrder(&m_aOK, WINDOW_ZORDER_BEHIND);
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 		initializeDatasources();
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 		// for the moment, we have a hard coded list of all known fields.
609cdf0e10cSrcweir 		// A better solution would be to store all known field translations in the configuration, which could be
610cdf0e10cSrcweir 		// extensible by the user in an arbitrary way.
611cdf0e10cSrcweir 		// But for the moment we need a quick solution ...
612cdf0e10cSrcweir 		// (the main thing would be to store the translations to use here in the user interface, besides that, the code
613cdf0e10cSrcweir 		// should be adjustable with a rather small effort.)
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 		// initialize the strings for the field labels
616cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_FIRSTNAME )) );
617cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_LASTNAME )) );
618cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_COMPANY)) );
619cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_DEPARTMENT )) );
620cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_STREET )) );
621cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_ZIPCODE )) );
622cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_CITY )) );
623cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_STATE)) );
624cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_COUNTRY )) );
625cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_HOMETEL )) );
626cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_WORKTEL )) );
627cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_OFFICETEL)) );
628cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_MOBILE)) );
629cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_TELOTHER)) );
630cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_PAGER)) );
631cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_FAX )) );
632cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_EMAIL )) );
633cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_URL )) );
634cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_TITLE )) );
635cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_POSITION )) );
636cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_INITIALS )) );
637cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_ADDRFORM )) );
638cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_SALUTATION )) );
639cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_ID)) );
640cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_CALENDAR)) );
641cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_INVITE)) );
642cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_NOTE)) );
643cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_USER1)) );
644cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_USER2)) );
645cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_USER3)) );
646cdf0e10cSrcweir 		m_pImpl->aFieldLabels.push_back( String(SvtResId( STR_FIELD_USER4)) );
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 		// force a even number of known fields
649cdf0e10cSrcweir 		m_pImpl->bOddFieldNumber = (m_pImpl->aFieldLabels.size() % 2) != 0;
650cdf0e10cSrcweir 		if (m_pImpl->bOddFieldNumber)
651cdf0e10cSrcweir 			m_pImpl->aFieldLabels.push_back( String() );
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 		// limit the scrollbar range accordingly
654cdf0e10cSrcweir 		sal_Int32 nOverallFieldPairs = m_pImpl->aFieldLabels.size() / 2;
655cdf0e10cSrcweir 		m_aFieldScroller.SetRange( Range(0, nOverallFieldPairs - FIELD_PAIRS_VISIBLE) );
656cdf0e10cSrcweir 		m_aFieldScroller.SetLineSize(1);
657cdf0e10cSrcweir 		m_aFieldScroller.SetPageSize(FIELD_PAIRS_VISIBLE);
658cdf0e10cSrcweir 
659cdf0e10cSrcweir 		// reset the current field assignments
660cdf0e10cSrcweir 		m_pImpl->aFieldAssignments.resize(m_pImpl->aFieldLabels.size());
661cdf0e10cSrcweir 			// (empty strings mean "no assignment")
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 		// some knittings
664cdf0e10cSrcweir 		m_aFieldScroller.SetScrollHdl(LINK(this, AddressBookSourceDialog, OnFieldScroll));
665cdf0e10cSrcweir 		m_aAdministrateDatasources.SetClickHdl(LINK(this, AddressBookSourceDialog, OnAdministrateDatasources));
666cdf0e10cSrcweir 		m_aDatasource.EnableAutocomplete(sal_True);
667cdf0e10cSrcweir 		m_aTable.EnableAutocomplete(sal_True);
668cdf0e10cSrcweir 		m_aTable.SetGetFocusHdl(LINK(this, AddressBookSourceDialog, OnComboGetFocus));
669cdf0e10cSrcweir 		m_aDatasource.SetGetFocusHdl(LINK(this, AddressBookSourceDialog, OnComboGetFocus));
670cdf0e10cSrcweir 		m_aTable.SetLoseFocusHdl(LINK(this, AddressBookSourceDialog, OnComboLoseFocus));
671cdf0e10cSrcweir 		m_aDatasource.SetLoseFocusHdl(LINK(this, AddressBookSourceDialog, OnComboLoseFocus));
672cdf0e10cSrcweir 		m_aTable.SetSelectHdl(LINK(this, AddressBookSourceDialog, OnComboSelect));
673cdf0e10cSrcweir 		m_aDatasource.SetSelectHdl(LINK(this, AddressBookSourceDialog, OnComboSelect));
674cdf0e10cSrcweir 		m_aOK.SetClickHdl(LINK(this, AddressBookSourceDialog, OnOkClicked));
675cdf0e10cSrcweir 
676cdf0e10cSrcweir 		m_aDatasource.SetDropDownLineCount(15);
677cdf0e10cSrcweir 
678cdf0e10cSrcweir 		// initialize the field controls
679cdf0e10cSrcweir 		resetFields();
680cdf0e10cSrcweir 		m_aFieldScroller.SetThumbPos(0);
681cdf0e10cSrcweir 		m_pImpl->nFieldScrollPos = -1;
682cdf0e10cSrcweir 		implScrollFields(0, sal_False, sal_False);
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 		// the logical names
685cdf0e10cSrcweir 		String sLogicalFieldNames(SvtResId(STR_LOCAGICAL_FIELD_NAMES));
686cdf0e10cSrcweir 		sal_Int32 nAdjustedTokenCount = sLogicalFieldNames.GetTokenCount(';') + (m_pImpl->bOddFieldNumber ? 1 : 0);
687cdf0e10cSrcweir 		DBG_ASSERT(nAdjustedTokenCount == (sal_Int32)m_pImpl->aFieldLabels.size(),
688cdf0e10cSrcweir 			"AddressBookSourceDialog::AddressBookSourceDialog: inconsistence between logical and UI field names!");
689cdf0e10cSrcweir 		m_pImpl->aLogicalFieldNames.reserve(nAdjustedTokenCount);
690cdf0e10cSrcweir 		for (sal_Int32 i = 0; i<nAdjustedTokenCount; ++i)
691cdf0e10cSrcweir 			m_pImpl->aLogicalFieldNames.push_back(sLogicalFieldNames.GetToken((sal_uInt16)i, ';'));
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 		PostUserEvent(LINK(this, AddressBookSourceDialog, OnDelayedInitialize));
694cdf0e10cSrcweir 			// so the dialog will at least show up before we do the loading of the
695cdf0e10cSrcweir 			// configuration data and the (maybe time consuming) analysis of the data source/table to select
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 		FreeResource();
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 		if ( !m_pImpl->bWorkingPersistent )
700cdf0e10cSrcweir 		{
701cdf0e10cSrcweir 			StyleSettings aSystemStyle = GetSettings().GetStyleSettings();
702cdf0e10cSrcweir 			const Color& rNewColor = aSystemStyle.GetDialogColor();
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 			m_aDatasource.SetReadOnly( sal_True );
705cdf0e10cSrcweir 			m_aDatasource.SetBackground( Wallpaper( rNewColor ) );
706cdf0e10cSrcweir 			m_aDatasource.SetControlBackground( rNewColor );
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 			m_aTable.SetReadOnly( sal_True );
709cdf0e10cSrcweir 			m_aTable.SetBackground( Wallpaper( rNewColor ) );
710cdf0e10cSrcweir 			m_aTable.SetControlBackground( rNewColor );
711cdf0e10cSrcweir 
712cdf0e10cSrcweir 			m_aAdministrateDatasources.Hide( );
713cdf0e10cSrcweir 		}
714cdf0e10cSrcweir 	}
715cdf0e10cSrcweir 
716cdf0e10cSrcweir 	// -------------------------------------------------------------------
717cdf0e10cSrcweir 	void AddressBookSourceDialog::getFieldMapping(Sequence< AliasProgrammaticPair >& _rMapping) const
718cdf0e10cSrcweir 	{
719cdf0e10cSrcweir 		_rMapping.realloc( m_pImpl->aLogicalFieldNames.size() );
720cdf0e10cSrcweir 		AliasProgrammaticPair* pPair = _rMapping.getArray();
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 		::rtl::OUString sCurrent;
723cdf0e10cSrcweir 		for	(	ConstStringArrayIterator aProgrammatic = m_pImpl->aLogicalFieldNames.begin();
724cdf0e10cSrcweir 				aProgrammatic != m_pImpl->aLogicalFieldNames.end();
725cdf0e10cSrcweir 				++aProgrammatic
726cdf0e10cSrcweir 			)
727cdf0e10cSrcweir 		{
728cdf0e10cSrcweir 			sCurrent = *aProgrammatic;
729cdf0e10cSrcweir 			if ( m_pImpl->pConfigData->hasFieldAssignment( sCurrent ) )
730cdf0e10cSrcweir 			{
731cdf0e10cSrcweir 				// the user gave us an assignment for this field
732cdf0e10cSrcweir 				pPair->ProgrammaticName = *aProgrammatic;
733cdf0e10cSrcweir 				pPair->Alias = m_pImpl->pConfigData->getFieldAssignment( *aProgrammatic );
734cdf0e10cSrcweir 				++pPair;
735cdf0e10cSrcweir 			}
736cdf0e10cSrcweir 		}
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 		_rMapping.realloc( pPair - _rMapping.getArray() );
739cdf0e10cSrcweir 	}
740cdf0e10cSrcweir 
741cdf0e10cSrcweir 	// -------------------------------------------------------------------
742cdf0e10cSrcweir 	void AddressBookSourceDialog::loadConfiguration()
743cdf0e10cSrcweir 	{
744cdf0e10cSrcweir         ::rtl::OUString sName = m_pImpl->pConfigData->getDatasourceName();
745cdf0e10cSrcweir         INetURLObject aURL( sName );
746cdf0e10cSrcweir         if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
747cdf0e10cSrcweir 		{
748cdf0e10cSrcweir 			OFileNotation aFileNotation( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
749cdf0e10cSrcweir 			sName = aFileNotation.get(OFileNotation::N_SYSTEM);
750cdf0e10cSrcweir         }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir 		m_aDatasource.SetText(sName);
753cdf0e10cSrcweir 		m_aTable.SetText(m_pImpl->pConfigData->getCommand());
754cdf0e10cSrcweir 		// we ignore the CommandType: only tables are supported
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 		// the logical names for the fields
757cdf0e10cSrcweir 		DBG_ASSERT(m_pImpl->aLogicalFieldNames.size() == m_pImpl->aFieldAssignments.size(),
758cdf0e10cSrcweir 			"AddressBookSourceDialog::loadConfiguration: inconsistence between field names and field assignments!");
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 		ConstStringArrayIterator aLogical = m_pImpl->aLogicalFieldNames.begin();
761cdf0e10cSrcweir 		StringArrayIterator aAssignment = m_pImpl->aFieldAssignments.begin();
762cdf0e10cSrcweir 		for	(	;
763cdf0e10cSrcweir 				aLogical < m_pImpl->aLogicalFieldNames.end();
764cdf0e10cSrcweir 				++aLogical, ++aAssignment
765cdf0e10cSrcweir 			)
766cdf0e10cSrcweir 			*aAssignment = m_pImpl->pConfigData->getFieldAssignment(*aLogical);
767cdf0e10cSrcweir 	}
768cdf0e10cSrcweir 
769cdf0e10cSrcweir 	// -------------------------------------------------------------------
770cdf0e10cSrcweir 	AddressBookSourceDialog::~AddressBookSourceDialog()
771cdf0e10cSrcweir 	{
772cdf0e10cSrcweir 		sal_Int32 i;
773cdf0e10cSrcweir 		for (i=0; i<FIELD_CONTROLS_VISIBLE; ++i)
774cdf0e10cSrcweir 		{
775cdf0e10cSrcweir 			delete m_pImpl->pFieldLabels[i];
776cdf0e10cSrcweir 			delete m_pImpl->pFields[i];
777cdf0e10cSrcweir 		}
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 		delete m_pImpl;
780cdf0e10cSrcweir 	}
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 	// -------------------------------------------------------------------
783cdf0e10cSrcweir 	void AddressBookSourceDialog::initializeDatasources()
784cdf0e10cSrcweir 	{
785cdf0e10cSrcweir 		if (!m_xDatabaseContext.is())
786cdf0e10cSrcweir 		{
787cdf0e10cSrcweir 			DBG_ASSERT(m_xORB.is(), "AddressBookSourceDialog::initializeDatasources: no service factory!");
788cdf0e10cSrcweir 			if (!m_xORB.is())
789cdf0e10cSrcweir 				return;
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 			const String sContextServiceName = String::CreateFromAscii("com.sun.star.sdb.DatabaseContext");
792cdf0e10cSrcweir 			try
793cdf0e10cSrcweir 			{
794cdf0e10cSrcweir 				m_xDatabaseContext = Reference< XNameAccess >(m_xORB->createInstance(sContextServiceName), UNO_QUERY);
795cdf0e10cSrcweir 			}
796cdf0e10cSrcweir 			catch(Exception&) { }
797cdf0e10cSrcweir 			if (!m_xDatabaseContext.is())
798cdf0e10cSrcweir 			{
799cdf0e10cSrcweir 				ShowServiceNotAvailableError( this, sContextServiceName, sal_False);
800cdf0e10cSrcweir 				return;
801cdf0e10cSrcweir 			}
802cdf0e10cSrcweir 		}
803cdf0e10cSrcweir 		m_aDatasource.Clear();
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 		// fill the datasources listbox
806cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aDatasourceNames;
807cdf0e10cSrcweir 		try
808cdf0e10cSrcweir 		{
809cdf0e10cSrcweir 			aDatasourceNames = m_xDatabaseContext->getElementNames();
810cdf0e10cSrcweir 		}
811cdf0e10cSrcweir 		catch(Exception&)
812cdf0e10cSrcweir 		{
813cdf0e10cSrcweir 			DBG_ERROR("AddressBookSourceDialog::initializeDatasources: caught an exception while asking for the data source names!");
814cdf0e10cSrcweir 		}
815cdf0e10cSrcweir 		const ::rtl::OUString* pDatasourceNames = aDatasourceNames.getConstArray();
816cdf0e10cSrcweir 		const ::rtl::OUString* pEnd = pDatasourceNames + aDatasourceNames.getLength();
817cdf0e10cSrcweir 		for (; pDatasourceNames < pEnd; ++pDatasourceNames)
818cdf0e10cSrcweir 			m_aDatasource.InsertEntry(*pDatasourceNames);
819cdf0e10cSrcweir 	}
820cdf0e10cSrcweir 
821cdf0e10cSrcweir 	// -------------------------------------------------------------------
822cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnFieldScroll, ScrollBar*, _pScrollBar)
823cdf0e10cSrcweir 	{
824cdf0e10cSrcweir 		implScrollFields( _pScrollBar->GetThumbPos(), sal_True, sal_True );
825cdf0e10cSrcweir 		return 0L;
826cdf0e10cSrcweir 	}
827cdf0e10cSrcweir 
828cdf0e10cSrcweir 	// -------------------------------------------------------------------
829cdf0e10cSrcweir 	void AddressBookSourceDialog::resetTables()
830cdf0e10cSrcweir 	{
831cdf0e10cSrcweir 		if (!m_xDatabaseContext.is())
832cdf0e10cSrcweir 			return;
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 		WaitObject aWaitCursor(this);
835cdf0e10cSrcweir 
836cdf0e10cSrcweir 		// no matter what we do here, we handled the currently selected data source (no matter if successfull or not)
837cdf0e10cSrcweir 		m_aDatasource.SaveValue();
838cdf0e10cSrcweir 
839cdf0e10cSrcweir 		// create an interaction handler (may be needed for connecting)
840cdf0e10cSrcweir 		const String sInteractionHandlerServiceName = String::CreateFromAscii("com.sun.star.task.InteractionHandler");
841cdf0e10cSrcweir 		Reference< XInteractionHandler > xHandler;
842cdf0e10cSrcweir 		try
843cdf0e10cSrcweir 		{
844cdf0e10cSrcweir 			xHandler = Reference< XInteractionHandler >(m_xORB->createInstance(sInteractionHandlerServiceName), UNO_QUERY);
845cdf0e10cSrcweir 		}
846cdf0e10cSrcweir 		catch(Exception&) { }
847cdf0e10cSrcweir 		if (!xHandler.is())
848cdf0e10cSrcweir 		{
849cdf0e10cSrcweir 			ShowServiceNotAvailableError(this, sInteractionHandlerServiceName, sal_True);
850cdf0e10cSrcweir 			return;
851cdf0e10cSrcweir 		}
852cdf0e10cSrcweir 
853cdf0e10cSrcweir 		// the currently selected table
854cdf0e10cSrcweir 		::rtl::OUString sOldTable = m_aTable.GetText();
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 		m_aTable.Clear();
857cdf0e10cSrcweir 
858cdf0e10cSrcweir 		m_xCurrentDatasourceTables= NULL;
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 		// get the tables of the connection
861cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aTableNames;
862cdf0e10cSrcweir 		Any aException;
863cdf0e10cSrcweir 		try
864cdf0e10cSrcweir 		{
865cdf0e10cSrcweir 			Reference< XCompletedConnection > xDS;
866cdf0e10cSrcweir             if ( m_pImpl->bWorkingPersistent )
867cdf0e10cSrcweir             {
868cdf0e10cSrcweir                 String sSelectedDS = lcl_getSelectedDataSource(  m_aDatasource );
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 			    // get the data source the user has chosen and let it build a connection
871cdf0e10cSrcweir                 INetURLObject aURL( sSelectedDS );
872cdf0e10cSrcweir                 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID || m_xDatabaseContext->hasByName(sSelectedDS) )
873cdf0e10cSrcweir 				    m_xDatabaseContext->getByName( sSelectedDS ) >>= xDS;
874cdf0e10cSrcweir             }
875cdf0e10cSrcweir             else
876cdf0e10cSrcweir             {
877cdf0e10cSrcweir                 xDS = xDS.query( m_pImpl->m_xTransientDataSource );
878cdf0e10cSrcweir             }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 			// build the connection
881cdf0e10cSrcweir 			Reference< XConnection > xConn;
882cdf0e10cSrcweir             if (xDS.is())
883cdf0e10cSrcweir 				xConn = xDS->connectWithCompletion(xHandler);
884cdf0e10cSrcweir 
885cdf0e10cSrcweir 			// get the table names
886cdf0e10cSrcweir 			Reference< XTablesSupplier > xSupplTables(xConn, UNO_QUERY);
887cdf0e10cSrcweir 			if (xSupplTables.is())
888cdf0e10cSrcweir 			{
889cdf0e10cSrcweir 				m_xCurrentDatasourceTables = Reference< XNameAccess >(xSupplTables->getTables(), UNO_QUERY);
890cdf0e10cSrcweir 				if (m_xCurrentDatasourceTables.is())
891cdf0e10cSrcweir 					aTableNames = m_xCurrentDatasourceTables->getElementNames();
892cdf0e10cSrcweir 			}
893cdf0e10cSrcweir 		}
894cdf0e10cSrcweir 		catch(SQLContext& e) { aException <<= e; }
895cdf0e10cSrcweir 		catch(SQLWarning& e) { aException <<= e; }
896cdf0e10cSrcweir 		catch(SQLException& e) { aException <<= e; }
897cdf0e10cSrcweir 		catch(Exception&)
898cdf0e10cSrcweir 		{
899cdf0e10cSrcweir 			DBG_ERROR("AddressBookSourceDialog::resetTables: could not retrieve the table!");
900cdf0e10cSrcweir 		}
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 		if (aException.hasValue())
903cdf0e10cSrcweir 		{
904cdf0e10cSrcweir 			Reference< XInteractionRequest > xRequest = new OInteractionRequest(aException);
905cdf0e10cSrcweir 			try
906cdf0e10cSrcweir 			{
907cdf0e10cSrcweir 				xHandler->handle(xRequest);
908cdf0e10cSrcweir 			}
909cdf0e10cSrcweir 			catch(Exception&) { }
910cdf0e10cSrcweir 			return;
911cdf0e10cSrcweir 		}
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 		sal_Bool bKnowOldTable = sal_False;
914cdf0e10cSrcweir 		// fill the table list
915cdf0e10cSrcweir 		const ::rtl::OUString* pTableNames = aTableNames.getConstArray();
916cdf0e10cSrcweir 		const ::rtl::OUString* pEnd = pTableNames + aTableNames.getLength();
917cdf0e10cSrcweir 		for (;pTableNames != pEnd; ++pTableNames)
918cdf0e10cSrcweir 		{
919cdf0e10cSrcweir 			m_aTable.InsertEntry(*pTableNames);
920cdf0e10cSrcweir 			if (0 == pTableNames->compareTo(sOldTable))
921cdf0e10cSrcweir 				bKnowOldTable = sal_True;
922cdf0e10cSrcweir 		}
923cdf0e10cSrcweir 
924cdf0e10cSrcweir 		// set the old table, if the new data source knows a table with this name, too. Else reset the tables edit field.
925cdf0e10cSrcweir 		if (!bKnowOldTable)
926cdf0e10cSrcweir 			sOldTable = ::rtl::OUString();
927cdf0e10cSrcweir 		m_aTable.SetText(sOldTable);
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 		resetFields();
930cdf0e10cSrcweir 	}
931cdf0e10cSrcweir 
932cdf0e10cSrcweir 	// -------------------------------------------------------------------
933cdf0e10cSrcweir 	void AddressBookSourceDialog::resetFields()
934cdf0e10cSrcweir 	{
935cdf0e10cSrcweir 		WaitObject aWaitCursor(this);
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 		// no matter what we do here, we handled the currently selected table (no matter if successfull or not)
938cdf0e10cSrcweir 		m_aDatasource.SaveValue();
939cdf0e10cSrcweir 
940cdf0e10cSrcweir 		String sSelectedTable = m_aTable.GetText();
941cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aColumnNames;
942cdf0e10cSrcweir 		try
943cdf0e10cSrcweir 		{
944cdf0e10cSrcweir 			if (m_xCurrentDatasourceTables.is())
945cdf0e10cSrcweir 			{
946cdf0e10cSrcweir 				// get the table and the columns
947cdf0e10cSrcweir 				Reference< XColumnsSupplier > xSuppTableCols;
948cdf0e10cSrcweir 				if (m_xCurrentDatasourceTables->hasByName(sSelectedTable))
949cdf0e10cSrcweir 					::cppu::extractInterface(xSuppTableCols, m_xCurrentDatasourceTables->getByName(sSelectedTable));
950cdf0e10cSrcweir 				Reference< XNameAccess > xColumns;
951cdf0e10cSrcweir 				if (xSuppTableCols.is())
952cdf0e10cSrcweir 					xColumns = xSuppTableCols->getColumns();
953cdf0e10cSrcweir 				if (xColumns.is())
954cdf0e10cSrcweir 					aColumnNames = xColumns->getElementNames();
955cdf0e10cSrcweir 			}
956cdf0e10cSrcweir 		}
957cdf0e10cSrcweir 		catch(Exception&)
958cdf0e10cSrcweir 		{
959cdf0e10cSrcweir 			DBG_ERROR("AddressBookSourceDialog::resetFields: could not retrieve the table columns!");
960cdf0e10cSrcweir 		}
961cdf0e10cSrcweir 
962cdf0e10cSrcweir 
963cdf0e10cSrcweir 		const ::rtl::OUString* pColumnNames = aColumnNames.getConstArray();
964cdf0e10cSrcweir 		const ::rtl::OUString* pEnd = pColumnNames + aColumnNames.getLength();
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 		// for quicker access
967cdf0e10cSrcweir 		::std::set< String > aColumnNameSet;
968cdf0e10cSrcweir 		for (pColumnNames = aColumnNames.getConstArray(); pColumnNames != pEnd; ++pColumnNames)
969cdf0e10cSrcweir 			aColumnNameSet.insert(*pColumnNames);
970cdf0e10cSrcweir 
971cdf0e10cSrcweir 		std::vector<String>::iterator aInitialSelection = m_pImpl->aFieldAssignments.begin() + m_pImpl->nFieldScrollPos;
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 		ListBox** pListbox = m_pImpl->pFields;
974cdf0e10cSrcweir 		String sSaveSelection;
975cdf0e10cSrcweir 		for (sal_Int32 i=0; i<FIELD_CONTROLS_VISIBLE; ++i, ++pListbox, ++aInitialSelection)
976cdf0e10cSrcweir 		{
977cdf0e10cSrcweir 			sSaveSelection = (*pListbox)->GetSelectEntry();
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 			(*pListbox)->Clear();
980cdf0e10cSrcweir 
981cdf0e10cSrcweir 			// the one entry for "no selection"
982cdf0e10cSrcweir 			(*pListbox)->InsertEntry(m_sNoFieldSelection, 0);
983cdf0e10cSrcweir 			// as it's entry data, set the index of the list box in our array
984cdf0e10cSrcweir 			(*pListbox)->SetEntryData(0, reinterpret_cast<void*>(i));
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 			// the field names
987cdf0e10cSrcweir 			for (pColumnNames = aColumnNames.getConstArray(); pColumnNames != pEnd; ++pColumnNames)
988cdf0e10cSrcweir 				(*pListbox)->InsertEntry(*pColumnNames);
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 			if (aInitialSelection->Len() && (aColumnNameSet.end() != aColumnNameSet.find(*aInitialSelection)))
991cdf0e10cSrcweir 				// we can select the entry as specified in our field assignment array
992cdf0e10cSrcweir 				(*pListbox)->SelectEntry(*aInitialSelection);
993cdf0e10cSrcweir 			else
994cdf0e10cSrcweir 				// try to restore the selection
995cdf0e10cSrcweir 				if (aColumnNameSet.end() != aColumnNameSet.find(sSaveSelection))
996cdf0e10cSrcweir 					// the old selection is a valid column name
997cdf0e10cSrcweir 					(*pListbox)->SelectEntry(sSaveSelection);
998cdf0e10cSrcweir 				else
999cdf0e10cSrcweir 					// select the <none> entry
1000cdf0e10cSrcweir 					(*pListbox)->SelectEntryPos(0);
1001cdf0e10cSrcweir 		}
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 		// adjust m_pImpl->aFieldAssignments
1004cdf0e10cSrcweir 		for (	StringArrayIterator aAdjust = m_pImpl->aFieldAssignments.begin();
1005cdf0e10cSrcweir 				aAdjust != m_pImpl->aFieldAssignments.end();
1006cdf0e10cSrcweir 				++aAdjust
1007cdf0e10cSrcweir 			)
1008cdf0e10cSrcweir 			if (aAdjust->Len())
1009cdf0e10cSrcweir 				if (aColumnNameSet.end() == aColumnNameSet.find(*aAdjust))
1010cdf0e10cSrcweir 					aAdjust->Erase();
1011cdf0e10cSrcweir 	}
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 	// -------------------------------------------------------------------
1014cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnFieldSelect, ListBox*, _pListbox)
1015cdf0e10cSrcweir 	{
1016cdf0e10cSrcweir 		// the index of the affected list box in our array
1017cdf0e10cSrcweir 		sal_IntPtr nListBoxIndex = reinterpret_cast<sal_IntPtr>(_pListbox->GetEntryData(0));
1018cdf0e10cSrcweir 		DBG_ASSERT(nListBoxIndex >= 0 && nListBoxIndex < FIELD_CONTROLS_VISIBLE,
1019cdf0e10cSrcweir 			"AddressBookSourceDialog::OnFieldScroll: invalid list box entry!");
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir 		// update the array where we remember the field selections
1022cdf0e10cSrcweir 		if (0 == _pListbox->GetSelectEntryPos())
1023cdf0e10cSrcweir 			// it's the "no field selection" entry
1024cdf0e10cSrcweir 			m_pImpl->aFieldAssignments[m_pImpl->nFieldScrollPos * 2 + nListBoxIndex] = String();
1025cdf0e10cSrcweir 		else
1026cdf0e10cSrcweir 			// it's a regular field entry
1027cdf0e10cSrcweir 			m_pImpl->aFieldAssignments[m_pImpl->nFieldScrollPos * 2 + nListBoxIndex] = _pListbox->GetSelectEntry();
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir 		return 0L;
1030cdf0e10cSrcweir 	}
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir 	// -------------------------------------------------------------------
1033cdf0e10cSrcweir 	void AddressBookSourceDialog::implScrollFields(sal_Int32 _nPos, sal_Bool _bAdjustFocus, sal_Bool _bAdjustScrollbar)
1034cdf0e10cSrcweir 	{
1035cdf0e10cSrcweir 		if (_nPos == m_pImpl->nFieldScrollPos)
1036cdf0e10cSrcweir 			// nothing to do
1037cdf0e10cSrcweir 			return;
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir 		// loop through our field control rows and do some adjustments
1040cdf0e10cSrcweir 		// for the new texts
1041cdf0e10cSrcweir 		FixedText** pLeftLabelControl = m_pImpl->pFieldLabels;
1042cdf0e10cSrcweir 		FixedText** pRightLabelControl = pLeftLabelControl + 1;
1043cdf0e10cSrcweir 		ConstStringArrayIterator pLeftColumnLabel = m_pImpl->aFieldLabels.begin() + 2 * _nPos;
1044cdf0e10cSrcweir 		ConstStringArrayIterator pRightColumnLabel = pLeftColumnLabel + 1;
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir 		// for the focus movement and the selection scroll
1047cdf0e10cSrcweir 		ListBox** pLeftListControl = m_pImpl->pFields;
1048cdf0e10cSrcweir 		ListBox** pRightListControl = pLeftListControl + 1;
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 		// for the focus movement
1051cdf0e10cSrcweir 		sal_Int32 nOldFocusRow = -1;
1052cdf0e10cSrcweir 		sal_Int32 nOldFocusColumn = 0;
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir 		// for the selection scroll
1055cdf0e10cSrcweir 		ConstStringArrayIterator pLeftAssignment = m_pImpl->aFieldAssignments.begin() + 2 * _nPos;
1056cdf0e10cSrcweir 		ConstStringArrayIterator pRightAssignment = pLeftAssignment + 1;
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir 		m_pImpl->nLastVisibleListIndex = -1;
1059cdf0e10cSrcweir 		// loop
1060cdf0e10cSrcweir 		for (sal_Int32 i=0; i<FIELD_PAIRS_VISIBLE; ++i)
1061cdf0e10cSrcweir 		{
1062cdf0e10cSrcweir 			if ((*pLeftListControl)->HasChildPathFocus())
1063cdf0e10cSrcweir 			{
1064cdf0e10cSrcweir 				nOldFocusRow = i;
1065cdf0e10cSrcweir 				nOldFocusColumn = 0;
1066cdf0e10cSrcweir 			}
1067cdf0e10cSrcweir 			else if ((*pRightListControl)->HasChildPathFocus())
1068cdf0e10cSrcweir 			{
1069cdf0e10cSrcweir 				nOldFocusRow = i;
1070cdf0e10cSrcweir 				nOldFocusColumn = 1;
1071cdf0e10cSrcweir 			}
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir 			// the new texts of the label controls
1074cdf0e10cSrcweir 			(*pLeftLabelControl)->SetText(*pLeftColumnLabel);
1075cdf0e10cSrcweir 			(*pRightLabelControl)->SetText(*pRightColumnLabel);
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir 			// we may have to hide the controls in the right column, if we have no label text for it
1078cdf0e10cSrcweir 			// (which means we have an odd number of fields, though we forced our internal arrays to
1079cdf0e10cSrcweir 			// be even-sized for easier handling)
1080cdf0e10cSrcweir 			// (If sometimes we support an arbitrary number of field assignments, we would have to care for
1081cdf0e10cSrcweir 			// an invisible left hand side column, too. But right now, the left hand side controls are always
1082cdf0e10cSrcweir 			// visible)
1083cdf0e10cSrcweir 			sal_Bool bHideRightColumn = (0 == pRightColumnLabel->Len());
1084cdf0e10cSrcweir 			(*pRightLabelControl)->Show(!bHideRightColumn);
1085cdf0e10cSrcweir 			(*pRightListControl)->Show(!bHideRightColumn);
1086cdf0e10cSrcweir 			// the new selections of the listboxes
1087cdf0e10cSrcweir 			implSelectField(*pLeftListControl, *pLeftAssignment);
1088cdf0e10cSrcweir 			implSelectField(*pRightListControl, *pRightAssignment);
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir 			// the index of the last visible list box
1091cdf0e10cSrcweir 			++m_pImpl->nLastVisibleListIndex;	// the left hand side box is always visible
1092cdf0e10cSrcweir 			if (!bHideRightColumn)
1093cdf0e10cSrcweir 				++m_pImpl->nLastVisibleListIndex;
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir 		    // increment ...
1096cdf0e10cSrcweir             if ( i < FIELD_PAIRS_VISIBLE - 1 )
1097cdf0e10cSrcweir             {   // (not in the very last round, here the +=2 could result in an invalid
1098cdf0e10cSrcweir                 // iterator position, which causes an abort in a non-product version
1099cdf0e10cSrcweir 			    pLeftLabelControl += 2;
1100cdf0e10cSrcweir 			    pRightLabelControl += 2;
1101cdf0e10cSrcweir 			    pLeftColumnLabel += 2;
1102cdf0e10cSrcweir 			    pRightColumnLabel += 2;
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 			    pLeftListControl += 2;
1105cdf0e10cSrcweir 			    pRightListControl += 2;
1106cdf0e10cSrcweir 			    pLeftAssignment += 2;
1107cdf0e10cSrcweir 			    pRightAssignment += 2;
1108cdf0e10cSrcweir             }
1109cdf0e10cSrcweir 		}
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir 		if (_bAdjustFocus && (nOldFocusRow >= 0))
1112cdf0e10cSrcweir 		{	// we have to adjust the focus and one of the list boxes has the focus
1113cdf0e10cSrcweir 			sal_Int32 nDelta = m_pImpl->nFieldScrollPos - _nPos;
1114cdf0e10cSrcweir 			// the new row for the focus
1115cdf0e10cSrcweir 			sal_Int32 nNewFocusRow = nOldFocusRow + nDelta;
1116cdf0e10cSrcweir 			// normalize
1117cdf0e10cSrcweir 			nNewFocusRow = std::min(nNewFocusRow, (sal_Int32)(FIELD_PAIRS_VISIBLE - 1), ::std::less< sal_Int32 >());
1118cdf0e10cSrcweir 			nNewFocusRow = std::max(nNewFocusRow, (sal_Int32)0, ::std::less< sal_Int32 >());
1119cdf0e10cSrcweir 			// set the new focus (in the same column)
1120cdf0e10cSrcweir 			m_pImpl->pFields[nNewFocusRow * 2 + nOldFocusColumn]->GrabFocus();
1121cdf0e10cSrcweir 		}
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 		m_pImpl->nFieldScrollPos = _nPos;
1124cdf0e10cSrcweir 
1125cdf0e10cSrcweir 		if (_bAdjustScrollbar)
1126cdf0e10cSrcweir 			m_aFieldScroller.SetThumbPos(m_pImpl->nFieldScrollPos);
1127cdf0e10cSrcweir 	}
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir 	// -------------------------------------------------------------------
1130cdf0e10cSrcweir 	void AddressBookSourceDialog::implSelectField(ListBox* _pBox, const String& _rText)
1131cdf0e10cSrcweir 	{
1132cdf0e10cSrcweir 		if (_rText.Len())
1133cdf0e10cSrcweir 			// a valid field name
1134cdf0e10cSrcweir 			_pBox->SelectEntry(_rText);
1135cdf0e10cSrcweir 		else
1136cdf0e10cSrcweir 			// no selection for this item
1137cdf0e10cSrcweir 			_pBox->SelectEntryPos(0);
1138cdf0e10cSrcweir 	}
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir 	// -------------------------------------------------------------------
1141cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnDelayedInitialize, void*, EMPTYARG)
1142cdf0e10cSrcweir 	{
1143cdf0e10cSrcweir 		// load the initial data from the configuration
1144cdf0e10cSrcweir 		loadConfiguration();
1145cdf0e10cSrcweir 		resetTables();
1146cdf0e10cSrcweir 			// will reset the tables/fields implicitly
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 		if ( !m_pImpl->bWorkingPersistent )
1149cdf0e10cSrcweir 			if ( m_pImpl->pFields[0] )
1150cdf0e10cSrcweir 				m_pImpl->pFields[0]->GrabFocus();
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir 		return 0L;
1153cdf0e10cSrcweir 	}
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir 	// -------------------------------------------------------------------
1156cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnComboSelect, ComboBox*, _pBox)
1157cdf0e10cSrcweir 	{
1158cdf0e10cSrcweir 		if (_pBox == &m_aDatasource)
1159cdf0e10cSrcweir 			resetTables();
1160cdf0e10cSrcweir 		else
1161cdf0e10cSrcweir 			resetFields();
1162cdf0e10cSrcweir 		return 0;
1163cdf0e10cSrcweir 	}
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 	// -------------------------------------------------------------------
1166cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnComboGetFocus, ComboBox*, _pBox)
1167cdf0e10cSrcweir 	{
1168cdf0e10cSrcweir 		_pBox->SaveValue();
1169cdf0e10cSrcweir 		return 0L;
1170cdf0e10cSrcweir 	}
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir 	// -------------------------------------------------------------------
1173cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnComboLoseFocus, ComboBox*, _pBox)
1174cdf0e10cSrcweir 	{
1175cdf0e10cSrcweir 		if (_pBox->GetSavedValue() != _pBox->GetText())
1176cdf0e10cSrcweir 		{
1177cdf0e10cSrcweir 			if (_pBox == &m_aDatasource)
1178cdf0e10cSrcweir 				resetTables();
1179cdf0e10cSrcweir 			else
1180cdf0e10cSrcweir 				resetFields();
1181cdf0e10cSrcweir 		}
1182cdf0e10cSrcweir 		return 0L;
1183cdf0e10cSrcweir 	}
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir 	// -------------------------------------------------------------------
1186cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnOkClicked, Button*, EMPTYARG)
1187cdf0e10cSrcweir 	{
1188cdf0e10cSrcweir         String sSelectedDS = lcl_getSelectedDataSource(  m_aDatasource );
1189cdf0e10cSrcweir         if ( m_pImpl->bWorkingPersistent )
1190cdf0e10cSrcweir         {
1191cdf0e10cSrcweir 		    m_pImpl->pConfigData->setDatasourceName(sSelectedDS);
1192cdf0e10cSrcweir 		    m_pImpl->pConfigData->setCommand(m_aTable.GetText());
1193cdf0e10cSrcweir         }
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 		// set the field assignments
1196cdf0e10cSrcweir 		ConstStringArrayIterator aLogical = m_pImpl->aLogicalFieldNames.begin();
1197cdf0e10cSrcweir 		ConstStringArrayIterator aAssignment = m_pImpl->aFieldAssignments.begin();
1198cdf0e10cSrcweir 		for	(	;
1199cdf0e10cSrcweir 				aLogical < m_pImpl->aLogicalFieldNames.end();
1200cdf0e10cSrcweir 				++aLogical, ++aAssignment
1201cdf0e10cSrcweir 			)
1202cdf0e10cSrcweir 			m_pImpl->pConfigData->setFieldAssignment(*aLogical, *aAssignment);
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir 		EndDialog(RET_OK);
1206cdf0e10cSrcweir 		return 0L;
1207cdf0e10cSrcweir 	}
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 	// -------------------------------------------------------------------
1210cdf0e10cSrcweir 	IMPL_LINK(AddressBookSourceDialog, OnAdministrateDatasources, void*, EMPTYARG)
1211cdf0e10cSrcweir 	{
1212cdf0e10cSrcweir 		// collect some initial arguments for the dialog
1213cdf0e10cSrcweir 		Sequence< Any > aArgs(1);
1214cdf0e10cSrcweir         aArgs[0] <<= PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow")), 0, makeAny(VCLUnoHelper::GetInterface(this)), PropertyState_DIRECT_VALUE);
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir 		// create the dialog object
1217cdf0e10cSrcweir 		const String sDialogServiceName = String::CreateFromAscii("com.sun.star.ui.dialogs.AddressBookSourcePilot");
1218cdf0e10cSrcweir 		Reference< XExecutableDialog > xAdminDialog;
1219cdf0e10cSrcweir 		try
1220cdf0e10cSrcweir 		{
1221cdf0e10cSrcweir 			xAdminDialog = Reference< XExecutableDialog >(m_xORB->createInstanceWithArguments(sDialogServiceName, aArgs), UNO_QUERY);
1222cdf0e10cSrcweir 		}
1223cdf0e10cSrcweir 		catch(Exception&) { }
1224cdf0e10cSrcweir 		if (!xAdminDialog.is())
1225cdf0e10cSrcweir 		{
1226cdf0e10cSrcweir 			ShowServiceNotAvailableError(this, sDialogServiceName, sal_True);
1227cdf0e10cSrcweir 			return 1L;
1228cdf0e10cSrcweir 		}
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir 		// excute the dialog
1231cdf0e10cSrcweir 		try
1232cdf0e10cSrcweir 		{
1233cdf0e10cSrcweir             if ( xAdminDialog->execute() == RET_OK )
1234cdf0e10cSrcweir             {
1235cdf0e10cSrcweir                 Reference<XPropertySet> xProp(xAdminDialog,UNO_QUERY);
1236cdf0e10cSrcweir 				if ( xProp.is() )
1237cdf0e10cSrcweir 				{
1238cdf0e10cSrcweir                     ::rtl::OUString sName;
1239cdf0e10cSrcweir                     xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSourceName"))) >>= sName;
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir                     INetURLObject aURL( sName );
1242cdf0e10cSrcweir                     if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1243cdf0e10cSrcweir 			        {
1244cdf0e10cSrcweir 				        OFileNotation aFileNotation( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1245cdf0e10cSrcweir 				        sName = aFileNotation.get(OFileNotation::N_SYSTEM);
1246cdf0e10cSrcweir                     }
1247cdf0e10cSrcweir                     m_aDatasource.InsertEntry(sName);
1248cdf0e10cSrcweir 					delete m_pImpl->pConfigData;
1249cdf0e10cSrcweir 					m_pImpl->pConfigData = new AssignmentPersistentData();
1250cdf0e10cSrcweir 					loadConfiguration();
1251cdf0e10cSrcweir                     resetTables();
1252cdf0e10cSrcweir 			        // will reset the fields implicitly
1253cdf0e10cSrcweir                 }
1254cdf0e10cSrcweir             }
1255cdf0e10cSrcweir 		}
1256cdf0e10cSrcweir 		catch(Exception&)
1257cdf0e10cSrcweir 		{
1258cdf0e10cSrcweir 			DBG_ERROR("AddressBookSourceDialog::OnAdministrateDatasources: an error occured while executing the administration dialog!");
1259cdf0e10cSrcweir 		}
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 		// re-fill the data source list
1262cdf0e10cSrcweir 		// try to preserve the current selection
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir //		initializeDatasources();
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir 		return 0L;
1267cdf0e10cSrcweir 	}
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir 	// -------------------------------------------------------------------
1270cdf0e10cSrcweir 	long AddressBookSourceDialog::PreNotify( NotifyEvent& _rNEvt )
1271cdf0e10cSrcweir 	{
1272cdf0e10cSrcweir 		switch (_rNEvt.GetType())
1273cdf0e10cSrcweir 		{
1274cdf0e10cSrcweir 			case EVENT_KEYINPUT:
1275cdf0e10cSrcweir 			{
1276cdf0e10cSrcweir 				const KeyEvent* pKeyEvent =	_rNEvt.GetKeyEvent();
1277cdf0e10cSrcweir 				sal_uInt16 nCode  = pKeyEvent->GetKeyCode().GetCode();
1278cdf0e10cSrcweir 				sal_Bool   bShift = pKeyEvent->GetKeyCode().IsShift();
1279cdf0e10cSrcweir 				sal_Bool   bCtrl  = pKeyEvent->GetKeyCode().IsMod1();
1280cdf0e10cSrcweir 				sal_Bool   bAlt =	pKeyEvent->GetKeyCode().IsMod2();
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir 				if (KEY_TAB == nCode)
1283cdf0e10cSrcweir 				{	// somebody pressed the tab key
1284cdf0e10cSrcweir 					if (!bAlt && !bCtrl && !bShift)
1285cdf0e10cSrcweir 					{	// it's really the only the key (no modifiers)
1286cdf0e10cSrcweir 						if (m_pImpl->pFields[m_pImpl->nLastVisibleListIndex]->HasChildPathFocus())
1287cdf0e10cSrcweir 							// the last of our visible list boxes has the focus
1288cdf0e10cSrcweir 							if (m_pImpl->nFieldScrollPos < m_aFieldScroller.GetRangeMax())
1289cdf0e10cSrcweir 							{	// we can still scroll down
1290cdf0e10cSrcweir 								sal_Int32 nNextFocusList = m_pImpl->nLastVisibleListIndex + 1 - 2;
1291cdf0e10cSrcweir 								// -> scroll down
1292cdf0e10cSrcweir 								implScrollFields(m_pImpl->nFieldScrollPos + 1, sal_False, sal_True);
1293cdf0e10cSrcweir 								// give the left control in the "next" line the focus
1294cdf0e10cSrcweir 								m_pImpl->pFields[nNextFocusList]->GrabFocus();
1295cdf0e10cSrcweir 								// return saying "have handled this"
1296cdf0e10cSrcweir 								return 1;
1297cdf0e10cSrcweir 							}
1298cdf0e10cSrcweir 					}
1299cdf0e10cSrcweir 					else if (!bAlt && !bCtrl && bShift)
1300cdf0e10cSrcweir 					{	// it's shift-tab
1301cdf0e10cSrcweir 						if (m_pImpl->pFields[0]->HasChildPathFocus())
1302cdf0e10cSrcweir 							// our first list box has the focus
1303cdf0e10cSrcweir 							if (m_pImpl->nFieldScrollPos > 0)
1304cdf0e10cSrcweir 							{	// we can still scroll up
1305cdf0e10cSrcweir 								// -> scroll up
1306cdf0e10cSrcweir 								implScrollFields(m_pImpl->nFieldScrollPos - 1, sal_False, sal_True);
1307cdf0e10cSrcweir 								// give the right control in the "prebious" line the focus
1308cdf0e10cSrcweir 								m_pImpl->pFields[0 - 1 + 2]->GrabFocus();
1309cdf0e10cSrcweir 								// return saying "have handled this"
1310cdf0e10cSrcweir 								return 1;
1311cdf0e10cSrcweir 							}
1312cdf0e10cSrcweir 					}
1313cdf0e10cSrcweir 				}
1314cdf0e10cSrcweir 			}
1315cdf0e10cSrcweir 			break;
1316cdf0e10cSrcweir 		}
1317cdf0e10cSrcweir 		return ModalDialog::PreNotify(_rNEvt);
1318cdf0e10cSrcweir 	}
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir // .......................................................................
1321cdf0e10cSrcweir }	// namespace svt
1322cdf0e10cSrcweir // .......................................................................
1323cdf0e10cSrcweir 
1324