xref: /AOO41X/main/dbaccess/source/ui/dlg/indexdialog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef _DBAUI_INDEXDIALOG_HXX_
32*cdf0e10cSrcweir #include "indexdialog.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_
35*cdf0e10cSrcweir #include "dbu_dlg.hrc"
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
38*cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #ifndef _DBAUI_INDEXDIALOG_HRC_
41*cdf0e10cSrcweir #include "indexdialog.hrc"
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #ifndef _DBAUI_INDEXFIELDSCONTROL_HXX_
44*cdf0e10cSrcweir #include "indexfieldscontrol.hxx"
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #ifndef _DBAUI_INDEXCOLLECTION_HXX_
47*cdf0e10cSrcweir #include "indexcollection.hxx"
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
50*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
53*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
56*cdf0e10cSrcweir #include "UITools.hxx"
57*cdf0e10cSrcweir #endif
58*cdf0e10cSrcweir #ifndef _SVTOOLS_IMGDEF_HXX
59*cdf0e10cSrcweir #include <svtools/imgdef.hxx>
60*cdf0e10cSrcweir #endif
61*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
62*cdf0e10cSrcweir #include "browserids.hxx"
63*cdf0e10cSrcweir #endif
64*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
65*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
66*cdf0e10cSrcweir #endif
67*cdf0e10cSrcweir //......................................................................
68*cdf0e10cSrcweir namespace dbaui
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir //......................................................................
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
73*cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
74*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
75*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
76*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
77*cdf0e10cSrcweir 	using namespace ::dbtools;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	//==================================================================
80*cdf0e10cSrcweir 	//= helper
81*cdf0e10cSrcweir 	//==================================================================
82*cdf0e10cSrcweir 	//------------------------------------------------------------------
83*cdf0e10cSrcweir 	sal_Bool operator ==(const OIndexField& _rLHS, const OIndexField& _rRHS)
84*cdf0e10cSrcweir 	{
85*cdf0e10cSrcweir 		return	(_rLHS.sFieldName == _rRHS.sFieldName)
86*cdf0e10cSrcweir 			&&	(_rLHS.bSortAscending == _rRHS.bSortAscending);
87*cdf0e10cSrcweir 	}
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	//------------------------------------------------------------------
90*cdf0e10cSrcweir 	sal_Bool operator !=(const OIndexField& _rLHS, const OIndexField& _rRHS)
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 		return !(_rLHS == _rRHS);
93*cdf0e10cSrcweir 	}
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	//------------------------------------------------------------------
96*cdf0e10cSrcweir 	sal_Bool operator ==(const IndexFields& _rLHS, const IndexFields& _rRHS)
97*cdf0e10cSrcweir 	{
98*cdf0e10cSrcweir 		if (_rLHS.size() != _rRHS.size())
99*cdf0e10cSrcweir 			return sal_False;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 		ConstIndexFieldsIterator aLeft = _rLHS.begin();
102*cdf0e10cSrcweir         ConstIndexFieldsIterator aLeftEnd = _rLHS.end();
103*cdf0e10cSrcweir 		ConstIndexFieldsIterator aRight = _rRHS.begin();
104*cdf0e10cSrcweir 		for	(; aLeft != aLeftEnd; ++aLeft, ++aRight)
105*cdf0e10cSrcweir 		{
106*cdf0e10cSrcweir 			if (*aLeft != *aRight)
107*cdf0e10cSrcweir 				return sal_False;
108*cdf0e10cSrcweir 		}
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 		return sal_True;
111*cdf0e10cSrcweir 	}
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	//------------------------------------------------------------------
114*cdf0e10cSrcweir 	sal_Bool operator !=(const IndexFields& _rLHS, const IndexFields& _rRHS)
115*cdf0e10cSrcweir 	{
116*cdf0e10cSrcweir 		return !(_rLHS == _rRHS);
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	//==================================================================
120*cdf0e10cSrcweir 	//= DbaIndexList
121*cdf0e10cSrcweir 	//==================================================================
122*cdf0e10cSrcweir 	//------------------------------------------------------------------
123*cdf0e10cSrcweir 	DbaIndexList::DbaIndexList(Window* _pParent, const ResId& _rId)
124*cdf0e10cSrcweir 		:SvTreeListBox(_pParent, _rId)
125*cdf0e10cSrcweir 		,m_bSuspendSelectHdl(sal_False)
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir 	}
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	extern sal_Bool isCharOk(sal_Unicode _cChar,sal_Bool _bFirstChar,sal_Bool _bUpperCase,const ::rtl::OUString& _sAllowedChars);
130*cdf0e10cSrcweir 	//------------------------------------------------------------------
131*cdf0e10cSrcweir 	sal_Bool DbaIndexList::EditedEntry( SvLBoxEntry* _pEntry, const String& _rNewText )
132*cdf0e10cSrcweir 	{
133*cdf0e10cSrcweir 		// first check if this is valid SQL92 name
134*cdf0e10cSrcweir 		if ( isSQL92CheckEnabled(m_xConnection) )
135*cdf0e10cSrcweir 		{
136*cdf0e10cSrcweir 			Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
137*cdf0e10cSrcweir 			if ( xMeta.is() )
138*cdf0e10cSrcweir 			{
139*cdf0e10cSrcweir 				::rtl::OUString sNewName(_rNewText);
140*cdf0e10cSrcweir 				::rtl::OUString sAlias = ::dbtools::convertName2SQLName(sNewName,xMeta->getExtraNameCharacters());
141*cdf0e10cSrcweir 				if ( ( xMeta->supportsMixedCaseQuotedIdentifiers() )
142*cdf0e10cSrcweir 						?
143*cdf0e10cSrcweir 						sAlias != sNewName
144*cdf0e10cSrcweir 						:
145*cdf0e10cSrcweir 				!sNewName.equalsIgnoreAsciiCase(sAlias))
146*cdf0e10cSrcweir 					return sal_False;
147*cdf0e10cSrcweir 			}
148*cdf0e10cSrcweir 		}
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 		if (!SvTreeListBox::EditedEntry(_pEntry, _rNewText))
151*cdf0e10cSrcweir 			return sal_False;
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 		String sOldText = GetEntryText(_pEntry);
154*cdf0e10cSrcweir 		SvTreeListBox::SetEntryText(_pEntry, _rNewText);
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 		sal_Bool bValid = sal_True;
157*cdf0e10cSrcweir 		if (m_aEndEditHdl.IsSet())
158*cdf0e10cSrcweir 			bValid = (0 != m_aEndEditHdl.Call(_pEntry));
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 		if (bValid)
161*cdf0e10cSrcweir 			return sal_True;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 		SvTreeListBox::SetEntryText(_pEntry, sOldText);
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 		return sal_False;
166*cdf0e10cSrcweir 	}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	//------------------------------------------------------------------
169*cdf0e10cSrcweir 	void DbaIndexList::enableSelectHandler()
170*cdf0e10cSrcweir 	{
171*cdf0e10cSrcweir 		DBG_ASSERT(m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!");
172*cdf0e10cSrcweir 		m_bSuspendSelectHdl = sal_False;
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	//------------------------------------------------------------------
176*cdf0e10cSrcweir 	void DbaIndexList::disableSelectHandler()
177*cdf0e10cSrcweir 	{
178*cdf0e10cSrcweir 		DBG_ASSERT(!m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!");
179*cdf0e10cSrcweir 		m_bSuspendSelectHdl = sal_True;
180*cdf0e10cSrcweir 	}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	//------------------------------------------------------------------
183*cdf0e10cSrcweir 	void DbaIndexList::SelectNoHandlerCall( SvLBoxEntry* _pEntry )
184*cdf0e10cSrcweir 	{
185*cdf0e10cSrcweir 		disableSelectHandler();
186*cdf0e10cSrcweir 		Select(_pEntry, sal_True);
187*cdf0e10cSrcweir 		enableSelectHandler();
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	//------------------------------------------------------------------
191*cdf0e10cSrcweir 	sal_Bool DbaIndexList::Select( SvLBoxEntry* pEntry, sal_Bool _bSelect )
192*cdf0e10cSrcweir 	{
193*cdf0e10cSrcweir 		sal_Bool bReturn = SvTreeListBox::Select(pEntry, _bSelect);
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 		if (m_aSelectHdl.IsSet() && !m_bSuspendSelectHdl && _bSelect)
196*cdf0e10cSrcweir 			m_aSelectHdl.Call(this);
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 		return bReturn;
199*cdf0e10cSrcweir 	}
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	//==================================================================
202*cdf0e10cSrcweir 	//= DbaIndexDialog
203*cdf0e10cSrcweir 	//==================================================================
204*cdf0e10cSrcweir DBG_NAME(DbaIndexDialog)
205*cdf0e10cSrcweir //------------------------------------------------------------------
206*cdf0e10cSrcweir 	DbaIndexDialog::DbaIndexDialog(	Window* _pParent, const Sequence< ::rtl::OUString >& _rFieldNames,
207*cdf0e10cSrcweir 									const Reference< XNameAccess >& _rxIndexes,
208*cdf0e10cSrcweir 									const Reference< XConnection >& _rxConnection,
209*cdf0e10cSrcweir 									const Reference< XMultiServiceFactory >& _rxORB,sal_Int32 _nMaxColumnsInIndex)
210*cdf0e10cSrcweir 		:ModalDialog( _pParent, ModuleRes(DLG_INDEXDESIGN))
211*cdf0e10cSrcweir 		,m_xConnection(_rxConnection)
212*cdf0e10cSrcweir 		,m_aGeometrySettings(E_DIALOG, ::rtl::OUString::createFromAscii("dbaccess.tabledesign.indexdialog"))
213*cdf0e10cSrcweir 		,m_aActions							(this, ModuleRes(TLB_ACTIONS))
214*cdf0e10cSrcweir 		,m_aIndexes							(this, ModuleRes(CTR_INDEXLIST))
215*cdf0e10cSrcweir 		,m_aIndexDetails					(this, ModuleRes(FL_INDEXDETAILS))
216*cdf0e10cSrcweir 		,m_aDescriptionLabel				(this, ModuleRes(FT_DESC_LABEL))
217*cdf0e10cSrcweir 		,m_aDescription						(this, ModuleRes(FT_DESCRIPTION))
218*cdf0e10cSrcweir 		,m_aUnique							(this, ModuleRes(CB_UNIQUE))
219*cdf0e10cSrcweir 		,m_aFieldsLabel						(this, ModuleRes(FT_FIELDS))
220*cdf0e10cSrcweir 		,m_pFields(new IndexFieldsControl	(this, ModuleRes(CTR_FIELDS),_nMaxColumnsInIndex,::dbtools::getBooleanDataSourceSetting( m_xConnection, "AddIndexAppendix" )))
221*cdf0e10cSrcweir 		,m_aClose							(this, ModuleRes(PB_CLOSE))
222*cdf0e10cSrcweir 		,m_aHelp							(this, ModuleRes(HB_HELP))
223*cdf0e10cSrcweir 		,m_pIndexes(NULL)
224*cdf0e10cSrcweir 		,m_pPreviousSelection(NULL)
225*cdf0e10cSrcweir 		,m_bEditAgain(sal_False)
226*cdf0e10cSrcweir 		,m_xORB(_rxORB)
227*cdf0e10cSrcweir 	{
228*cdf0e10cSrcweir         DBG_CTOR(DbaIndexDialog,NULL);
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 		FreeResource();
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 		m_aActions.SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexAction));
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 		m_aIndexes.SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexSelected));
235*cdf0e10cSrcweir 		m_aIndexes.SetEndEditHdl(LINK(this, DbaIndexDialog, OnEntryEdited));
236*cdf0e10cSrcweir 		m_aIndexes.SetSelectionMode(SINGLE_SELECTION);
237*cdf0e10cSrcweir 		m_aIndexes.SetHighlightRange();
238*cdf0e10cSrcweir 		m_aIndexes.setConnection(m_xConnection);
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 		m_pFields->Init(_rFieldNames);
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 		setToolBox(&m_aActions);
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 		m_pIndexes = new OIndexCollection();
245*cdf0e10cSrcweir 		try
246*cdf0e10cSrcweir 		{
247*cdf0e10cSrcweir 			m_pIndexes->attach(_rxIndexes);
248*cdf0e10cSrcweir 		}
249*cdf0e10cSrcweir 		catch(SQLException& e)
250*cdf0e10cSrcweir 		{
251*cdf0e10cSrcweir 			::dbaui::showError(SQLExceptionInfo(e),_pParent,_rxORB);
252*cdf0e10cSrcweir 		}
253*cdf0e10cSrcweir 		catch(Exception&)
254*cdf0e10cSrcweir 		{
255*cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "DbaIndexDialog::DbaIndexDialog: could not retrieve basic information from the UNO collection!");
256*cdf0e10cSrcweir 		}
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 		fillIndexList();
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 		m_aUnique.SetClickHdl(LINK(this, DbaIndexDialog, OnModified));
261*cdf0e10cSrcweir 		m_pFields->SetModifyHdl(LINK(this, DbaIndexDialog, OnModified));
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 		m_aClose.SetClickHdl(LINK(this, DbaIndexDialog, OnCloseDialog));
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 		// get our most recent geometry settings
266*cdf0e10cSrcweir //		if (m_aGeometrySettings.Exists())
267*cdf0e10cSrcweir //		{
268*cdf0e10cSrcweir //			Point aPos;
269*cdf0e10cSrcweir //			m_aGeometrySettings.GetPosition(aPos.X(), aPos.Y());
270*cdf0e10cSrcweir //			SetPosPixel(aPos);
271*cdf0e10cSrcweir //		}
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 		// if all of the indexes have an empty description, we're not interested in displaying it
274*cdf0e10cSrcweir 		Indexes::const_iterator aCheck;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 		for (	aCheck = m_pIndexes->begin();
277*cdf0e10cSrcweir 				aCheck != m_pIndexes->end();
278*cdf0e10cSrcweir 				++aCheck
279*cdf0e10cSrcweir 			)
280*cdf0e10cSrcweir 		{
281*cdf0e10cSrcweir 			if (aCheck->sDescription.getLength())
282*cdf0e10cSrcweir 				break;
283*cdf0e10cSrcweir 		}
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 		if (aCheck == m_pIndexes->end())
286*cdf0e10cSrcweir 		{
287*cdf0e10cSrcweir 			sal_Int32 nMoveUp = m_aUnique.GetPosPixel().Y() - m_aDescriptionLabel.GetPosPixel().Y();
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 			// hide the controls which are necessary for the description
290*cdf0e10cSrcweir 			m_aDescription.Hide();
291*cdf0e10cSrcweir 			m_aDescriptionLabel.Hide();
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 			// move other controls up
294*cdf0e10cSrcweir 			Point aPos = m_aUnique.GetPosPixel();
295*cdf0e10cSrcweir 			aPos.Y() -= nMoveUp;
296*cdf0e10cSrcweir 			m_aUnique.SetPosPixel(aPos);
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 			aPos = m_aFieldsLabel.GetPosPixel();
299*cdf0e10cSrcweir 			aPos.Y() -= nMoveUp;
300*cdf0e10cSrcweir 			m_aFieldsLabel.SetPosPixel(aPos);
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 			aPos = m_pFields->GetPosPixel();
303*cdf0e10cSrcweir 			aPos.Y() -= nMoveUp;
304*cdf0e10cSrcweir 			m_pFields->SetPosPixel(aPos);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 			// and enlarge the fields list
307*cdf0e10cSrcweir 			Size aSize = m_pFields->GetSizePixel();
308*cdf0e10cSrcweir 			aSize.Height() += nMoveUp;
309*cdf0e10cSrcweir 			m_pFields->SetSizePixel(aSize);
310*cdf0e10cSrcweir 		}
311*cdf0e10cSrcweir 	}
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 	//------------------------------------------------------------------
314*cdf0e10cSrcweir 	void DbaIndexDialog::updateToolbox()
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		m_aActions.EnableItem(ID_INDEX_NEW, !m_aIndexes.IsEditingActive());
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 		SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
319*cdf0e10cSrcweir 		sal_Bool bSelectedAnything = NULL != pSelected;
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 		if (pSelected)
323*cdf0e10cSrcweir 		{
324*cdf0e10cSrcweir 			// is the current entry modified?
325*cdf0e10cSrcweir 			Indexes::const_iterator aSelectedPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
326*cdf0e10cSrcweir 			m_aActions.EnableItem(ID_INDEX_SAVE, aSelectedPos->isModified() || aSelectedPos->isNew());
327*cdf0e10cSrcweir 			m_aActions.EnableItem(ID_INDEX_RESET, aSelectedPos->isModified() || aSelectedPos->isNew());
328*cdf0e10cSrcweir             bSelectedAnything = bSelectedAnything && !aSelectedPos->bPrimaryKey;
329*cdf0e10cSrcweir 		}
330*cdf0e10cSrcweir 		else
331*cdf0e10cSrcweir 		{
332*cdf0e10cSrcweir 			m_aActions.EnableItem(ID_INDEX_SAVE, sal_False);
333*cdf0e10cSrcweir 			m_aActions.EnableItem(ID_INDEX_RESET, sal_False);
334*cdf0e10cSrcweir 		}
335*cdf0e10cSrcweir         m_aActions.EnableItem(ID_INDEX_DROP, bSelectedAnything);
336*cdf0e10cSrcweir 		m_aActions.EnableItem(ID_INDEX_RENAME, bSelectedAnything);
337*cdf0e10cSrcweir 	}
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	//------------------------------------------------------------------
340*cdf0e10cSrcweir 	void DbaIndexDialog::fillIndexList()
341*cdf0e10cSrcweir 	{
342*cdf0e10cSrcweir 		sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
343*cdf0e10cSrcweir 		Image aPKeyIcon(ModuleRes( bHiContrast ? IMG_PKEYICON_SCH : IMG_PKEYICON));
344*cdf0e10cSrcweir 		// fill the list with the index names
345*cdf0e10cSrcweir 		m_aIndexes.Clear();
346*cdf0e10cSrcweir 		Indexes::iterator aIndexLoop = m_pIndexes->begin();
347*cdf0e10cSrcweir 		Indexes::iterator aEnd = m_pIndexes->end();
348*cdf0e10cSrcweir 		for (; aIndexLoop != aEnd; ++aIndexLoop)
349*cdf0e10cSrcweir 		{
350*cdf0e10cSrcweir 			SvLBoxEntry* pNewEntry = NULL;
351*cdf0e10cSrcweir 			if (aIndexLoop->bPrimaryKey)
352*cdf0e10cSrcweir 				pNewEntry = m_aIndexes.InsertEntry(aIndexLoop->sName, aPKeyIcon, aPKeyIcon);
353*cdf0e10cSrcweir 			else
354*cdf0e10cSrcweir 				pNewEntry = m_aIndexes.InsertEntry(aIndexLoop->sName);
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir 			pNewEntry->SetUserData(reinterpret_cast< void* >(sal_Int32(aIndexLoop - m_pIndexes->begin())));
357*cdf0e10cSrcweir 		}
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 		OnIndexSelected(&m_aIndexes);
360*cdf0e10cSrcweir 	}
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 	//------------------------------------------------------------------
363*cdf0e10cSrcweir 	DbaIndexDialog::~DbaIndexDialog( )
364*cdf0e10cSrcweir 	{
365*cdf0e10cSrcweir 		setToolBox(NULL);
366*cdf0e10cSrcweir 		delete m_pIndexes;
367*cdf0e10cSrcweir 		delete m_pFields;
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 		// save our geometry settings
370*cdf0e10cSrcweir //		Point aPos = GetPosPixel();
371*cdf0e10cSrcweir //		m_aGeometrySettings.SetPosition(aPos.X(), aPos.Y());
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir         DBG_DTOR(DbaIndexDialog,NULL);
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 	//------------------------------------------------------------------
377*cdf0e10cSrcweir 	sal_Bool DbaIndexDialog::implCommit(SvLBoxEntry* _pEntry)
378*cdf0e10cSrcweir 	{
379*cdf0e10cSrcweir 		DBG_ASSERT(_pEntry, "DbaIndexDialog::implCommit: invalid entry!");
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 		Indexes::iterator aCommitPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 		// if it's not a new index, remove it
384*cdf0e10cSrcweir 		// (we can't modify indexes, only drop'n'insert)
385*cdf0e10cSrcweir 		if (!aCommitPos->isNew())
386*cdf0e10cSrcweir 			if (!implDropIndex(_pEntry, sal_False))
387*cdf0e10cSrcweir 				return sal_False;
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 		// create the new index
390*cdf0e10cSrcweir 		SQLExceptionInfo aExceptionInfo;
391*cdf0e10cSrcweir 		try
392*cdf0e10cSrcweir 		{
393*cdf0e10cSrcweir 			m_pIndexes->commitNewIndex(aCommitPos);
394*cdf0e10cSrcweir 		}
395*cdf0e10cSrcweir 		catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
396*cdf0e10cSrcweir 		catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
397*cdf0e10cSrcweir 		catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 		// reflect the new selection in the toolbox
400*cdf0e10cSrcweir 		updateToolbox();
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 		if (aExceptionInfo.isValid())
403*cdf0e10cSrcweir 			showError(aExceptionInfo, this, m_xORB);
404*cdf0e10cSrcweir 		else
405*cdf0e10cSrcweir 		{
406*cdf0e10cSrcweir 			m_aUnique.SaveValue();
407*cdf0e10cSrcweir 			m_pFields->SaveValue();
408*cdf0e10cSrcweir 		}
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 		return !aExceptionInfo.isValid();
411*cdf0e10cSrcweir 	}
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	//------------------------------------------------------------------
414*cdf0e10cSrcweir 	void DbaIndexDialog::OnNewIndex()
415*cdf0e10cSrcweir 	{
416*cdf0e10cSrcweir 		// commit the current entry, if necessary
417*cdf0e10cSrcweir 		if (!implCommitPreviouslySelected())
418*cdf0e10cSrcweir 			return;
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 		// get a new unique name for the new index
421*cdf0e10cSrcweir 		String sNewIndexName;
422*cdf0e10cSrcweir 		const String sNewIndexNameBase(ModuleRes(STR_LOGICAL_INDEX_NAME));
423*cdf0e10cSrcweir 		sal_Int32 i;
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 		for ( i = 1; i < 0x7FFFFFFF; ++i )
426*cdf0e10cSrcweir 		{
427*cdf0e10cSrcweir 			sNewIndexName = sNewIndexNameBase;
428*cdf0e10cSrcweir 			sNewIndexName += String::CreateFromInt32(i);
429*cdf0e10cSrcweir 			if (m_pIndexes->end() == m_pIndexes->find(sNewIndexName))
430*cdf0e10cSrcweir 				break;
431*cdf0e10cSrcweir 		}
432*cdf0e10cSrcweir 		if ((i>0x7FFFFFFF) || (i<0))
433*cdf0e10cSrcweir 		{
434*cdf0e10cSrcweir 			DBG_ERROR("DbaIndexDialog::OnNewIndex: no free index name found!");
435*cdf0e10cSrcweir 			// can't do anything ... of course we try another base, but this could end with the same result ...
436*cdf0e10cSrcweir 			return;
437*cdf0e10cSrcweir 		}
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 		SvLBoxEntry* pNewEntry = m_aIndexes.InsertEntry(sNewIndexName);
440*cdf0e10cSrcweir 		m_pIndexes->insert(sNewIndexName);
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 		// update the user data on the entries in the list box:
443*cdf0e10cSrcweir 		// they're iterators of the index collection, and thus they have changed when removing the index
444*cdf0e10cSrcweir 		for (SvLBoxEntry* pAdjust = m_aIndexes.First(); pAdjust; pAdjust = m_aIndexes.Next(pAdjust))
445*cdf0e10cSrcweir 		{
446*cdf0e10cSrcweir 			Indexes::iterator aAfterInsertPos = m_pIndexes->find(m_aIndexes.GetEntryText(pAdjust));
447*cdf0e10cSrcweir 			DBG_ASSERT(aAfterInsertPos != m_pIndexes->end(), "DbaIndexDialog::OnNewIndex: problems with on of the entries!");
448*cdf0e10cSrcweir 			pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterInsertPos - m_pIndexes->begin())));
449*cdf0e10cSrcweir 		}
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 		// select the entry and start in-place editing
452*cdf0e10cSrcweir 		m_aIndexes.SelectNoHandlerCall(pNewEntry);
453*cdf0e10cSrcweir 		OnIndexSelected(&m_aIndexes);
454*cdf0e10cSrcweir 		m_aIndexes.EditEntry(pNewEntry);
455*cdf0e10cSrcweir 		updateToolbox();
456*cdf0e10cSrcweir 	}
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 	//------------------------------------------------------------------
459*cdf0e10cSrcweir 	void DbaIndexDialog::OnDropIndex(sal_Bool _bConfirm)
460*cdf0e10cSrcweir 	{
461*cdf0e10cSrcweir 		// the selected index
462*cdf0e10cSrcweir 		SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
463*cdf0e10cSrcweir 		DBG_ASSERT(pSelected, "DbaIndexDialog::OnDropIndex: invalid call!");
464*cdf0e10cSrcweir 		if (pSelected)
465*cdf0e10cSrcweir 		{
466*cdf0e10cSrcweir 			// let the user confirm the drop
467*cdf0e10cSrcweir 			if (_bConfirm)
468*cdf0e10cSrcweir 			{
469*cdf0e10cSrcweir 				String sConfirm(ModuleRes(STR_CONFIRM_DROP_INDEX));
470*cdf0e10cSrcweir 				sConfirm.SearchAndReplaceAscii("$name$", m_aIndexes.GetEntryText(pSelected));
471*cdf0e10cSrcweir 				QueryBox aConfirm(this, WB_YES_NO, sConfirm);
472*cdf0e10cSrcweir 				if (RET_YES != aConfirm.Execute())
473*cdf0e10cSrcweir 					return;
474*cdf0e10cSrcweir 			}
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 			// do the drop
477*cdf0e10cSrcweir 			implDropIndex(pSelected, sal_True);
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 			// reflect the new selection in the toolbox
480*cdf0e10cSrcweir 			updateToolbox();
481*cdf0e10cSrcweir 		}
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	//------------------------------------------------------------------
485*cdf0e10cSrcweir 	sal_Bool DbaIndexDialog::implDropIndex(SvLBoxEntry* _pEntry, sal_Bool _bRemoveFromCollection)
486*cdf0e10cSrcweir 	{
487*cdf0e10cSrcweir 		// do the drop
488*cdf0e10cSrcweir 		Indexes::iterator aDropPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
489*cdf0e10cSrcweir 		DBG_ASSERT(aDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: did not find the index in my collection!");
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir 		SQLExceptionInfo aExceptionInfo;
492*cdf0e10cSrcweir 		sal_Bool bSuccess = sal_False;
493*cdf0e10cSrcweir 		try
494*cdf0e10cSrcweir 		{
495*cdf0e10cSrcweir 			if (_bRemoveFromCollection)
496*cdf0e10cSrcweir 				bSuccess = m_pIndexes->drop(aDropPos);
497*cdf0e10cSrcweir 			else
498*cdf0e10cSrcweir 				bSuccess = m_pIndexes->dropNoRemove(aDropPos);
499*cdf0e10cSrcweir 		}
500*cdf0e10cSrcweir 		catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
501*cdf0e10cSrcweir 		catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
502*cdf0e10cSrcweir 		catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 		if (aExceptionInfo.isValid())
505*cdf0e10cSrcweir 			showError(aExceptionInfo, this, m_xORB);
506*cdf0e10cSrcweir 		else if (bSuccess && _bRemoveFromCollection)
507*cdf0e10cSrcweir 		{
508*cdf0e10cSrcweir 			SvLBoxTreeList* pModel = m_aIndexes.GetModel();
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir 			m_aIndexes.disableSelectHandler();
511*cdf0e10cSrcweir 			pModel->Remove(_pEntry);
512*cdf0e10cSrcweir 			m_aIndexes.enableSelectHandler();
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir 			// update the user data on the entries in the list box:
515*cdf0e10cSrcweir 			// they're iterators of the index collection, and thus they have changed when removing the index
516*cdf0e10cSrcweir 			for (SvLBoxEntry* pAdjust = m_aIndexes.First(); pAdjust; pAdjust = m_aIndexes.Next(pAdjust))
517*cdf0e10cSrcweir 			{
518*cdf0e10cSrcweir 				Indexes::iterator aAfterDropPos = m_pIndexes->find(m_aIndexes.GetEntryText(pAdjust));
519*cdf0e10cSrcweir 				DBG_ASSERT(aAfterDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: problems with on of the remaining entries!");
520*cdf0e10cSrcweir 				pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterDropPos - m_pIndexes->begin())));
521*cdf0e10cSrcweir 			}
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 			// if the remvoved entry was the selected on ...
524*cdf0e10cSrcweir 			if (m_pPreviousSelection == _pEntry)
525*cdf0e10cSrcweir 				m_pPreviousSelection = NULL;
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 			// the Remove automatically selected another entry (if possible), but we disabled the calling of the handler
528*cdf0e10cSrcweir 			// to prevent that we missed something ... call the handler directly
529*cdf0e10cSrcweir 			OnIndexSelected(&m_aIndexes);
530*cdf0e10cSrcweir 		}
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 		return !aExceptionInfo.isValid();
533*cdf0e10cSrcweir 	}
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 	//------------------------------------------------------------------
536*cdf0e10cSrcweir 	void DbaIndexDialog::OnRenameIndex()
537*cdf0e10cSrcweir 	{
538*cdf0e10cSrcweir 		// the selected index
539*cdf0e10cSrcweir 		SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
540*cdf0e10cSrcweir 		DBG_ASSERT(pSelected, "DbaIndexDialog::OnRenameIndex: invalid call!");
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 		// save the changes made 'til here
543*cdf0e10cSrcweir 		// Upon leaving the edit mode, the control will be re-initialized with the
544*cdf0e10cSrcweir 		// settings from the current entry
545*cdf0e10cSrcweir 		implSaveModified(sal_False);
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 		m_aIndexes.EditEntry(pSelected);
548*cdf0e10cSrcweir 		updateToolbox();
549*cdf0e10cSrcweir 	}
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir 	//------------------------------------------------------------------
552*cdf0e10cSrcweir 	void DbaIndexDialog::OnSaveIndex()
553*cdf0e10cSrcweir 	{
554*cdf0e10cSrcweir 		// the selected index
555*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
556*cdf0e10cSrcweir 		SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
557*cdf0e10cSrcweir 		OSL_ENSURE( pSelected, "DbaIndexDialog::OnSaveIndex: invalid call!" );
558*cdf0e10cSrcweir #endif
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 		implCommitPreviouslySelected();
561*cdf0e10cSrcweir 		updateToolbox();
562*cdf0e10cSrcweir 	}
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 	//------------------------------------------------------------------
565*cdf0e10cSrcweir 	void DbaIndexDialog::OnResetIndex()
566*cdf0e10cSrcweir 	{
567*cdf0e10cSrcweir 		// the selected index
568*cdf0e10cSrcweir 		SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
569*cdf0e10cSrcweir 		DBG_ASSERT(pSelected, "DbaIndexDialog::OnResetIndex: invalid call!");
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 		Indexes::iterator aResetPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 		if (aResetPos->isNew())
574*cdf0e10cSrcweir 		{
575*cdf0e10cSrcweir 			OnDropIndex(sal_False);
576*cdf0e10cSrcweir 			return;
577*cdf0e10cSrcweir 		}
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 		SQLExceptionInfo aExceptionInfo;
580*cdf0e10cSrcweir 		try
581*cdf0e10cSrcweir 		{
582*cdf0e10cSrcweir 			m_pIndexes->resetIndex(aResetPos);
583*cdf0e10cSrcweir 		}
584*cdf0e10cSrcweir 		catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
585*cdf0e10cSrcweir 		catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
586*cdf0e10cSrcweir 		catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 		if (aExceptionInfo.isValid())
589*cdf0e10cSrcweir 			showError(aExceptionInfo, this, m_xORB);
590*cdf0e10cSrcweir 		else
591*cdf0e10cSrcweir 			m_aIndexes.SetEntryText(pSelected, aResetPos->sName);
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir 		updateControls(pSelected);
594*cdf0e10cSrcweir 		updateToolbox();
595*cdf0e10cSrcweir 	}
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 	//------------------------------------------------------------------
598*cdf0e10cSrcweir 	IMPL_LINK( DbaIndexDialog, OnIndexAction, ToolBox*, /*NOTINTERESTEDIN*/ )
599*cdf0e10cSrcweir 	{
600*cdf0e10cSrcweir 		sal_uInt16 nClicked = m_aActions.GetCurItemId();
601*cdf0e10cSrcweir 		switch (nClicked)
602*cdf0e10cSrcweir 		{
603*cdf0e10cSrcweir 			case ID_INDEX_NEW:
604*cdf0e10cSrcweir 				OnNewIndex();
605*cdf0e10cSrcweir 				break;
606*cdf0e10cSrcweir 			case ID_INDEX_DROP:
607*cdf0e10cSrcweir 				OnDropIndex();
608*cdf0e10cSrcweir 				break;
609*cdf0e10cSrcweir 			case ID_INDEX_RENAME:
610*cdf0e10cSrcweir 				OnRenameIndex();
611*cdf0e10cSrcweir 				break;
612*cdf0e10cSrcweir 			case ID_INDEX_SAVE:
613*cdf0e10cSrcweir 				OnSaveIndex();
614*cdf0e10cSrcweir 				break;
615*cdf0e10cSrcweir 			case ID_INDEX_RESET:
616*cdf0e10cSrcweir 				OnResetIndex();
617*cdf0e10cSrcweir 				break;
618*cdf0e10cSrcweir 		}
619*cdf0e10cSrcweir 		return 0L;
620*cdf0e10cSrcweir 	}
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 	//------------------------------------------------------------------
623*cdf0e10cSrcweir 	IMPL_LINK( DbaIndexDialog, OnCloseDialog, void*, /*NOTINTERESTEDIN*/ )
624*cdf0e10cSrcweir 	{
625*cdf0e10cSrcweir 		if (m_aIndexes.IsEditingActive())
626*cdf0e10cSrcweir 		{
627*cdf0e10cSrcweir 			DBG_ASSERT(!m_bEditAgain, "DbaIndexDialog::OnCloseDialog: somebody was faster than hell!");
628*cdf0e10cSrcweir 				// this means somebody entered a new name, which was invalid, which cause us to posted us an event,
629*cdf0e10cSrcweir 				// and before the event arrived the user clicked onto "close". VERY fast, this user ....
630*cdf0e10cSrcweir 			m_aIndexes.EndEditing(sal_False);
631*cdf0e10cSrcweir 			if (m_bEditAgain)
632*cdf0e10cSrcweir 				// could not commit the new name (started a new - asynchronous - edit trial)
633*cdf0e10cSrcweir 				return 1L;
634*cdf0e10cSrcweir 		}
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir 		// the currently selected entry
637*cdf0e10cSrcweir 		const SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
638*cdf0e10cSrcweir 		DBG_ASSERT(pSelected == m_pPreviousSelection, "DbaIndexDialog::OnCloseDialog: inconsistence!");
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir 		sal_Int32 nResponse = RET_NO;
641*cdf0e10cSrcweir 		if (pSelected)
642*cdf0e10cSrcweir 		{
643*cdf0e10cSrcweir 			// the descriptor
644*cdf0e10cSrcweir 			Indexes::const_iterator aSelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 			if (aSelected->isModified() || aSelected->isNew())
647*cdf0e10cSrcweir 			{
648*cdf0e10cSrcweir 				QueryBox aQuestion(this, ModuleRes(QUERY_SAVE_CURRENT_INDEX));
649*cdf0e10cSrcweir 				nResponse = aQuestion.Execute();
650*cdf0e10cSrcweir 			}
651*cdf0e10cSrcweir 		}
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 		switch (nResponse)
654*cdf0e10cSrcweir 		{
655*cdf0e10cSrcweir 			case RET_YES:
656*cdf0e10cSrcweir 				if (!implCommitPreviouslySelected())
657*cdf0e10cSrcweir 					return 1L;
658*cdf0e10cSrcweir 				break;
659*cdf0e10cSrcweir 			case RET_NO:
660*cdf0e10cSrcweir 				break;
661*cdf0e10cSrcweir 			default:
662*cdf0e10cSrcweir 				return 1L;
663*cdf0e10cSrcweir 		}
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir 		EndDialog(RET_OK);
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir 		return 0L;
668*cdf0e10cSrcweir 	}
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir 	//------------------------------------------------------------------
671*cdf0e10cSrcweir 	IMPL_LINK( DbaIndexDialog, OnEditIndexAgain, SvLBoxEntry*, _pEntry )
672*cdf0e10cSrcweir 	{
673*cdf0e10cSrcweir 		m_bEditAgain = sal_False;
674*cdf0e10cSrcweir 		m_aIndexes.EditEntry(_pEntry);
675*cdf0e10cSrcweir 		return 0L;
676*cdf0e10cSrcweir 	}
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir 	//------------------------------------------------------------------
679*cdf0e10cSrcweir 	IMPL_LINK( DbaIndexDialog, OnEntryEdited, SvLBoxEntry*, _pEntry )
680*cdf0e10cSrcweir 	{
681*cdf0e10cSrcweir 		Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir 		DBG_ASSERT(aPosition >= m_pIndexes->begin() && aPosition < m_pIndexes->end(),
684*cdf0e10cSrcweir 			"DbaIndexDialog::OnEntryEdited: invalid entry!");
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir 		String sNewName = m_aIndexes.GetEntryText(_pEntry);
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 		Indexes::const_iterator aSameName = m_pIndexes->find(sNewName);
689*cdf0e10cSrcweir 		if ((aSameName != aPosition) && (m_pIndexes->end() != aSameName))
690*cdf0e10cSrcweir 		{
691*cdf0e10cSrcweir 			String sError(ModuleRes(STR_INDEX_NAME_ALREADY_USED));
692*cdf0e10cSrcweir 			sError.SearchAndReplaceAscii("$name$", sNewName);
693*cdf0e10cSrcweir 			ErrorBox aError(this, WB_OK, sError);
694*cdf0e10cSrcweir 			aError.Execute();
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir 			updateToolbox();
697*cdf0e10cSrcweir 			m_bEditAgain = sal_True;
698*cdf0e10cSrcweir 			PostUserEvent(LINK(this, DbaIndexDialog, OnEditIndexAgain), _pEntry);
699*cdf0e10cSrcweir 			return 0L;
700*cdf0e10cSrcweir 		}
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 		aPosition->sName = sNewName;
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir 		// rename can be done by a drop/insert combination only
705*cdf0e10cSrcweir 		if (aPosition->isNew())
706*cdf0e10cSrcweir 		{
707*cdf0e10cSrcweir 			updateToolbox();
708*cdf0e10cSrcweir 			// no commitment needed here ....
709*cdf0e10cSrcweir 			return 1L;
710*cdf0e10cSrcweir 		}
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir 		if (aPosition->sName != aPosition->getOriginalName())
713*cdf0e10cSrcweir 		{
714*cdf0e10cSrcweir 			aPosition->setModified(sal_True);
715*cdf0e10cSrcweir 			updateToolbox();
716*cdf0e10cSrcweir 		}
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 		return 1L;
719*cdf0e10cSrcweir 	}
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir 	//------------------------------------------------------------------
722*cdf0e10cSrcweir 	sal_Bool DbaIndexDialog::implSaveModified(sal_Bool _bPlausibility)
723*cdf0e10cSrcweir 	{
724*cdf0e10cSrcweir 		if (m_pPreviousSelection)
725*cdf0e10cSrcweir 		{
726*cdf0e10cSrcweir 			// try to commit the previously selected index
727*cdf0e10cSrcweir 			if (m_pFields->IsModified() && !m_pFields->SaveModified())
728*cdf0e10cSrcweir 				return sal_False;
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir 			Indexes::iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir 			// the unique flag
733*cdf0e10cSrcweir 			aPreviouslySelected->bUnique = m_aUnique.IsChecked();
734*cdf0e10cSrcweir 			if (m_aUnique.GetSavedValue() != m_aUnique.GetState())
735*cdf0e10cSrcweir 				aPreviouslySelected->setModified(sal_True);
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir 			// the fields
738*cdf0e10cSrcweir 			m_pFields->commitTo(aPreviouslySelected->aFields);
739*cdf0e10cSrcweir 			if (m_pFields->GetSavedValue() != aPreviouslySelected->aFields)
740*cdf0e10cSrcweir 				aPreviouslySelected->setModified(sal_True);
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir 			// plausibility checks
743*cdf0e10cSrcweir 			if (_bPlausibility && !implCheckPlausibility(aPreviouslySelected))
744*cdf0e10cSrcweir 				return sal_False;
745*cdf0e10cSrcweir 		}
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 		return sal_True;
748*cdf0e10cSrcweir 	}
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir 	//------------------------------------------------------------------
751*cdf0e10cSrcweir 	sal_Bool DbaIndexDialog::implCheckPlausibility(const ConstIndexesIterator& _rPos)
752*cdf0e10cSrcweir 	{
753*cdf0e10cSrcweir 		// need at least one field
754*cdf0e10cSrcweir 		if (0 == _rPos->aFields.size())
755*cdf0e10cSrcweir 		{
756*cdf0e10cSrcweir 			ErrorBox aError(this, ModuleRes(ERR_NEED_INDEX_FIELDS));
757*cdf0e10cSrcweir 			aError.Execute();
758*cdf0e10cSrcweir 			m_pFields->GrabFocus();
759*cdf0e10cSrcweir 			return sal_False;
760*cdf0e10cSrcweir 		}
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir 		// no double fields
763*cdf0e10cSrcweir 		DECLARE_STL_STDKEY_SET( String, StringBag );
764*cdf0e10cSrcweir 		StringBag aExistentFields;
765*cdf0e10cSrcweir 		for (	ConstIndexFieldsIterator aFieldCheck = _rPos->aFields.begin();
766*cdf0e10cSrcweir 				aFieldCheck != _rPos->aFields.end();
767*cdf0e10cSrcweir 				++aFieldCheck
768*cdf0e10cSrcweir 			)
769*cdf0e10cSrcweir 		{
770*cdf0e10cSrcweir 			if (aExistentFields.end() != aExistentFields.find(aFieldCheck->sFieldName))
771*cdf0e10cSrcweir 			{
772*cdf0e10cSrcweir 				// a column is specified twice ... won't work anyway, so prevent this here and now
773*cdf0e10cSrcweir 				String sMessage(ModuleRes(STR_INDEXDESIGN_DOUBLE_COLUMN_NAME));
774*cdf0e10cSrcweir 				sMessage.SearchAndReplaceAscii("$name$", aFieldCheck->sFieldName);
775*cdf0e10cSrcweir 				ErrorBox aError(this, WB_OK, sMessage);
776*cdf0e10cSrcweir 				aError.Execute();
777*cdf0e10cSrcweir 				m_pFields->GrabFocus();
778*cdf0e10cSrcweir 				return sal_False;
779*cdf0e10cSrcweir 			}
780*cdf0e10cSrcweir 			aExistentFields.insert(aFieldCheck->sFieldName);
781*cdf0e10cSrcweir 		}
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir 		return sal_True;
784*cdf0e10cSrcweir 	}
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir 	//------------------------------------------------------------------
787*cdf0e10cSrcweir 	sal_Bool DbaIndexDialog::implCommitPreviouslySelected()
788*cdf0e10cSrcweir 	{
789*cdf0e10cSrcweir 		if (m_pPreviousSelection)
790*cdf0e10cSrcweir 		{
791*cdf0e10cSrcweir 			Indexes::iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir 			if (!implSaveModified())
794*cdf0e10cSrcweir 				return sal_False;
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 			// commit the index (if necessary)
797*cdf0e10cSrcweir 			if (aPreviouslySelected->isModified() && !implCommit(m_pPreviousSelection))
798*cdf0e10cSrcweir 				return sal_False;
799*cdf0e10cSrcweir 		}
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 		return sal_True;
802*cdf0e10cSrcweir 	}
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir 	//------------------------------------------------------------------
805*cdf0e10cSrcweir 	IMPL_LINK( DbaIndexDialog, OnModified, void*, /*NOTINTERESTEDIN*/ )
806*cdf0e10cSrcweir 	{
807*cdf0e10cSrcweir 		DBG_ASSERT(m_pPreviousSelection, "DbaIndexDialog, OnModified: invalid call!");
808*cdf0e10cSrcweir 		Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir 		aPosition->setModified(sal_True);
811*cdf0e10cSrcweir 		updateToolbox();
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir 		return 1L;
814*cdf0e10cSrcweir 	}
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir 	//------------------------------------------------------------------
817*cdf0e10cSrcweir 	void DbaIndexDialog::updateControls(const SvLBoxEntry* _pEntry)
818*cdf0e10cSrcweir 	{
819*cdf0e10cSrcweir 		if (_pEntry)
820*cdf0e10cSrcweir 		{
821*cdf0e10cSrcweir 			// the descriptor of the selected index
822*cdf0e10cSrcweir 			Indexes::const_iterator aSelectedIndex = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir 			// fill the controls
825*cdf0e10cSrcweir 			m_aUnique.Check(aSelectedIndex->bUnique);
826*cdf0e10cSrcweir 			m_aUnique.Enable(!aSelectedIndex->bPrimaryKey);
827*cdf0e10cSrcweir 			m_aUnique.SaveValue();
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir 			m_pFields->initializeFrom(aSelectedIndex->aFields);
830*cdf0e10cSrcweir 			m_pFields->Enable(!aSelectedIndex->bPrimaryKey);
831*cdf0e10cSrcweir 			m_pFields->SaveValue();
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 			m_aDescription.SetText(aSelectedIndex->sDescription);
834*cdf0e10cSrcweir 			m_aDescription.Enable(!aSelectedIndex->bPrimaryKey);
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir 			m_aDescriptionLabel.Enable(!aSelectedIndex->bPrimaryKey);
837*cdf0e10cSrcweir 		}
838*cdf0e10cSrcweir 		else
839*cdf0e10cSrcweir 		{
840*cdf0e10cSrcweir 			m_aUnique.Check(sal_False);
841*cdf0e10cSrcweir 			m_pFields->initializeFrom(IndexFields());
842*cdf0e10cSrcweir 			m_aDescription.SetText(String());
843*cdf0e10cSrcweir 		}
844*cdf0e10cSrcweir 	}
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 	//------------------------------------------------------------------
847*cdf0e10cSrcweir 	IMPL_LINK( DbaIndexDialog, OnIndexSelected, DbaIndexList*, /*NOTINTERESTEDIN*/ )
848*cdf0e10cSrcweir 	{
849*cdf0e10cSrcweir 		m_aIndexes.EndSelection();
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir 		if (m_aIndexes.IsEditingActive())
852*cdf0e10cSrcweir 			m_aIndexes.EndEditing(sal_False);
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir 		// commit the old data
855*cdf0e10cSrcweir 		if (m_aIndexes.FirstSelected() != m_pPreviousSelection)
856*cdf0e10cSrcweir 		{	// (this call may happen in case somebody ended an in-place edit with 'return', so we need to check this before committing)
857*cdf0e10cSrcweir 			if (!implCommitPreviouslySelected())
858*cdf0e10cSrcweir 			{
859*cdf0e10cSrcweir 				m_aIndexes.SelectNoHandlerCall(m_pPreviousSelection);
860*cdf0e10cSrcweir 				return 1L;
861*cdf0e10cSrcweir 			}
862*cdf0e10cSrcweir 		}
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir 		sal_Bool bHaveSelection = (NULL != m_aIndexes.FirstSelected());
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir 		// disable/enable the detail controls
867*cdf0e10cSrcweir 		m_aIndexDetails.Enable(bHaveSelection);
868*cdf0e10cSrcweir 		m_aUnique.Enable(bHaveSelection);
869*cdf0e10cSrcweir 		m_aDescriptionLabel.Enable(bHaveSelection);
870*cdf0e10cSrcweir 		m_aFieldsLabel.Enable(bHaveSelection);
871*cdf0e10cSrcweir 		m_pFields->Enable(bHaveSelection);
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir 		SvLBoxEntry* pNewSelection = m_aIndexes.FirstSelected();
874*cdf0e10cSrcweir 		updateControls(pNewSelection);
875*cdf0e10cSrcweir 		if (bHaveSelection)
876*cdf0e10cSrcweir 			m_aIndexes.GrabFocus();
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir 		m_pPreviousSelection = pNewSelection;
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 		updateToolbox();
881*cdf0e10cSrcweir 		return 0L;
882*cdf0e10cSrcweir 	}
883*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
884*cdf0e10cSrcweir 	void DbaIndexDialog::StateChanged( StateChangedType nType )
885*cdf0e10cSrcweir 	{
886*cdf0e10cSrcweir 		ModalDialog::StateChanged( nType );
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir 		if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
889*cdf0e10cSrcweir 		{
890*cdf0e10cSrcweir 			// Check if we need to get new images for normal/high contrast mode
891*cdf0e10cSrcweir 			checkImageList();
892*cdf0e10cSrcweir 		}
893*cdf0e10cSrcweir 		else if ( nType == STATE_CHANGE_TEXT )
894*cdf0e10cSrcweir 		{
895*cdf0e10cSrcweir 			// The physical toolbar changed its outlook and shows another logical toolbar!
896*cdf0e10cSrcweir 			// We have to set the correct high contrast mode on the new tbx manager.
897*cdf0e10cSrcweir 			//	pMgr->SetHiContrast( IsHiContrastMode() );
898*cdf0e10cSrcweir 			checkImageList();
899*cdf0e10cSrcweir 		}
900*cdf0e10cSrcweir 	}
901*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
902*cdf0e10cSrcweir 	void DbaIndexDialog::DataChanged( const DataChangedEvent& rDCEvt )
903*cdf0e10cSrcweir 	{
904*cdf0e10cSrcweir 		ModalDialog::DataChanged( rDCEvt );
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir 		if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS	)	||
907*cdf0e10cSrcweir 			( rDCEvt.GetType() == DATACHANGED_DISPLAY	))	&&
908*cdf0e10cSrcweir 			( rDCEvt.GetFlags() & SETTINGS_STYLE		))
909*cdf0e10cSrcweir 		{
910*cdf0e10cSrcweir 			// Check if we need to get new images for normal/high contrast mode
911*cdf0e10cSrcweir 			checkImageList();
912*cdf0e10cSrcweir 		}
913*cdf0e10cSrcweir 	}
914*cdf0e10cSrcweir 	//------------------------------------------------------------------
915*cdf0e10cSrcweir 	ImageList DbaIndexDialog::getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
916*cdf0e10cSrcweir 	{
917*cdf0e10cSrcweir 		sal_Int16 nN = IMG_INDEX_DLG_SC;
918*cdf0e10cSrcweir 		sal_Int16 nH = IMG_INDEX_DLG_SCH;
919*cdf0e10cSrcweir 		if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
920*cdf0e10cSrcweir 		{
921*cdf0e10cSrcweir 			nN = IMG_INDEX_DLG_LC;
922*cdf0e10cSrcweir 			nH = IMG_INDEX_DLG_LCH;
923*cdf0e10cSrcweir 		} // if ( _eBitmapSet == SFX_SYMBOLS_LARGE )
924*cdf0e10cSrcweir 		return ImageList(ModuleRes( _bHiContast ? nH : nN ));
925*cdf0e10cSrcweir 	}
926*cdf0e10cSrcweir 	//------------------------------------------------------------------
927*cdf0e10cSrcweir 	void DbaIndexDialog::resizeControls(const Size& _rDiff)
928*cdf0e10cSrcweir 	{
929*cdf0e10cSrcweir 		// we use large images so we must change them
930*cdf0e10cSrcweir 		Size aTbNewSize = m_aActions.GetSizePixel();
931*cdf0e10cSrcweir 		if ( _rDiff.Width() || _rDiff.Height() )
932*cdf0e10cSrcweir 		{
933*cdf0e10cSrcweir 			Size aDlgSize = GetSizePixel();
934*cdf0e10cSrcweir 			// adjust size of dlg
935*cdf0e10cSrcweir 			SetSizePixel(Size(aDlgSize.Width() + _rDiff.Width(),
936*cdf0e10cSrcweir 							  aDlgSize.Height() + _rDiff.Height())
937*cdf0e10cSrcweir 						);
938*cdf0e10cSrcweir 			Size aIndexSize = m_aIndexes.GetSizePixel();
939*cdf0e10cSrcweir 			m_aIndexes.SetPosSizePixel(m_aIndexes.GetPosPixel() + Point(0,_rDiff.Height()),
940*cdf0e10cSrcweir 									Size(aIndexSize.Width() + _rDiff.Width(),
941*cdf0e10cSrcweir 									     aIndexSize.Height()));
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir 			//now move the rest to the left side
944*cdf0e10cSrcweir 			Point aMove(_rDiff.Width(),_rDiff.Height());
945*cdf0e10cSrcweir 			m_aIndexDetails.SetPosPixel(m_aIndexDetails.GetPosPixel() + aMove);
946*cdf0e10cSrcweir 			m_aDescriptionLabel.SetPosPixel(m_aDescriptionLabel.GetPosPixel() + aMove);
947*cdf0e10cSrcweir 			m_aDescription.SetPosPixel(m_aDescription.GetPosPixel() + aMove);
948*cdf0e10cSrcweir 			m_aUnique.SetPosPixel(m_aUnique.GetPosPixel() + aMove);
949*cdf0e10cSrcweir 			m_aFieldsLabel.SetPosPixel(m_aFieldsLabel.GetPosPixel() + aMove);
950*cdf0e10cSrcweir 			OSL_ENSURE(m_pFields,"NO valid fields!");
951*cdf0e10cSrcweir 			m_pFields->SetPosPixel(m_pFields->GetPosPixel() + aMove);
952*cdf0e10cSrcweir 			m_aClose.SetPosPixel(m_aClose.GetPosPixel() + aMove);
953*cdf0e10cSrcweir 			m_aHelp.SetPosPixel(m_aHelp.GetPosPixel() + aMove);
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir 			Invalidate();
956*cdf0e10cSrcweir 		}
957*cdf0e10cSrcweir 	}
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir //......................................................................
960*cdf0e10cSrcweir }	// namespace dbaui
961*cdf0e10cSrcweir //......................................................................
962*cdf0e10cSrcweir 
963