1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _DBAUI_PARAMDIALOG_HXX_
28cdf0e10cSrcweir #include "paramdialog.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _DBAUI_PARAMDIALOG_HRC_
31cdf0e10cSrcweir #include "paramdialog.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_
34cdf0e10cSrcweir #include "dbu_dlg.hrc"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _DBAUI_COMMON_TYPES_HXX_
37cdf0e10cSrcweir #include "commontypes.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_
40cdf0e10cSrcweir #include "moduledbu.hxx"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
43cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
46cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
49cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
52cdf0e10cSrcweir #include "dbustrings.hrc"
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
55cdf0e10cSrcweir #include <vcl/svapp.hxx>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
58cdf0e10cSrcweir #include <vcl/msgbox.hxx>
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
61cdf0e10cSrcweir #include <tools/debug.hxx>
62cdf0e10cSrcweir #endif
63cdf0e10cSrcweir #include <tools/diagnose_ex.h>
64cdf0e10cSrcweir #ifndef _DBAUI_LOCALRESACCESS_HXX_
65cdf0e10cSrcweir #include "localresaccess.hxx"
66cdf0e10cSrcweir #endif
67cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
68cdf0e10cSrcweir #include <unotools/syslocale.hxx>
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #define EF_VISITED		0x0001
72cdf0e10cSrcweir #define EF_DIRTY		0x0002
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //.........................................................................
75cdf0e10cSrcweir namespace dbaui
76cdf0e10cSrcweir {
77cdf0e10cSrcweir //.........................................................................
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
80cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
81cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
82cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
83cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
84cdf0e10cSrcweir 	using namespace ::com::sun::star::util;
85cdf0e10cSrcweir 	using namespace ::connectivity;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	//==================================================================
88cdf0e10cSrcweir 	//= OParameterDialog
89cdf0e10cSrcweir 	//==================================================================
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	//------------------------------------------------------------------------------
92cdf0e10cSrcweir 	#define INIT_MEMBERS()											\
93cdf0e10cSrcweir 		:ModalDialog( pParent, ModuleRes(DLG_PARAMETERS))			\
94cdf0e10cSrcweir 		,m_aNamesFrame	(this, ModuleRes(FL_PARAMS))					\
95cdf0e10cSrcweir 		,m_aAllParams	(this, ModuleRes(LB_ALLPARAMS))					\
96cdf0e10cSrcweir 		,m_aValueFrame	(this, ModuleRes(FT_VALUE))						\
97cdf0e10cSrcweir 		,m_aParam		(this, ModuleRes(ET_PARAM))						\
98cdf0e10cSrcweir 		,m_aTravelNext	(this, ModuleRes(BT_TRAVELNEXT))				\
99cdf0e10cSrcweir 		,m_aOKBtn		(this, ModuleRes(BT_OK))						\
100cdf0e10cSrcweir 		,m_aCancelBtn	(this, ModuleRes(BT_CANCEL))					\
101cdf0e10cSrcweir 		,m_nCurrentlySelected(LISTBOX_ENTRY_NOTFOUND)				\
102cdf0e10cSrcweir 		,m_xConnection(_rxConnection)								\
103cdf0e10cSrcweir 		,m_aPredicateInput( _rxORB, _rxConnection, getParseContext() )	\
104cdf0e10cSrcweir 		,m_bNeedErrorOnCurrent(sal_True)							\
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	//------------------------------------------------------------------------------
DBG_NAME(OParameterDialog)108cdf0e10cSrcweir DBG_NAME(OParameterDialog)
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	OParameterDialog::OParameterDialog(
111cdf0e10cSrcweir 			Window* pParent, const Reference< XIndexAccess > & rParamContainer,
112cdf0e10cSrcweir 			const Reference< XConnection > & _rxConnection, const Reference< XMultiServiceFactory >& _rxORB)
113cdf0e10cSrcweir 		INIT_MEMBERS()
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir         DBG_CTOR(OParameterDialog,NULL);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		if (_rxORB.is())
118cdf0e10cSrcweir 			m_xFormatter = Reference< XNumberFormatter>(_rxORB->createInstance(
119cdf0e10cSrcweir 			::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
120cdf0e10cSrcweir 		else {
121cdf0e10cSrcweir 			DBG_ERROR("OParameterDialog::OParameterDialog: need a service factory!");
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 		Reference< XNumberFormatsSupplier >  xNumberFormats = ::dbtools::getNumberFormats(m_xConnection, sal_True);
125cdf0e10cSrcweir 		if (!xNumberFormats.is())
126cdf0e10cSrcweir 			::comphelper::disposeComponent(m_xFormatter);
127cdf0e10cSrcweir 		else if (m_xFormatter.is())
128cdf0e10cSrcweir 			m_xFormatter->attachNumberFormatsSupplier(xNumberFormats);
129cdf0e10cSrcweir 		try
130cdf0e10cSrcweir 		{
131cdf0e10cSrcweir 			DBG_ASSERT(rParamContainer->getCount(), "OParameterDialog::OParameterDialog : can't handle empty containers !");
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 			m_aFinalValues.realloc(rParamContainer->getCount());
134cdf0e10cSrcweir 			PropertyValue* pValues = m_aFinalValues.getArray();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 			for (sal_Int32 i = 0, nCount = rParamContainer->getCount(); i<nCount; ++i, ++pValues)
137cdf0e10cSrcweir 			{
138cdf0e10cSrcweir 				Reference< XPropertySet >  xParamAsSet;
139cdf0e10cSrcweir 				rParamContainer->getByIndex(i) >>= xParamAsSet;
140cdf0e10cSrcweir 				OSL_ENSURE(xParamAsSet.is(),"Parameter is null!");
141cdf0e10cSrcweir 				if(!xParamAsSet.is())
142cdf0e10cSrcweir 					continue;
143cdf0e10cSrcweir 				pValues->Name = ::comphelper::getString(xParamAsSet->getPropertyValue(PROPERTY_NAME));
144cdf0e10cSrcweir 				m_aAllParams.InsertEntry(pValues->Name);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 				if (!pValues->Value.hasValue())
147cdf0e10cSrcweir 					// it won't have a value, 'cause it's default constructed. But may be later we support
148cdf0e10cSrcweir 					// initializing this dialog with values
149cdf0e10cSrcweir 					pValues->Value = makeAny(::rtl::OUString());
150cdf0e10cSrcweir 					// default the values to an empty string
151cdf0e10cSrcweir 
152cdf0e10cSrcweir                 m_aVisitedParams.push_back(0);
153cdf0e10cSrcweir 					// not visited, not dirty
154cdf0e10cSrcweir 			}
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 			m_xParams = rParamContainer;
157cdf0e10cSrcweir 		}
158cdf0e10cSrcweir 		catch(Exception&)
159cdf0e10cSrcweir 		{
160cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		Construct();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 		m_aResetVisitFlag.SetTimeoutHdl(LINK(this, OParameterDialog, OnVisitedTimeout));
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 		FreeResource();
169cdf0e10cSrcweir 	}
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	//------------------------------------------------------------------------------
~OParameterDialog()172cdf0e10cSrcweir 	OParameterDialog::~OParameterDialog()
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		if (m_aResetVisitFlag.IsActive())
175cdf0e10cSrcweir 			m_aResetVisitFlag.Stop();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         DBG_DTOR(OParameterDialog,NULL);
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	//------------------------------------------------------------------------------
Construct()181cdf0e10cSrcweir 	void OParameterDialog::Construct()
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		m_aAllParams.SetSelectHdl(LINK(this, OParameterDialog, OnEntrySelected));
184cdf0e10cSrcweir 		m_aParam.SetLoseFocusHdl(LINK(this, OParameterDialog, OnValueLoseFocus));
185cdf0e10cSrcweir 		m_aParam.SetModifyHdl(LINK(this, OParameterDialog, OnValueModified));
186cdf0e10cSrcweir 		m_aTravelNext.SetClickHdl(LINK(this, OParameterDialog, OnButtonClicked));
187cdf0e10cSrcweir 		m_aOKBtn.SetClickHdl(LINK(this, OParameterDialog, OnButtonClicked));
188cdf0e10cSrcweir 		m_aCancelBtn.SetClickHdl(LINK(this, OParameterDialog, OnButtonClicked));
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 		if (m_aAllParams.GetEntryCount())
191cdf0e10cSrcweir 		{
192cdf0e10cSrcweir 			m_aAllParams.SelectEntryPos(0);
193cdf0e10cSrcweir 			LINK(this, OParameterDialog, OnEntrySelected).Call(&m_aAllParams);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 			if (m_aAllParams.GetEntryCount() == 1)
196cdf0e10cSrcweir 			{
197cdf0e10cSrcweir 				m_aTravelNext.Enable(sal_False);
198cdf0e10cSrcweir 			}
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 			if (m_aAllParams.GetEntryCount() > 1)
201cdf0e10cSrcweir 			{
202cdf0e10cSrcweir 				m_aOKBtn.SetStyle(m_aOKBtn.GetStyle() & ~WB_DEFBUTTON);
203cdf0e10cSrcweir 				m_aTravelNext.SetStyle(m_aTravelNext.GetStyle() | WB_DEFBUTTON);
204cdf0e10cSrcweir 			}
205cdf0e10cSrcweir 		}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 		m_aParam.GrabFocus();
208cdf0e10cSrcweir 	}
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	//------------------------------------------------------------------------------
211cdf0e10cSrcweir 	IMPL_LINK(OParameterDialog, OnValueLoseFocus, Control*, /*pSource*/)
212cdf0e10cSrcweir 	{
213cdf0e10cSrcweir 		if (m_nCurrentlySelected != LISTBOX_ENTRY_NOTFOUND)
214cdf0e10cSrcweir 		{
215cdf0e10cSrcweir 			if ( ( m_aVisitedParams[ m_nCurrentlySelected ] & EF_DIRTY ) == 0 )
216cdf0e10cSrcweir 				// nothing to do, the value isn't dirty
217cdf0e10cSrcweir 				return 0L;
218cdf0e10cSrcweir 		}
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 		// transform the current string according to the param field type
221cdf0e10cSrcweir 		::rtl::OUString sTransformedText(m_aParam.GetText());
222cdf0e10cSrcweir 		Reference< XPropertySet >  xParamAsSet;
223cdf0e10cSrcweir 		m_xParams->getByIndex(m_nCurrentlySelected) >>= xParamAsSet;
224cdf0e10cSrcweir 		if (xParamAsSet.is())
225cdf0e10cSrcweir 		{
226cdf0e10cSrcweir 			if (m_xConnection.is() && m_xFormatter.is())
227cdf0e10cSrcweir 			{
228cdf0e10cSrcweir 				::rtl::OUString sParamValue( m_aParam.GetText() );
229cdf0e10cSrcweir 				sal_Bool bValid = m_aPredicateInput.normalizePredicateString( sParamValue, xParamAsSet );
230cdf0e10cSrcweir 				m_aParam.SetText( sParamValue );
231cdf0e10cSrcweir 				if ( bValid )
232cdf0e10cSrcweir 				{
233cdf0e10cSrcweir 					// with this the value isn't dirty anymore
234cdf0e10cSrcweir 					if (m_nCurrentlySelected != LISTBOX_ENTRY_NOTFOUND)
235cdf0e10cSrcweir 						m_aVisitedParams[m_nCurrentlySelected] &= ~EF_DIRTY;
236cdf0e10cSrcweir 				}
237cdf0e10cSrcweir 				else
238cdf0e10cSrcweir 				{
239cdf0e10cSrcweir 					if (!m_bNeedErrorOnCurrent)
240cdf0e10cSrcweir 						return 1L;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 					m_bNeedErrorOnCurrent = sal_False;	// will be reset in OnValueModified
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 					::rtl::OUString sName;
245cdf0e10cSrcweir 					try
246cdf0e10cSrcweir 					{
247cdf0e10cSrcweir 						sName = ::comphelper::getString(xParamAsSet->getPropertyValue(PROPERTY_NAME));
248cdf0e10cSrcweir 					}
249cdf0e10cSrcweir 					catch(Exception&)
250cdf0e10cSrcweir 					{
251cdf0e10cSrcweir                         DBG_UNHANDLED_EXCEPTION();
252cdf0e10cSrcweir 					}
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 					String sMessage;
255cdf0e10cSrcweir 					{
256cdf0e10cSrcweir 						LocalResourceAccess aDummy(DLG_PARAMETERS, RSC_MODALDIALOG);
257cdf0e10cSrcweir 						sMessage = String(ModuleRes(STR_COULD_NOT_CONVERT_PARAM));
258cdf0e10cSrcweir 					}
259cdf0e10cSrcweir 					sMessage.SearchAndReplaceAll(String::CreateFromAscii("$name$"), sName.getStr());
260cdf0e10cSrcweir 					ErrorBox(NULL, WB_OK, sMessage).Execute();
261cdf0e10cSrcweir 					m_aParam.GrabFocus();
262cdf0e10cSrcweir 					return 1L;
263cdf0e10cSrcweir 				}
264cdf0e10cSrcweir 			}
265cdf0e10cSrcweir 		}
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 		return 0L;
268cdf0e10cSrcweir 	}
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	//------------------------------------------------------------------------------
IMPL_LINK(OParameterDialog,OnButtonClicked,PushButton *,pButton)271cdf0e10cSrcweir 	IMPL_LINK(OParameterDialog, OnButtonClicked, PushButton*, pButton)
272cdf0e10cSrcweir 	{
273cdf0e10cSrcweir 		if (&m_aCancelBtn == pButton)
274cdf0e10cSrcweir 		{
275cdf0e10cSrcweir 			// no interpreting of the given values anymore ....
276cdf0e10cSrcweir 			m_aParam.SetLoseFocusHdl(Link());	// no direct call from the control anymore ...
277cdf0e10cSrcweir 			m_bNeedErrorOnCurrent = sal_False;		// in case of any indirect calls -> no error message
278cdf0e10cSrcweir 			m_aCancelBtn.SetClickHdl(Link());
279cdf0e10cSrcweir 			m_aCancelBtn.Click();
280cdf0e10cSrcweir 		}
281cdf0e10cSrcweir 		else if (&m_aOKBtn == pButton)
282cdf0e10cSrcweir 		{
283cdf0e10cSrcweir 			// transfer the current values into the Any
284cdf0e10cSrcweir 			if (LINK(this, OParameterDialog, OnEntrySelected).Call(&m_aAllParams) != 0L)
285cdf0e10cSrcweir 			{	// there was an error interpreting the current text
286cdf0e10cSrcweir 				m_bNeedErrorOnCurrent = sal_True;
287cdf0e10cSrcweir 					// we're are out of the complex web :) of direct and indirect calls to OnValueLoseFocus now,
288cdf0e10cSrcweir 					// so the next time it is called we need an error message, again ....
289cdf0e10cSrcweir 					// (TODO : there surely are better solutions for this ...)
290cdf0e10cSrcweir 				return 1L;
291cdf0e10cSrcweir 			}
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 			if (m_xParams.is())
294cdf0e10cSrcweir 			{
295cdf0e10cSrcweir 				// write the parameters
296cdf0e10cSrcweir 				try
297cdf0e10cSrcweir 				{
298cdf0e10cSrcweir 					::rtl::OUString sError;
299cdf0e10cSrcweir 					PropertyValue* pValues = m_aFinalValues.getArray();
300cdf0e10cSrcweir 					for (sal_Int32 i = 0, nCount = m_xParams->getCount(); i<nCount; ++i, ++pValues)
301cdf0e10cSrcweir 					{
302cdf0e10cSrcweir 						Reference< XPropertySet >  xParamAsSet;
303cdf0e10cSrcweir 						m_xParams->getByIndex(i) >>= xParamAsSet;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 						::rtl::OUString sValue;
306cdf0e10cSrcweir 						pValues->Value >>= sValue;
307cdf0e10cSrcweir 						pValues->Value <<= ::rtl::OUString( m_aPredicateInput.getPredicateValue( sValue, xParamAsSet, sal_False ) );
308cdf0e10cSrcweir 					}
309cdf0e10cSrcweir 				}
310cdf0e10cSrcweir 				catch(Exception&)
311cdf0e10cSrcweir 				{
312cdf0e10cSrcweir                     DBG_UNHANDLED_EXCEPTION();
313cdf0e10cSrcweir 				}
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 			}
316cdf0e10cSrcweir 			// to close the dialog (which is more code than a simple EndDialog)
317cdf0e10cSrcweir 			m_aOKBtn.SetClickHdl(Link());
318cdf0e10cSrcweir 			m_aOKBtn.Click();
319cdf0e10cSrcweir 		}
320cdf0e10cSrcweir 		else if (&m_aTravelNext == pButton)
321cdf0e10cSrcweir 		{
322cdf0e10cSrcweir 			sal_uInt16 nCurrent = m_aAllParams.GetSelectEntryPos();
323cdf0e10cSrcweir 			sal_uInt16 nCount = m_aAllParams.GetEntryCount();
324cdf0e10cSrcweir 			DBG_ASSERT(nCount == m_aVisitedParams.size(), "OParameterDialog::OnButtonClicked : inconsistent lists !");
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 			// search the next entry in list we haven't visited yet
327cdf0e10cSrcweir 			sal_uInt16 nNext = (nCurrent + 1) % nCount;
328cdf0e10cSrcweir 			while ((nNext != nCurrent) && ( m_aVisitedParams[nNext] & EF_VISITED ))
329cdf0e10cSrcweir 				nNext = (nNext + 1) % nCount;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 			if ( m_aVisitedParams[nNext] & EF_VISITED )
332cdf0e10cSrcweir 				// there is no such "not visited yet" entry -> simpy take the next one
333cdf0e10cSrcweir 				nNext = (nCurrent + 1) % nCount;
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 			m_aAllParams.SelectEntryPos(nNext);
336cdf0e10cSrcweir 			LINK(this, OParameterDialog, OnEntrySelected).Call(&m_aAllParams);
337cdf0e10cSrcweir 			m_bNeedErrorOnCurrent = sal_True;
338cdf0e10cSrcweir 				// we're are out of the complex web :) of direct and indirect calls to OnValueLoseFocus now,
339cdf0e10cSrcweir 				// so the next time it is called we need an error message, again ....
340cdf0e10cSrcweir 				// (TODO : there surely are better solutions for this ...)
341cdf0e10cSrcweir 		}
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 		return 0L;
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	//------------------------------------------------------------------------------
347cdf0e10cSrcweir 	IMPL_LINK(OParameterDialog, OnEntrySelected, ListBox*, /*pList*/)
348cdf0e10cSrcweir 	{
349cdf0e10cSrcweir 		if (m_aResetVisitFlag.IsActive())
350cdf0e10cSrcweir 		{
351cdf0e10cSrcweir 			LINK(this, OParameterDialog, OnVisitedTimeout).Call(&m_aResetVisitFlag);
352cdf0e10cSrcweir 			m_aResetVisitFlag.Stop();
353cdf0e10cSrcweir 		}
354cdf0e10cSrcweir 		// save the old values
355cdf0e10cSrcweir 		if (m_nCurrentlySelected != LISTBOX_ENTRY_NOTFOUND)
356cdf0e10cSrcweir 		{
357cdf0e10cSrcweir 			// do the transformation of the current text
358cdf0e10cSrcweir 			if (LINK(this, OParameterDialog, OnValueLoseFocus).Call(&m_aParam) != 0L)
359cdf0e10cSrcweir 			{	// there was an error interpreting the text
360cdf0e10cSrcweir 				m_aAllParams.SelectEntryPos(m_nCurrentlySelected);
361cdf0e10cSrcweir 				return 1L;
362cdf0e10cSrcweir 			}
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 			m_aFinalValues[m_nCurrentlySelected].Value <<= ::rtl::OUString(m_aParam.GetText());
365cdf0e10cSrcweir 		}
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 		// initialize the controls with the new values
368cdf0e10cSrcweir 		sal_uInt16 nSelected = m_aAllParams.GetSelectEntryPos();
369cdf0e10cSrcweir 		DBG_ASSERT(nSelected != LISTBOX_ENTRY_NOTFOUND, "OParameterDialog::OnEntrySelected : no current entry !");
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 		m_aParam.SetText(::comphelper::getString(m_aFinalValues[nSelected].Value));
372cdf0e10cSrcweir 		m_nCurrentlySelected = nSelected;
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 		// with this the value isn't dirty
375cdf0e10cSrcweir 		DBG_ASSERT(m_nCurrentlySelected < m_aVisitedParams.size(), "OParameterDialog::OnEntrySelected : invalid current entry !");
376cdf0e10cSrcweir 		m_aVisitedParams[m_nCurrentlySelected] &= ~EF_DIRTY;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 		m_aResetVisitFlag.SetTimeout(1000);
379cdf0e10cSrcweir 		m_aResetVisitFlag.Start();
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 		return 0L;
382cdf0e10cSrcweir 	}
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	//------------------------------------------------------------------------------
385cdf0e10cSrcweir 	IMPL_LINK(OParameterDialog, OnVisitedTimeout, Timer*, /*pTimer*/)
386cdf0e10cSrcweir 	{
387cdf0e10cSrcweir 		DBG_ASSERT(m_nCurrentlySelected != LISTBOX_ENTRY_NOTFOUND, "OParameterDialog::OnVisitedTimeout : invalid call !");
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 		// mark the currently selected entry as visited
390cdf0e10cSrcweir 		DBG_ASSERT(m_nCurrentlySelected < m_aVisitedParams.size(), "OParameterDialog::OnVisitedTimeout : invalid entry !");
391cdf0e10cSrcweir 		m_aVisitedParams[m_nCurrentlySelected] |= EF_VISITED;
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 		// was it the last "not visited yet" entry ?
394cdf0e10cSrcweir 		ConstByteVectorIterator aIter;
395cdf0e10cSrcweir 		for	(	aIter = m_aVisitedParams.begin();
396cdf0e10cSrcweir 				aIter < m_aVisitedParams.end();
397cdf0e10cSrcweir 				++aIter
398cdf0e10cSrcweir 			)
399cdf0e10cSrcweir 		{
400cdf0e10cSrcweir 			if (((*aIter) & EF_VISITED) == 0)
401cdf0e10cSrcweir 				break;
402cdf0e10cSrcweir 		}
403cdf0e10cSrcweir 		if (aIter == m_aVisitedParams.end())
404cdf0e10cSrcweir 		{	// yes, there isn't another one -> change the "default button"
405cdf0e10cSrcweir 			m_aTravelNext.SetStyle(m_aTravelNext.GetStyle() & ~WB_DEFBUTTON);
406cdf0e10cSrcweir 			m_aOKBtn.SetStyle(m_aOKBtn.GetStyle() | WB_DEFBUTTON);
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 			// set to focus to one of the buttons temporary (with this their "default"-state is really updated)
409cdf0e10cSrcweir 			Window* pOldFocus = Application::GetFocusWindow();
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 			// if the old focus window is the value edit do some preparations ...
412cdf0e10cSrcweir 			Selection aSel;
413cdf0e10cSrcweir 			if (pOldFocus == &m_aParam)
414cdf0e10cSrcweir 			{
415cdf0e10cSrcweir 				m_aParam.SetLoseFocusHdl(Link());
416cdf0e10cSrcweir 				aSel = m_aParam.GetSelection();
417cdf0e10cSrcweir 			}
418cdf0e10cSrcweir 			m_aTravelNext.GrabFocus();
419cdf0e10cSrcweir 			if (pOldFocus)
420cdf0e10cSrcweir 				pOldFocus->GrabFocus();
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 			// restore the settings for the value edit
423cdf0e10cSrcweir 			if (pOldFocus == &m_aParam)
424cdf0e10cSrcweir 			{
425cdf0e10cSrcweir 				m_aParam.SetLoseFocusHdl(LINK(this, OParameterDialog, OnValueLoseFocus));
426cdf0e10cSrcweir 				m_aParam.SetSelection(aSel);
427cdf0e10cSrcweir 			}
428cdf0e10cSrcweir 		}
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 		return 0L;
431cdf0e10cSrcweir 	}
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 	//------------------------------------------------------------------------------
434cdf0e10cSrcweir 	IMPL_LINK(OParameterDialog, OnValueModified, Control*, /*pBox*/)
435cdf0e10cSrcweir 	{
436cdf0e10cSrcweir 		// mark the currently selected entry as dirty
437cdf0e10cSrcweir 		DBG_ASSERT(m_nCurrentlySelected < m_aVisitedParams.size(), "OParameterDialog::OnValueModified : invalid entry !");
438cdf0e10cSrcweir 		m_aVisitedParams[m_nCurrentlySelected] |= EF_DIRTY;
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 		m_bNeedErrorOnCurrent = sal_True;
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 		return 0L;
443cdf0e10cSrcweir 	}
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 
446cdf0e10cSrcweir //.........................................................................
447cdf0e10cSrcweir }	// namespace dbaui
448cdf0e10cSrcweir //.........................................................................
449