xref: /AOO41X/main/svx/source/fmcomp/fmgridcl.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_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "svx/dbexch.hrc"
32*cdf0e10cSrcweir #include "svx/fmgridif.hxx"
33*cdf0e10cSrcweir #include "fmitems.hxx"
34*cdf0e10cSrcweir #include "fmprop.hrc"
35*cdf0e10cSrcweir #include "svx/fmtools.hxx"
36*cdf0e10cSrcweir #include "svx/fmresids.hrc"
37*cdf0e10cSrcweir #include "fmservs.hxx"
38*cdf0e10cSrcweir #include "fmurl.hxx"
39*cdf0e10cSrcweir #include "formcontrolfactory.hxx"
40*cdf0e10cSrcweir #include "gridcell.hxx"
41*cdf0e10cSrcweir #include "gridcols.hxx"
42*cdf0e10cSrcweir #include "svx/dbaexchange.hxx"
43*cdf0e10cSrcweir #include "svx/dialmgr.hxx"
44*cdf0e10cSrcweir #include "svx/dialogs.hrc"
45*cdf0e10cSrcweir #include "svx/fmgridcl.hxx"
46*cdf0e10cSrcweir #include "svx/svxdlg.hxx"
47*cdf0e10cSrcweir #include "svx/svxids.hrc"
48*cdf0e10cSrcweir #include "trace.hxx"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <com/sun/star/form/XConfirmDeleteListener.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/form/XFormComponent.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/io/XPersistObject.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/sdb/RowChangeAction.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/sdbc/XPreparedStatement.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDeleteRows.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormats.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #ifndef _SVSTDARR_STRINGSDTOR
69*cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
70*cdf0e10cSrcweir #define _SVSTDARR_ULONGS
71*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir #include <comphelper/extract.hxx>
75*cdf0e10cSrcweir #include <comphelper/numbers.hxx>
76*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
77*cdf0e10cSrcweir #include <comphelper/property.hxx>
78*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
79*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
80*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
81*cdf0e10cSrcweir #include <svl/eitem.hxx>
82*cdf0e10cSrcweir #include <svtools/fmtfield.hxx>
83*cdf0e10cSrcweir #include <svl/numuno.hxx>
84*cdf0e10cSrcweir #include <tools/multisel.hxx>
85*cdf0e10cSrcweir #include <tools/shl.hxx>
86*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
87*cdf0e10cSrcweir #include <vcl/help.hxx>
88*cdf0e10cSrcweir #include <vcl/image.hxx>
89*cdf0e10cSrcweir #include <vcl/longcurr.hxx>
90*cdf0e10cSrcweir #include <vcl/menu.hxx>
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir #include <math.h>
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
95*cdf0e10cSrcweir using namespace ::com::sun::star::view;
96*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
97*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
98*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
99*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
100*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
101*cdf0e10cSrcweir using namespace ::com::sun::star::form;
102*cdf0e10cSrcweir using namespace ::com::sun::star::util;
103*cdf0e10cSrcweir using namespace ::com::sun::star::container;
104*cdf0e10cSrcweir using namespace ::cppu;
105*cdf0e10cSrcweir using namespace ::svxform;
106*cdf0e10cSrcweir using namespace ::svx;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir //==============================================================================
109*cdf0e10cSrcweir //------------------------------------------------------------------------------
110*cdf0e10cSrcweir ::rtl::OUString FieldServiceFromId(sal_Int32 nID)
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir 	switch (nID)
113*cdf0e10cSrcweir 	{
114*cdf0e10cSrcweir 		case SID_FM_EDIT			: return FM_COL_TEXTFIELD;
115*cdf0e10cSrcweir 		case SID_FM_COMBOBOX		: return FM_COL_COMBOBOX;
116*cdf0e10cSrcweir 		case SID_FM_LISTBOX 		: return FM_COL_LISTBOX;
117*cdf0e10cSrcweir 		case SID_FM_CHECKBOX		: return FM_COL_CHECKBOX;
118*cdf0e10cSrcweir 		case SID_FM_DATEFIELD		: return FM_COL_DATEFIELD;
119*cdf0e10cSrcweir 		case SID_FM_TIMEFIELD		: return FM_COL_TIMEFIELD;
120*cdf0e10cSrcweir 		case SID_FM_NUMERICFIELD	: return FM_COL_NUMERICFIELD;
121*cdf0e10cSrcweir 		case SID_FM_CURRENCYFIELD	: return FM_COL_CURRENCYFIELD;
122*cdf0e10cSrcweir 		case SID_FM_PATTERNFIELD	: return FM_COL_PATTERNFIELD;
123*cdf0e10cSrcweir 		case SID_FM_FORMATTEDFIELD	: return FM_COL_FORMATTEDFIELD;
124*cdf0e10cSrcweir 	}
125*cdf0e10cSrcweir 	return ::rtl::OUString();
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir //==============================================================================
129*cdf0e10cSrcweir struct FmGridHeaderData
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir 	ODataAccessDescriptor	aDropData;
132*cdf0e10cSrcweir 	Point					aDropPosPixel;
133*cdf0e10cSrcweir 	sal_Int8				nDropAction;
134*cdf0e10cSrcweir 	Reference< XInterface > xDroppedStatement;
135*cdf0e10cSrcweir 	Reference< XInterface > xDroppedResultSet;
136*cdf0e10cSrcweir };
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir //==============================================================================
139*cdf0e10cSrcweir //------------------------------------------------------------------------------
140*cdf0e10cSrcweir const sal_Int16 nChangeTypeOffset = 1000;
141*cdf0e10cSrcweir void SetMenuItem(const ImageList& rList, sal_uInt16 nID, Menu* pMenu, Menu& rNewMenu, sal_Bool bDesignMode = sal_True, sal_Int16 nOffset = nChangeTypeOffset)
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir 	pMenu->SetItemImage(nID, rList.GetImage(nID));
144*cdf0e10cSrcweir 	pMenu->EnableItem(nID, bDesignMode);
145*cdf0e10cSrcweir 	rNewMenu.InsertItem(nID + nOffset, pMenu->GetItemText(nID));
146*cdf0e10cSrcweir 	rNewMenu.SetItemImage(nID + nOffset, rList.GetImage(nID));
147*cdf0e10cSrcweir 	rNewMenu.SetHelpId(nID + nOffset, pMenu->GetHelpId(nID));
148*cdf0e10cSrcweir 	rNewMenu.EnableItem(nID + nOffset, bDesignMode);
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir //------------------------------------------------------------------------------
152*cdf0e10cSrcweir FmGridHeader::FmGridHeader( BrowseBox* pParent, WinBits nWinBits)
153*cdf0e10cSrcweir 		:EditBrowserHeader(pParent, nWinBits)
154*cdf0e10cSrcweir 		,DropTargetHelper(this)
155*cdf0e10cSrcweir 		,m_pImpl(new FmGridHeaderData)
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir //------------------------------------------------------------------------------
160*cdf0e10cSrcweir FmGridHeader::~FmGridHeader()
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir 	delete m_pImpl;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //------------------------------------------------------------------------------
166*cdf0e10cSrcweir sal_uInt16 FmGridHeader::GetModelColumnPos(sal_uInt16 nId) const
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir 	return static_cast<FmGridControl*>(GetParent())->GetModelColumnPos(nId);
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir //---------------------------------------------------------------------------------------
171*cdf0e10cSrcweir void FmGridHeader::notifyColumnSelect(sal_uInt16 nColumnId)
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir 	sal_uInt16 nPos = GetModelColumnPos(nColumnId);
174*cdf0e10cSrcweir 	Reference< XIndexAccess >  xColumns(((FmGridControl*)GetParent())->GetPeer()->getColumns(), UNO_QUERY);
175*cdf0e10cSrcweir 	if ( nPos < xColumns->getCount() )
176*cdf0e10cSrcweir 	{
177*cdf0e10cSrcweir 		Reference< XSelectionSupplier >  xSelSupplier(xColumns, UNO_QUERY);
178*cdf0e10cSrcweir 		if ( xSelSupplier.is() )
179*cdf0e10cSrcweir 		{
180*cdf0e10cSrcweir 			Reference< XPropertySet >  xColumn;
181*cdf0e10cSrcweir 			xColumns->getByIndex(nPos) >>= xColumn;
182*cdf0e10cSrcweir 			xSelSupplier->select(makeAny(xColumn));
183*cdf0e10cSrcweir 		}
184*cdf0e10cSrcweir 	}
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir //------------------------------------------------------------------------------
187*cdf0e10cSrcweir void FmGridHeader::Select()
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir 	EditBrowserHeader::Select();
190*cdf0e10cSrcweir 	notifyColumnSelect(GetCurItemId());
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir //------------------------------------------------------------------------------
194*cdf0e10cSrcweir void FmGridHeader::RequestHelp( const HelpEvent& rHEvt )
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
197*cdf0e10cSrcweir 	if ( nItemId )
198*cdf0e10cSrcweir 	{
199*cdf0e10cSrcweir 		if ( rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON) )
200*cdf0e10cSrcweir 		{
201*cdf0e10cSrcweir 			Rectangle aItemRect = GetItemRect( nItemId );
202*cdf0e10cSrcweir 			Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
203*cdf0e10cSrcweir 			aItemRect.Left()   = aPt.X();
204*cdf0e10cSrcweir 			aItemRect.Top()    = aPt.Y();
205*cdf0e10cSrcweir 			aPt = OutputToScreenPixel( aItemRect.BottomRight() );
206*cdf0e10cSrcweir 			aItemRect.Right()  = aPt.X();
207*cdf0e10cSrcweir 			aItemRect.Bottom() = aPt.Y();
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 			sal_uInt16 nPos = GetModelColumnPos(nItemId);
210*cdf0e10cSrcweir 			Reference< ::com::sun::star::container::XIndexContainer >  xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
211*cdf0e10cSrcweir 			try
212*cdf0e10cSrcweir 			{
213*cdf0e10cSrcweir 				Reference< ::com::sun::star::beans::XPropertySet >	xColumn(xColumns->getByIndex(nPos),UNO_QUERY);
214*cdf0e10cSrcweir 				::rtl::OUString aHelpText;
215*cdf0e10cSrcweir 				xColumn->getPropertyValue(FM_PROP_HELPTEXT) >>= aHelpText;
216*cdf0e10cSrcweir                 if ( !aHelpText.getLength() )
217*cdf0e10cSrcweir                     xColumn->getPropertyValue(FM_PROP_DESCRIPTION) >>= aHelpText;
218*cdf0e10cSrcweir 				if ( aHelpText.getLength() )
219*cdf0e10cSrcweir 				{
220*cdf0e10cSrcweir 					if ( rHEvt.GetMode() & HELPMODE_BALLOON )
221*cdf0e10cSrcweir 						Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText );
222*cdf0e10cSrcweir 					else
223*cdf0e10cSrcweir 						Help::ShowQuickHelp( this, aItemRect, aHelpText );
224*cdf0e10cSrcweir 					return;
225*cdf0e10cSrcweir 				}
226*cdf0e10cSrcweir 			}
227*cdf0e10cSrcweir 			catch(Exception&)
228*cdf0e10cSrcweir 			{
229*cdf0e10cSrcweir 				return;
230*cdf0e10cSrcweir 			}
231*cdf0e10cSrcweir 		}
232*cdf0e10cSrcweir 	}
233*cdf0e10cSrcweir 	EditBrowserHeader::RequestHelp( rHEvt );
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir //------------------------------------------------------------------------------
237*cdf0e10cSrcweir sal_Int8 FmGridHeader::AcceptDrop( const AcceptDropEvent& rEvt )
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir 	// drop allowed in design mode only
240*cdf0e10cSrcweir 	if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode())
241*cdf0e10cSrcweir 		return DND_ACTION_NONE;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 	// search for recognized formats
244*cdf0e10cSrcweir 	const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
245*cdf0e10cSrcweir 	if (OColumnTransferable::canExtractColumnDescriptor(rFlavors, CTF_COLUMN_DESCRIPTOR | CTF_FIELD_DESCRIPTOR))
246*cdf0e10cSrcweir 		return rEvt.mnAction;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 	return DND_ACTION_NONE;
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir //------------------------------------------------------------------------------
252*cdf0e10cSrcweir sal_Int8 FmGridHeader::ExecuteDrop( const ExecuteDropEvent& _rEvt )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir 	if (!static_cast<FmGridControl*>(GetParent())->IsDesignMode())
255*cdf0e10cSrcweir 		return DND_ACTION_NONE;
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 	TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	// check the formats
260*cdf0e10cSrcweir 	sal_Bool bColumnDescriptor	= OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), CTF_COLUMN_DESCRIPTOR);
261*cdf0e10cSrcweir 	sal_Bool bFieldDescriptor	= OColumnTransferable::canExtractColumnDescriptor(aDroppedData.GetDataFlavorExVector(), CTF_FIELD_DESCRIPTOR);
262*cdf0e10cSrcweir 	if (!bColumnDescriptor && !bFieldDescriptor)
263*cdf0e10cSrcweir 	{
264*cdf0e10cSrcweir 		DBG_ERROR("FmGridHeader::ExecuteDrop: should never have reached this (no extractable format)!");
265*cdf0e10cSrcweir 		return DND_ACTION_NONE;
266*cdf0e10cSrcweir 	}
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	// extract the descriptor
269*cdf0e10cSrcweir 	::rtl::OUString sDatasouce, sCommand, sFieldName,sDatabaseLocation,sConnnectionResource;
270*cdf0e10cSrcweir 	sal_Int32		nCommandType = CommandType::COMMAND;
271*cdf0e10cSrcweir 	Reference< XPreparedStatement > 	xStatement;
272*cdf0e10cSrcweir 	Reference< XResultSet > 			xResultSet;
273*cdf0e10cSrcweir 	Reference< XPropertySet >			xField;
274*cdf0e10cSrcweir 	Reference< XConnection >			xConnection;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 	ODataAccessDescriptor aColumn = OColumnTransferable::extractColumnDescriptor(aDroppedData);
277*cdf0e10cSrcweir 	if (aColumn.has(daDataSource))	aColumn[daDataSource]	>>= sDatasouce;
278*cdf0e10cSrcweir 	if (aColumn.has(daDatabaseLocation))	aColumn[daDatabaseLocation]	>>= sDatabaseLocation;
279*cdf0e10cSrcweir 	if (aColumn.has(daConnectionResource))	aColumn[daConnectionResource] >>= sConnnectionResource;
280*cdf0e10cSrcweir 	if (aColumn.has(daCommand)) 	aColumn[daCommand]		>>= sCommand;
281*cdf0e10cSrcweir 	if (aColumn.has(daCommandType)) aColumn[daCommandType]	>>= nCommandType;
282*cdf0e10cSrcweir 	if (aColumn.has(daColumnName))	aColumn[daColumnName]	>>= sFieldName;
283*cdf0e10cSrcweir 	if (aColumn.has(daColumnObject))aColumn[daColumnObject] >>= xField;
284*cdf0e10cSrcweir 	if (aColumn.has(daConnection))	aColumn[daConnection]	>>= xConnection;
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 	if  (   !sFieldName.getLength()
287*cdf0e10cSrcweir         ||  !sCommand.getLength()
288*cdf0e10cSrcweir         ||  (   !sDatasouce.getLength()
289*cdf0e10cSrcweir             &&  !sDatabaseLocation.getLength()
290*cdf0e10cSrcweir             &&  !xConnection.is()
291*cdf0e10cSrcweir             )
292*cdf0e10cSrcweir         )
293*cdf0e10cSrcweir 	{
294*cdf0e10cSrcweir 		DBG_ERROR( "FmGridHeader::ExecuteDrop: somebody started a nonsense drag operation!!" );
295*cdf0e10cSrcweir 		return DND_ACTION_NONE;
296*cdf0e10cSrcweir 	}
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	try
299*cdf0e10cSrcweir 	{
300*cdf0e10cSrcweir 		// need a connection
301*cdf0e10cSrcweir 		if (!xConnection.is())
302*cdf0e10cSrcweir 		{	// the transferable did not contain the connection -> build an own one
303*cdf0e10cSrcweir 			try
304*cdf0e10cSrcweir 			{
305*cdf0e10cSrcweir                 ::rtl::OUString sSignificantSource( sDatasouce.getLength() ? sDatasouce : sDatabaseLocation );
306*cdf0e10cSrcweir 				xConnection = OStaticDataAccessTools().getConnection_withFeedback(sSignificantSource, ::rtl::OUString(),::rtl::OUString(),static_cast<FmGridControl*>(GetParent())->getServiceManager());
307*cdf0e10cSrcweir 			}
308*cdf0e10cSrcweir 			catch(NoSuchElementException&)
309*cdf0e10cSrcweir 			{	// allowed, means sDatasouce isn't a valid data source name ....
310*cdf0e10cSrcweir 			}
311*cdf0e10cSrcweir 			catch(Exception&)
312*cdf0e10cSrcweir 			{
313*cdf0e10cSrcweir 				DBG_ERROR("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
314*cdf0e10cSrcweir 			}
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 			if (!xConnection.is())
317*cdf0e10cSrcweir 			{
318*cdf0e10cSrcweir 				DBG_ERROR("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
319*cdf0e10cSrcweir 				return DND_ACTION_NONE;
320*cdf0e10cSrcweir 			}
321*cdf0e10cSrcweir 		}
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 		// try to obtain the column object
324*cdf0e10cSrcweir 		if (!xField.is())
325*cdf0e10cSrcweir 		{
326*cdf0e10cSrcweir #ifdef DBG_UTIL
327*cdf0e10cSrcweir 			Reference< XServiceInfo >  xServiceInfo(xConnection, UNO_QUERY);
328*cdf0e10cSrcweir 			DBG_ASSERT(xServiceInfo.is() && xServiceInfo->supportsService(SRV_SDB_CONNECTION), "FmGridHeader::ExecuteDrop: invalid connection (no database access connection !)");
329*cdf0e10cSrcweir #endif
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 			Reference< XNameAccess > xFields;
332*cdf0e10cSrcweir 			switch (nCommandType)
333*cdf0e10cSrcweir 			{
334*cdf0e10cSrcweir 				case CommandType::TABLE:
335*cdf0e10cSrcweir 				{
336*cdf0e10cSrcweir 					Reference< XTablesSupplier > xSupplyTables(xConnection, UNO_QUERY);
337*cdf0e10cSrcweir 					Reference< XColumnsSupplier >  xSupplyColumns;
338*cdf0e10cSrcweir 					xSupplyTables->getTables()->getByName(sCommand) >>= xSupplyColumns;
339*cdf0e10cSrcweir 					xFields = xSupplyColumns->getColumns();
340*cdf0e10cSrcweir 				}
341*cdf0e10cSrcweir 				break;
342*cdf0e10cSrcweir 				case CommandType::QUERY:
343*cdf0e10cSrcweir 				{
344*cdf0e10cSrcweir 					Reference< XQueriesSupplier > xSupplyQueries(xConnection, UNO_QUERY);
345*cdf0e10cSrcweir 					Reference< XColumnsSupplier > xSupplyColumns;
346*cdf0e10cSrcweir 					xSupplyQueries->getQueries()->getByName(sCommand) >>= xSupplyColumns;
347*cdf0e10cSrcweir 					xFields  = xSupplyColumns->getColumns();
348*cdf0e10cSrcweir 				}
349*cdf0e10cSrcweir 				break;
350*cdf0e10cSrcweir 				default:
351*cdf0e10cSrcweir 				{
352*cdf0e10cSrcweir 					xStatement = xConnection->prepareStatement(sCommand);
353*cdf0e10cSrcweir 					// not interested in any results
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 					Reference< XPropertySet > xStatProps(xStatement,UNO_QUERY);
356*cdf0e10cSrcweir 					xStatProps->setPropertyValue(rtl::OUString::createFromAscii("MaxRows"), makeAny(sal_Int32(0)));
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 					xResultSet = xStatement->executeQuery();
359*cdf0e10cSrcweir 					Reference< XColumnsSupplier >  xSupplyCols(xResultSet, UNO_QUERY);
360*cdf0e10cSrcweir 					if (xSupplyCols.is())
361*cdf0e10cSrcweir 						xFields = xSupplyCols->getColumns();
362*cdf0e10cSrcweir 				}
363*cdf0e10cSrcweir 			}
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 			if (xFields.is() && xFields->hasByName(sFieldName))
366*cdf0e10cSrcweir 				xFields->getByName(sFieldName) >>= xField;
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 			if (!xField.is())
369*cdf0e10cSrcweir 			{
370*cdf0e10cSrcweir 				::comphelper::disposeComponent(xStatement);
371*cdf0e10cSrcweir 				return DND_ACTION_NONE;
372*cdf0e10cSrcweir 			}
373*cdf0e10cSrcweir 		}
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 		// do the drop asynchronously
376*cdf0e10cSrcweir 		// (85957 - UI actions within the drop are not allowed, but we want to open a popup menu)
377*cdf0e10cSrcweir 		m_pImpl->aDropData = aColumn;
378*cdf0e10cSrcweir 		m_pImpl->aDropData[daConnection] <<= xConnection;
379*cdf0e10cSrcweir 		m_pImpl->aDropData[daColumnObject] <<= xField;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 		m_pImpl->nDropAction = _rEvt.mnAction;
382*cdf0e10cSrcweir 		m_pImpl->aDropPosPixel = _rEvt.maPosPixel;
383*cdf0e10cSrcweir 		m_pImpl->xDroppedStatement = xStatement;
384*cdf0e10cSrcweir 		m_pImpl->xDroppedResultSet = xResultSet;
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 		PostUserEvent(LINK(this, FmGridHeader, OnAsyncExecuteDrop));
387*cdf0e10cSrcweir 	}
388*cdf0e10cSrcweir 	catch (Exception&)
389*cdf0e10cSrcweir 	{
390*cdf0e10cSrcweir 		DBG_ERROR("FmGridHeader::ExecuteDrop: caught an exception while creatin' the column !");
391*cdf0e10cSrcweir 		::comphelper::disposeComponent(xStatement);
392*cdf0e10cSrcweir 		return sal_False;
393*cdf0e10cSrcweir 	}
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 	return DND_ACTION_LINK;
396*cdf0e10cSrcweir }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir //------------------------------------------------------------------------------
399*cdf0e10cSrcweir IMPL_LINK( FmGridHeader, OnAsyncExecuteDrop, void*, /*NOTINTERESTEDIN*/ )
400*cdf0e10cSrcweir {
401*cdf0e10cSrcweir 	::rtl::OUString 			sCommand, sFieldName,sURL;
402*cdf0e10cSrcweir 	sal_Int32					nCommandType = CommandType::COMMAND;
403*cdf0e10cSrcweir 	Reference< XPropertySet >	xField;
404*cdf0e10cSrcweir 	Reference< XConnection >	xConnection;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 	::rtl::OUString sDatasouce = m_pImpl->aDropData.getDataSource();
407*cdf0e10cSrcweir 	if ( !sDatasouce.getLength() && m_pImpl->aDropData.has(daConnectionResource) )
408*cdf0e10cSrcweir 		m_pImpl->aDropData[daConnectionResource]	>>= sURL;
409*cdf0e10cSrcweir 	m_pImpl->aDropData[daCommand]		>>= sCommand;
410*cdf0e10cSrcweir 	m_pImpl->aDropData[daCommandType]	>>= nCommandType;
411*cdf0e10cSrcweir 	m_pImpl->aDropData[daColumnName]	>>= sFieldName;
412*cdf0e10cSrcweir 	m_pImpl->aDropData[daConnection]	>>= xConnection;
413*cdf0e10cSrcweir 	m_pImpl->aDropData[daColumnObject]	>>= xField;
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	try
416*cdf0e10cSrcweir 	{
417*cdf0e10cSrcweir 		// need number formats
418*cdf0e10cSrcweir 		Reference< XNumberFormatsSupplier > xSupplier = OStaticDataAccessTools().getNumberFormats(xConnection, sal_True);
419*cdf0e10cSrcweir 		Reference< XNumberFormats >  xNumberFormats;
420*cdf0e10cSrcweir 		if (xSupplier.is())
421*cdf0e10cSrcweir 			xNumberFormats = xSupplier->getNumberFormats();
422*cdf0e10cSrcweir 		if (!xNumberFormats.is())
423*cdf0e10cSrcweir 		{
424*cdf0e10cSrcweir 			::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
425*cdf0e10cSrcweir 			::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
426*cdf0e10cSrcweir 			return 0L;
427*cdf0e10cSrcweir 		}
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 		// Vom Feld werden nun zwei Informationen benoetigt:
430*cdf0e10cSrcweir 		// a.) Name des Feldes fuer Label und ControlSource
431*cdf0e10cSrcweir 		// b.) FormatKey, um festzustellen, welches Feld erzeugt werden soll
432*cdf0e10cSrcweir 		sal_Int32 nDataType = 0;
433*cdf0e10cSrcweir 		xField->getPropertyValue(FM_PROP_FIELDTYPE) >>= nDataType;
434*cdf0e10cSrcweir 		// diese Datentypen koennen im Gridcontrol nicht verarbeitet werden
435*cdf0e10cSrcweir 		switch (nDataType)
436*cdf0e10cSrcweir 		{
437*cdf0e10cSrcweir 			case DataType::BLOB:
438*cdf0e10cSrcweir 			case DataType::LONGVARBINARY:
439*cdf0e10cSrcweir 			case DataType::BINARY:
440*cdf0e10cSrcweir 			case DataType::VARBINARY:
441*cdf0e10cSrcweir 			case DataType::OTHER:
442*cdf0e10cSrcweir 				::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
443*cdf0e10cSrcweir 				::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
444*cdf0e10cSrcweir 				return 0L;
445*cdf0e10cSrcweir 		}
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 		// Erstellen der Column
448*cdf0e10cSrcweir 		Reference< XIndexContainer >  xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
449*cdf0e10cSrcweir 		Reference< XGridColumnFactory >  xFactory(xCols, UNO_QUERY);
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 		Point aPos	= OutputToScreenPixel(m_pImpl->aDropPosPixel);
452*cdf0e10cSrcweir 		sal_uInt16 nColId = GetItemId(m_pImpl->aDropPosPixel);
453*cdf0e10cSrcweir 		// EinfuegePosition, immer vor der aktuellen Spalte
454*cdf0e10cSrcweir 		sal_uInt16 nPos = GetModelColumnPos(nColId);
455*cdf0e10cSrcweir 		Reference< XPropertySet >  xCol, xSecondCol;
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir 		// erzeugen der Column in abhaengigkeit vom type, default textfeld
458*cdf0e10cSrcweir 		SvULongs aPossibleTypes;
459*cdf0e10cSrcweir 		switch (nDataType)
460*cdf0e10cSrcweir 		{
461*cdf0e10cSrcweir 			case DataType::BIT:
462*cdf0e10cSrcweir 			case DataType::BOOLEAN:
463*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_CHECKBOX, aPossibleTypes.Count());
464*cdf0e10cSrcweir 				break;
465*cdf0e10cSrcweir 			case DataType::TINYINT:
466*cdf0e10cSrcweir 			case DataType::SMALLINT:
467*cdf0e10cSrcweir 			case DataType::INTEGER:
468*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_NUMERICFIELD, aPossibleTypes.Count());
469*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
470*cdf0e10cSrcweir 				break;
471*cdf0e10cSrcweir 			case DataType::REAL:
472*cdf0e10cSrcweir 			case DataType::DOUBLE:
473*cdf0e10cSrcweir 			case DataType::NUMERIC:
474*cdf0e10cSrcweir 			case DataType::DECIMAL:
475*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
476*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_NUMERICFIELD, aPossibleTypes.Count());
477*cdf0e10cSrcweir 				break;
478*cdf0e10cSrcweir 			case DataType::TIMESTAMP:
479*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_TWOFIELDS_DATE_N_TIME, aPossibleTypes.Count());
480*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_DATEFIELD, aPossibleTypes.Count());
481*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_TIMEFIELD, aPossibleTypes.Count());
482*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
483*cdf0e10cSrcweir 				break;
484*cdf0e10cSrcweir 			case DataType::DATE:
485*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_DATEFIELD, aPossibleTypes.Count());
486*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
487*cdf0e10cSrcweir 				break;
488*cdf0e10cSrcweir 			case DataType::TIME:
489*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_TIMEFIELD, aPossibleTypes.Count());
490*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
491*cdf0e10cSrcweir 				break;
492*cdf0e10cSrcweir 			case DataType::CHAR:
493*cdf0e10cSrcweir 			case DataType::VARCHAR:
494*cdf0e10cSrcweir 			case DataType::LONGVARCHAR:
495*cdf0e10cSrcweir 			default:
496*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_EDIT, aPossibleTypes.Count());
497*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_FORMATTEDFIELD, aPossibleTypes.Count());
498*cdf0e10cSrcweir 				break;
499*cdf0e10cSrcweir 		}
500*cdf0e10cSrcweir 		// if it's a currency field, a a "currency field" option
501*cdf0e10cSrcweir 		try
502*cdf0e10cSrcweir 		{
503*cdf0e10cSrcweir 			if	(	::comphelper::hasProperty(FM_PROP_ISCURRENCY, xField)
504*cdf0e10cSrcweir 				&&	::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISCURRENCY)))
505*cdf0e10cSrcweir 				aPossibleTypes.Insert(SID_FM_CURRENCYFIELD, 0);
506*cdf0e10cSrcweir 		}
507*cdf0e10cSrcweir 		catch(Exception&)
508*cdf0e10cSrcweir 		{
509*cdf0e10cSrcweir 			DBG_ERROR("FmGridHeader::ExecuteDrop: Exception occured!");
510*cdf0e10cSrcweir 		}
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 		sal_Int32 nPreferedType = -1;
513*cdf0e10cSrcweir 		sal_Bool bDateNTimeCol = sal_False;
514*cdf0e10cSrcweir 		if (aPossibleTypes.Count() != 0)
515*cdf0e10cSrcweir 		{
516*cdf0e10cSrcweir 			nPreferedType = aPossibleTypes[0];
517*cdf0e10cSrcweir 			if ((m_pImpl->nDropAction == DND_ACTION_LINK) && (aPossibleTypes.Count() > 1))
518*cdf0e10cSrcweir 			{
519*cdf0e10cSrcweir 				ImageList aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL) );
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 				PopupMenu aInsertMenu(SVX_RES(RID_SVXMNU_COLS));
522*cdf0e10cSrcweir 				PopupMenu aTypeMenu;
523*cdf0e10cSrcweir 				PopupMenu* pMenu = aInsertMenu.GetPopupMenu(SID_FM_INSERTCOL);
524*cdf0e10cSrcweir 				for (sal_uInt32 i=0; i<aPossibleTypes.Count(); ++i)
525*cdf0e10cSrcweir 					SetMenuItem(aImageList, sal_uInt16(aPossibleTypes[(sal_uInt16)i]), pMenu, aTypeMenu, sal_True, 0);
526*cdf0e10cSrcweir 				nPreferedType = aTypeMenu.Execute(this, m_pImpl->aDropPosPixel);
527*cdf0e10cSrcweir 			}
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 			bDateNTimeCol = nPreferedType == SID_FM_TWOFIELDS_DATE_N_TIME;
530*cdf0e10cSrcweir 			sal_uInt16 nColCount = bDateNTimeCol ? 2 : 1;
531*cdf0e10cSrcweir 			::rtl::OUString sFieldService;
532*cdf0e10cSrcweir 			while (nColCount--)
533*cdf0e10cSrcweir 			{
534*cdf0e10cSrcweir 				if (bDateNTimeCol)
535*cdf0e10cSrcweir 					nPreferedType = nColCount ? SID_FM_DATEFIELD : SID_FM_TIMEFIELD;
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 				sFieldService = FieldServiceFromId(nPreferedType);
538*cdf0e10cSrcweir 				Reference< XPropertySet >  xThisRoundCol;
539*cdf0e10cSrcweir 				if ( sFieldService.getLength() )
540*cdf0e10cSrcweir 					xThisRoundCol = xFactory->createColumn(sFieldService);
541*cdf0e10cSrcweir 				if (nColCount)
542*cdf0e10cSrcweir 					xSecondCol = xThisRoundCol;
543*cdf0e10cSrcweir 				else
544*cdf0e10cSrcweir 					xCol = xThisRoundCol;
545*cdf0e10cSrcweir 			}
546*cdf0e10cSrcweir 		}
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 		if (!xCol.is() || (bDateNTimeCol && !xSecondCol.is()))
549*cdf0e10cSrcweir 		{
550*cdf0e10cSrcweir 			::comphelper::disposeComponent(xCol);	// in case only the creation of the second column failed
551*cdf0e10cSrcweir 			::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
552*cdf0e10cSrcweir 			::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
553*cdf0e10cSrcweir 			return 0L;
554*cdf0e10cSrcweir 		}
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 		if (bDateNTimeCol)
557*cdf0e10cSrcweir 		{
558*cdf0e10cSrcweir             String sTimePostfix( SVX_RES( RID_STR_POSTFIX_TIME ) );
559*cdf0e10cSrcweir             xCol->setPropertyValue(FM_PROP_LABEL, makeAny( ::rtl::OUString( sFieldName + sTimePostfix ) ) );
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir             String sDatePostfix( SVX_RES( RID_STR_POSTFIX_DATE ) );
562*cdf0e10cSrcweir             xSecondCol->setPropertyValue(FM_PROP_LABEL, makeAny( ::rtl::OUString( sFieldName + sDatePostfix ) ) );
563*cdf0e10cSrcweir 		}
564*cdf0e10cSrcweir 		else
565*cdf0e10cSrcweir 			xCol->setPropertyValue(FM_PROP_LABEL, makeAny(sFieldName));
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir         FormControlFactory aControlFactory( ::comphelper::getProcessServiceFactory() );
568*cdf0e10cSrcweir         aControlFactory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xCol );
569*cdf0e10cSrcweir         aControlFactory.initializeFieldDependentProperties( xField, xCol, xNumberFormats );
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 		xCol->setPropertyValue(FM_PROP_CONTROLSOURCE, makeAny(sFieldName));
572*cdf0e10cSrcweir 		if ( xSecondCol.is() )
573*cdf0e10cSrcweir 			xSecondCol->setPropertyValue(FM_PROP_CONTROLSOURCE, makeAny(sFieldName));
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 		if (bDateNTimeCol)
576*cdf0e10cSrcweir 		{
577*cdf0e10cSrcweir 			String sRealName,sPurePostfix;
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir             String aPostfix[] = {
580*cdf0e10cSrcweir                 String( SVX_RES( RID_STR_POSTFIX_DATE ) ),
581*cdf0e10cSrcweir                 String( SVX_RES( RID_STR_POSTFIX_TIME ) )
582*cdf0e10cSrcweir             };
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 			for ( size_t i=0; i<2; ++i )
585*cdf0e10cSrcweir 			{
586*cdf0e10cSrcweir                 sPurePostfix = aPostfix[i];
587*cdf0e10cSrcweir 				sPurePostfix.EraseLeadingChars(' ');
588*cdf0e10cSrcweir 				sPurePostfix.EraseLeadingChars('(');
589*cdf0e10cSrcweir 				sPurePostfix.EraseTrailingChars(')');
590*cdf0e10cSrcweir 				sRealName = sFieldName;
591*cdf0e10cSrcweir 				sRealName += '_';
592*cdf0e10cSrcweir 				sRealName += sPurePostfix;
593*cdf0e10cSrcweir 				if (i)
594*cdf0e10cSrcweir 					xSecondCol->setPropertyValue(FM_PROP_NAME, makeAny(::rtl::OUString(sRealName)));
595*cdf0e10cSrcweir 				else
596*cdf0e10cSrcweir 					xCol->setPropertyValue(FM_PROP_NAME, makeAny(::rtl::OUString(sRealName)));
597*cdf0e10cSrcweir 			}
598*cdf0e10cSrcweir 		}
599*cdf0e10cSrcweir 		else
600*cdf0e10cSrcweir 			xCol->setPropertyValue(FM_PROP_NAME, makeAny(sFieldName));
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 		// jetzt einfuegen
603*cdf0e10cSrcweir 		Any aElement;
604*cdf0e10cSrcweir 		aElement <<= xCol;
605*cdf0e10cSrcweir 		xCols->insertByIndex(nPos, aElement);
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 		if (bDateNTimeCol)
608*cdf0e10cSrcweir 		{
609*cdf0e10cSrcweir 			aElement <<= xSecondCol;
610*cdf0e10cSrcweir 			xCols->insertByIndex(nPos == (sal_uInt16)-1 ? nPos : ++nPos, aElement);
611*cdf0e10cSrcweir 		}
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir 		// ist die component::Form an die Datenbankangebunden?
614*cdf0e10cSrcweir 		Reference< XFormComponent >  xFormCp(xCols, UNO_QUERY);
615*cdf0e10cSrcweir 		Reference< XPropertySet >  xForm(xFormCp->getParent(), UNO_QUERY);
616*cdf0e10cSrcweir 		if (xForm.is())
617*cdf0e10cSrcweir 		{
618*cdf0e10cSrcweir 			if (!::comphelper::getString(xForm->getPropertyValue(FM_PROP_DATASOURCE)).getLength())
619*cdf0e10cSrcweir 			{
620*cdf0e10cSrcweir 				if ( sDatasouce.getLength() )
621*cdf0e10cSrcweir 					xForm->setPropertyValue(FM_PROP_DATASOURCE, makeAny(sDatasouce));
622*cdf0e10cSrcweir 				else
623*cdf0e10cSrcweir 					xForm->setPropertyValue(FM_PROP_URL, makeAny(sURL));
624*cdf0e10cSrcweir 			}
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir 			if (!::comphelper::getString(xForm->getPropertyValue(FM_PROP_COMMAND)).getLength())
627*cdf0e10cSrcweir 			{
628*cdf0e10cSrcweir 				xForm->setPropertyValue(FM_PROP_COMMAND, makeAny(sCommand));
629*cdf0e10cSrcweir 				Any aCommandType;
630*cdf0e10cSrcweir 				switch (nCommandType)
631*cdf0e10cSrcweir 				{
632*cdf0e10cSrcweir 					case CommandType::TABLE:
633*cdf0e10cSrcweir 						aCommandType <<= (sal_Int32)CommandType::TABLE;
634*cdf0e10cSrcweir 						break;
635*cdf0e10cSrcweir 					case CommandType::QUERY:
636*cdf0e10cSrcweir 						aCommandType <<= (sal_Int32)CommandType::QUERY;
637*cdf0e10cSrcweir 						break;
638*cdf0e10cSrcweir 					default:
639*cdf0e10cSrcweir 						aCommandType <<= (sal_Int32)CommandType::COMMAND;
640*cdf0e10cSrcweir 						xForm->setPropertyValue(FM_PROP_ESCAPE_PROCESSING, bool2any((sal_Bool)(2 == nCommandType)));
641*cdf0e10cSrcweir 						break;
642*cdf0e10cSrcweir 				}
643*cdf0e10cSrcweir 				xForm->setPropertyValue(FM_PROP_COMMANDTYPE, aCommandType);
644*cdf0e10cSrcweir 			}
645*cdf0e10cSrcweir 		}
646*cdf0e10cSrcweir 	}
647*cdf0e10cSrcweir 	catch (Exception&)
648*cdf0e10cSrcweir 	{
649*cdf0e10cSrcweir 		DBG_ERROR("FmGridHeader::OnAsyncExecuteDrop: caught an exception while creatin' the column !");
650*cdf0e10cSrcweir 		::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
651*cdf0e10cSrcweir 		::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
652*cdf0e10cSrcweir 		return 0L;
653*cdf0e10cSrcweir 	}
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 	::comphelper::disposeComponent(m_pImpl->xDroppedResultSet);
656*cdf0e10cSrcweir 	::comphelper::disposeComponent(m_pImpl->xDroppedStatement);
657*cdf0e10cSrcweir 	return 1L;
658*cdf0e10cSrcweir }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir //------------------------------------------------------------------------------
661*cdf0e10cSrcweir void FmGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu)
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir 	sal_Bool bDesignMode = static_cast<FmGridControl*>(GetParent())->IsDesignMode();
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir 	Reference< ::com::sun::star::container::XIndexContainer >  xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
666*cdf0e10cSrcweir 	// Aufbau des Insert Menues
667*cdf0e10cSrcweir 	// mark the column if nColId != HEADERBAR_ITEM_NOTFOUND
668*cdf0e10cSrcweir 	if(nColId > 0)
669*cdf0e10cSrcweir 	{
670*cdf0e10cSrcweir 		sal_uInt16 nPos2 = GetModelColumnPos(nColId);
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 		Reference< ::com::sun::star::container::XIndexContainer >  xColumns(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
673*cdf0e10cSrcweir 		Reference< ::com::sun::star::beans::XPropertySet> xColumn;
674*cdf0e10cSrcweir 		::cppu::extractInterface(xColumn, xColumns->getByIndex(nPos2));
675*cdf0e10cSrcweir 		Reference< ::com::sun::star::view::XSelectionSupplier >  xSelSupplier(xColumns, UNO_QUERY);
676*cdf0e10cSrcweir 		if (xSelSupplier.is())
677*cdf0e10cSrcweir 			xSelSupplier->select(makeAny(xColumn));
678*cdf0e10cSrcweir 	}
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 	// EinfuegePosition, immer vor der aktuellen Spalte
681*cdf0e10cSrcweir 	sal_uInt16 nPos = GetModelColumnPos(nColId);
682*cdf0e10cSrcweir 	sal_Bool bMarked = nColId && static_cast<FmGridControl*>(GetParent())->isColumnMarked(nColId);
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir 	ImageList aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL) );
685*cdf0e10cSrcweir 	PopupMenu* pControlMenu = new PopupMenu;
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir 	PopupMenu* pMenu = rMenu.GetPopupMenu(SID_FM_INSERTCOL);
688*cdf0e10cSrcweir 	if (pMenu)
689*cdf0e10cSrcweir 	{
690*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_EDIT, pMenu, *pControlMenu, bDesignMode);
691*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_CHECKBOX, pMenu, *pControlMenu, bDesignMode);
692*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_COMBOBOX, pMenu, *pControlMenu, bDesignMode);
693*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_LISTBOX, pMenu, *pControlMenu, bDesignMode);
694*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_DATEFIELD, pMenu, *pControlMenu, bDesignMode);
695*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_TIMEFIELD, pMenu, *pControlMenu, bDesignMode);
696*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_NUMERICFIELD, pMenu, *pControlMenu, bDesignMode);
697*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_CURRENCYFIELD, pMenu, *pControlMenu, bDesignMode);
698*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_PATTERNFIELD, pMenu, *pControlMenu, bDesignMode);
699*cdf0e10cSrcweir 		SetMenuItem(aImageList, SID_FM_FORMATTEDFIELD, pMenu, *pControlMenu, bDesignMode);
700*cdf0e10cSrcweir 	}
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 	if (pMenu && xCols.is() && nColId)
703*cdf0e10cSrcweir 	{
704*cdf0e10cSrcweir 		Reference< ::com::sun::star::beans::XPropertySet > xSet;
705*cdf0e10cSrcweir 		::cppu::extractInterface(xSet, xCols->getByIndex(nPos));
706*cdf0e10cSrcweir 		sal_Int16 nClassId;
707*cdf0e10cSrcweir 		xSet->getPropertyValue(FM_PROP_CLASSID) >>= nClassId;
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir 		Reference< ::com::sun::star::io::XPersistObject >  xServiceQuestion(xSet, UNO_QUERY);
710*cdf0e10cSrcweir 		sal_Int32 nColType = xServiceQuestion.is() ? getColumnTypeByModelName(xServiceQuestion->getServiceName()) : 0;
711*cdf0e10cSrcweir 		if (nColType == TYPE_TEXTFIELD)
712*cdf0e10cSrcweir 		{	// edit fields and formatted fields have the same service name, thus getColumnTypeByModelName returns TYPE_TEXTFIELD
713*cdf0e10cSrcweir 			// in both cases. And as columns don't have an ::com::sun::star::lang::XServiceInfo interface, we have to distinguish both
714*cdf0e10cSrcweir 			// types via the existence of special properties
715*cdf0e10cSrcweir 			Reference< ::com::sun::star::beans::XPropertySet >	xProps(xSet, UNO_QUERY);
716*cdf0e10cSrcweir 			if (xProps.is())
717*cdf0e10cSrcweir 			{
718*cdf0e10cSrcweir 				Reference< ::com::sun::star::beans::XPropertySetInfo >	xPropsInfo = xProps->getPropertySetInfo();
719*cdf0e10cSrcweir 				if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(FM_PROP_FORMATSSUPPLIER))
720*cdf0e10cSrcweir 					nColType = TYPE_FORMATTEDFIELD;
721*cdf0e10cSrcweir 			}
722*cdf0e10cSrcweir 		}
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_EDIT + nChangeTypeOffset, bDesignMode && (nColType != TYPE_TEXTFIELD));
725*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_COMBOBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_COMBOBOX));
726*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_LISTBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_LISTBOX));
727*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_CHECKBOX + nChangeTypeOffset, bDesignMode && (nColType != TYPE_CHECKBOX));
728*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_DATEFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_DATEFIELD));
729*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_NUMERICFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_NUMERICFIELD));
730*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_TIMEFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_TIMEFIELD));
731*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_CURRENCYFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_CURRENCYFIELD));
732*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_PATTERNFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_PATTERNFIELD));
733*cdf0e10cSrcweir 		pControlMenu->EnableItem(SID_FM_FORMATTEDFIELD + nChangeTypeOffset, bDesignMode && (nColType != TYPE_FORMATTEDFIELD));
734*cdf0e10cSrcweir 		rMenu.SetPopupMenu(SID_FM_CHANGECOL, pControlMenu);
735*cdf0e10cSrcweir 	}
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir 	rMenu.EnableItem(SID_FM_INSERTCOL, bDesignMode && xCols.is());
738*cdf0e10cSrcweir 	rMenu.EnableItem(SID_FM_DELETECOL, bDesignMode && bMarked && xCols.is());
739*cdf0e10cSrcweir 	rMenu.EnableItem(SID_FM_CHANGECOL, bDesignMode && bMarked && xCols.is());
740*cdf0e10cSrcweir 	rMenu.EnableItem(SID_FM_SHOW_PROPERTY_BROWSER, bDesignMode && bMarked && xCols.is());
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir 	PopupMenu* pShowColsMenu = rMenu.GetPopupMenu(SID_FM_SHOWCOLS);
743*cdf0e10cSrcweir 	sal_uInt16 nHiddenCols = 0;
744*cdf0e10cSrcweir 	if (pShowColsMenu)
745*cdf0e10cSrcweir 	{
746*cdf0e10cSrcweir 		if (xCols.is())
747*cdf0e10cSrcweir 		{
748*cdf0e10cSrcweir 			// check for hidden cols
749*cdf0e10cSrcweir 			Reference< ::com::sun::star::beans::XPropertySet >	xCurCol;
750*cdf0e10cSrcweir 			Any aHidden,aName;
751*cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
752*cdf0e10cSrcweir 			{
753*cdf0e10cSrcweir 				::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
754*cdf0e10cSrcweir 				DBG_ASSERT(xCurCol.is(), "FmGridHeader::PreExecuteColumnContextMenu : the Peer has invalid columns !");
755*cdf0e10cSrcweir 				aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN);
756*cdf0e10cSrcweir 				DBG_ASSERT(aHidden.getValueType().getTypeClass() == TypeClass_BOOLEAN,
757*cdf0e10cSrcweir 					"FmGridHeader::PreExecuteColumnContextMenu : the property 'hidden' should be boolean !");
758*cdf0e10cSrcweir 				if (::comphelper::getBOOL(aHidden))
759*cdf0e10cSrcweir 				{
760*cdf0e10cSrcweir 					// put the column name into the 'show col' menu
761*cdf0e10cSrcweir 					if (nHiddenCols < 16)
762*cdf0e10cSrcweir 					{	// (only the first 16 items to keep the menu rather small)
763*cdf0e10cSrcweir 						aName = xCurCol->getPropertyValue(FM_PROP_LABEL);
764*cdf0e10cSrcweir 						pShowColsMenu->InsertItem(nHiddenCols + 1, ::comphelper::getString(aName), 0, nHiddenCols);
765*cdf0e10cSrcweir 							// the ID is arbitrary, but should be unique within the whole menu
766*cdf0e10cSrcweir 					}
767*cdf0e10cSrcweir 					++nHiddenCols;
768*cdf0e10cSrcweir 				}
769*cdf0e10cSrcweir 			}
770*cdf0e10cSrcweir 		}
771*cdf0e10cSrcweir 		pShowColsMenu->EnableItem(SID_FM_SHOWCOLS_MORE, xCols.is() && (nHiddenCols > 16));
772*cdf0e10cSrcweir 		pShowColsMenu->EnableItem(SID_FM_SHOWALLCOLS, xCols.is() && (nHiddenCols > 0));
773*cdf0e10cSrcweir 	}
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir 	// allow the 'hide column' item ?
776*cdf0e10cSrcweir 	sal_Bool bAllowHide = bMarked;											// a column is marked
777*cdf0e10cSrcweir 	bAllowHide = bAllowHide || (!bDesignMode && (nPos != (sal_uInt16)-1));	// OR we are in alive mode and have hit a column
778*cdf0e10cSrcweir 	bAllowHide = bAllowHide && xCols.is();								// AND we have a column container
779*cdf0e10cSrcweir 	bAllowHide = bAllowHide && (xCols->getCount()-nHiddenCols > 1); 	// AND there are at least two visible columns
780*cdf0e10cSrcweir 	rMenu.EnableItem(SID_FM_HIDECOL,  bAllowHide);
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir 	sal_Bool bChecked = sal_False;
783*cdf0e10cSrcweir 	if (bMarked)
784*cdf0e10cSrcweir 	{
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir 		SfxViewFrame* pCurrentFrame = SfxViewFrame::Current();
787*cdf0e10cSrcweir 		SfxItemState eState = SFX_ITEM_UNKNOWN;
788*cdf0e10cSrcweir 		// ask the bindings of the current view frame (which should be the one we're residing in) for the state
789*cdf0e10cSrcweir 		if (pCurrentFrame)
790*cdf0e10cSrcweir 		{
791*cdf0e10cSrcweir 			SfxPoolItem* pItem = NULL;
792*cdf0e10cSrcweir 			eState = pCurrentFrame->GetBindings().QueryState(SID_FM_CTL_PROPERTIES, pItem);
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir 			if (eState >= SFX_ITEM_AVAILABLE && pItem )
795*cdf0e10cSrcweir 			{
796*cdf0e10cSrcweir 				bChecked = pItem->ISA(SfxBoolItem) && ((SfxBoolItem*)pItem)->GetValue();
797*cdf0e10cSrcweir 				rMenu.CheckItem(SID_FM_SHOW_PROPERTY_BROWSER,bChecked);
798*cdf0e10cSrcweir 			}
799*cdf0e10cSrcweir 			delete pItem;
800*cdf0e10cSrcweir 		}
801*cdf0e10cSrcweir 	}
802*cdf0e10cSrcweir }
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir enum InspectorAction { eOpenInspector, eCloseInspector, eUpdateInspector, eNone };
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir //------------------------------------------------------------------------------
807*cdf0e10cSrcweir void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
808*cdf0e10cSrcweir {
809*cdf0e10cSrcweir 	Reference< ::com::sun::star::container::XIndexContainer >  xCols(static_cast<FmGridControl*>(GetParent())->GetPeer()->getColumns());
810*cdf0e10cSrcweir 	sal_uInt16 nPos = GetModelColumnPos(nColId);
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir 	// remove and delet the menu we inserted in PreExecuteColumnContextMenu
813*cdf0e10cSrcweir 	PopupMenu* pControlMenu = rMenu.GetPopupMenu(SID_FM_CHANGECOL);
814*cdf0e10cSrcweir 	delete pControlMenu;
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir 	::rtl::OUString aFieldType;
817*cdf0e10cSrcweir 	sal_Bool	bReplace = sal_False;
818*cdf0e10cSrcweir     InspectorAction eInspectorAction = eNone;
819*cdf0e10cSrcweir     Reference< XPropertySet > xColumnToInspect;
820*cdf0e10cSrcweir 	switch (nExecutionResult)
821*cdf0e10cSrcweir 	{
822*cdf0e10cSrcweir 		case SID_FM_DELETECOL:
823*cdf0e10cSrcweir 		{
824*cdf0e10cSrcweir 			Reference< XInterface >  xCol;
825*cdf0e10cSrcweir 			::cppu::extractInterface(xCol, xCols->getByIndex(nPos));
826*cdf0e10cSrcweir 			xCols->removeByIndex(nPos);
827*cdf0e10cSrcweir 			::comphelper::disposeComponent(xCol);
828*cdf0e10cSrcweir 		}	break;
829*cdf0e10cSrcweir 		case SID_FM_SHOW_PROPERTY_BROWSER:
830*cdf0e10cSrcweir             eInspectorAction = rMenu.IsItemChecked( SID_FM_SHOW_PROPERTY_BROWSER ) ? eOpenInspector : eCloseInspector;
831*cdf0e10cSrcweir             xColumnToInspect.set( xCols->getByIndex( nPos ), UNO_QUERY );
832*cdf0e10cSrcweir             break;
833*cdf0e10cSrcweir 		case SID_FM_EDIT + nChangeTypeOffset:
834*cdf0e10cSrcweir 			bReplace = sal_True;
835*cdf0e10cSrcweir 		case SID_FM_EDIT:
836*cdf0e10cSrcweir 			aFieldType = FM_COL_TEXTFIELD;
837*cdf0e10cSrcweir 			break;
838*cdf0e10cSrcweir 		case SID_FM_COMBOBOX + nChangeTypeOffset:
839*cdf0e10cSrcweir 			bReplace = sal_True;
840*cdf0e10cSrcweir 		case SID_FM_COMBOBOX:
841*cdf0e10cSrcweir 			aFieldType = FM_COL_COMBOBOX;
842*cdf0e10cSrcweir 			break;
843*cdf0e10cSrcweir 		case SID_FM_LISTBOX + nChangeTypeOffset:
844*cdf0e10cSrcweir 			bReplace = sal_True;
845*cdf0e10cSrcweir 		case SID_FM_LISTBOX:
846*cdf0e10cSrcweir 			aFieldType = FM_COL_LISTBOX;
847*cdf0e10cSrcweir 			break;
848*cdf0e10cSrcweir 		case SID_FM_CHECKBOX + nChangeTypeOffset:
849*cdf0e10cSrcweir 			bReplace = sal_True;
850*cdf0e10cSrcweir 		case SID_FM_CHECKBOX:
851*cdf0e10cSrcweir 			aFieldType = FM_COL_CHECKBOX;
852*cdf0e10cSrcweir 			break;
853*cdf0e10cSrcweir 		case SID_FM_DATEFIELD + nChangeTypeOffset:
854*cdf0e10cSrcweir 			bReplace = sal_True;
855*cdf0e10cSrcweir 		case SID_FM_DATEFIELD:
856*cdf0e10cSrcweir 			aFieldType = FM_COL_DATEFIELD;
857*cdf0e10cSrcweir 			break;
858*cdf0e10cSrcweir 		case SID_FM_TIMEFIELD + nChangeTypeOffset:
859*cdf0e10cSrcweir 			bReplace = sal_True;
860*cdf0e10cSrcweir 		case SID_FM_TIMEFIELD:
861*cdf0e10cSrcweir 			aFieldType = FM_COL_TIMEFIELD;
862*cdf0e10cSrcweir 			break;
863*cdf0e10cSrcweir 		case SID_FM_NUMERICFIELD + nChangeTypeOffset:
864*cdf0e10cSrcweir 			bReplace = sal_True;
865*cdf0e10cSrcweir 		case SID_FM_NUMERICFIELD:
866*cdf0e10cSrcweir 			aFieldType = FM_COL_NUMERICFIELD;
867*cdf0e10cSrcweir 			break;
868*cdf0e10cSrcweir 		case SID_FM_CURRENCYFIELD + nChangeTypeOffset:
869*cdf0e10cSrcweir 			bReplace = sal_True;
870*cdf0e10cSrcweir 		case SID_FM_CURRENCYFIELD:
871*cdf0e10cSrcweir 			aFieldType = FM_COL_CURRENCYFIELD;
872*cdf0e10cSrcweir 			break;
873*cdf0e10cSrcweir 		case SID_FM_PATTERNFIELD + nChangeTypeOffset:
874*cdf0e10cSrcweir 			bReplace = sal_True;
875*cdf0e10cSrcweir 		case SID_FM_PATTERNFIELD:
876*cdf0e10cSrcweir 			aFieldType = FM_COL_PATTERNFIELD;
877*cdf0e10cSrcweir 			break;
878*cdf0e10cSrcweir 		case SID_FM_FORMATTEDFIELD + nChangeTypeOffset:
879*cdf0e10cSrcweir 			bReplace = sal_True;
880*cdf0e10cSrcweir 		case SID_FM_FORMATTEDFIELD:
881*cdf0e10cSrcweir 			aFieldType = FM_COL_FORMATTEDFIELD;
882*cdf0e10cSrcweir 			break;
883*cdf0e10cSrcweir 		case SID_FM_HIDECOL:
884*cdf0e10cSrcweir 		{
885*cdf0e10cSrcweir 			Reference< ::com::sun::star::beans::XPropertySet >	xCurCol;
886*cdf0e10cSrcweir 			::cppu::extractInterface(xCurCol, xCols->getByIndex(nPos));
887*cdf0e10cSrcweir 			xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_True));
888*cdf0e10cSrcweir 		}
889*cdf0e10cSrcweir 		break;
890*cdf0e10cSrcweir 		case SID_FM_SHOWCOLS_MORE:
891*cdf0e10cSrcweir 		{
892*cdf0e10cSrcweir 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
893*cdf0e10cSrcweir 			if(pFact)
894*cdf0e10cSrcweir 			{
895*cdf0e10cSrcweir 				AbstractFmShowColsDialog* pDlg = pFact->CreateFmShowColsDialog(NULL);
896*cdf0e10cSrcweir 				DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
897*cdf0e10cSrcweir 				pDlg->SetColumns(xCols);
898*cdf0e10cSrcweir 				pDlg->Execute();
899*cdf0e10cSrcweir 				delete pDlg;
900*cdf0e10cSrcweir 			}
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir 		}
903*cdf0e10cSrcweir 		break;
904*cdf0e10cSrcweir 		case SID_FM_SHOWALLCOLS:
905*cdf0e10cSrcweir 		{
906*cdf0e10cSrcweir 			// just iterate through all the cols ...
907*cdf0e10cSrcweir 			Reference< ::com::sun::star::beans::XPropertySet >	xCurCol;
908*cdf0e10cSrcweir 			for (sal_uInt16 i=0; i<xCols->getCount(); ++i)
909*cdf0e10cSrcweir 			{
910*cdf0e10cSrcweir 				::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
911*cdf0e10cSrcweir 				xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_False));
912*cdf0e10cSrcweir 			}
913*cdf0e10cSrcweir 			// TODO : there must be a more clever way to do this ....
914*cdf0e10cSrcweir 			// with the above the view is updated after every single model update ...
915*cdf0e10cSrcweir 		}
916*cdf0e10cSrcweir 		break;
917*cdf0e10cSrcweir 		default:
918*cdf0e10cSrcweir 			if (nExecutionResult>0 && nExecutionResult<=16)
919*cdf0e10cSrcweir 			{	// it was a "show column/<colname>" command (there are at most 16 such items)
920*cdf0e10cSrcweir 				// search the nExecutionResult'th hidden col
921*cdf0e10cSrcweir 				Reference< ::com::sun::star::beans::XPropertySet >	xCurCol;
922*cdf0e10cSrcweir 				for (sal_uInt16 i=0; i<xCols->getCount() && nExecutionResult; ++i)
923*cdf0e10cSrcweir 				{
924*cdf0e10cSrcweir 					::cppu::extractInterface(xCurCol, xCols->getByIndex(i));
925*cdf0e10cSrcweir 					Any aHidden = xCurCol->getPropertyValue(FM_PROP_HIDDEN);
926*cdf0e10cSrcweir 					if (::comphelper::getBOOL(aHidden))
927*cdf0e10cSrcweir 						if (!--nExecutionResult)
928*cdf0e10cSrcweir 						{
929*cdf0e10cSrcweir 							xCurCol->setPropertyValue(FM_PROP_HIDDEN, makeAny((sal_Bool)sal_False));
930*cdf0e10cSrcweir 							break;
931*cdf0e10cSrcweir 						}
932*cdf0e10cSrcweir 				}
933*cdf0e10cSrcweir 			}
934*cdf0e10cSrcweir 			break;
935*cdf0e10cSrcweir 	}
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir 	if ( aFieldType.getLength() )
938*cdf0e10cSrcweir 	{
939*cdf0e10cSrcweir         try
940*cdf0e10cSrcweir         {
941*cdf0e10cSrcweir             Reference< XGridColumnFactory > xFactory( xCols, UNO_QUERY_THROW );
942*cdf0e10cSrcweir             Reference< XPropertySet > xNewCol( xFactory->createColumn( aFieldType ), UNO_SET_THROW );
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir             if ( bReplace )
945*cdf0e10cSrcweir             {
946*cdf0e10cSrcweir                 // ein paar Properties hinueberretten
947*cdf0e10cSrcweir                 Reference< XPropertySet > xReplaced( xCols->getByIndex( nPos ), UNO_QUERY );
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir                 OStaticDataAccessTools().TransferFormComponentProperties(
950*cdf0e10cSrcweir                     xReplaced, xNewCol, Application::GetSettings().GetUILocale() );
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir                 xCols->replaceByIndex( nPos, makeAny( xNewCol ) );
953*cdf0e10cSrcweir                 ::comphelper::disposeComponent( xReplaced );
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir                 eInspectorAction = eUpdateInspector;
956*cdf0e10cSrcweir                 xColumnToInspect = xNewCol;
957*cdf0e10cSrcweir             }
958*cdf0e10cSrcweir             else
959*cdf0e10cSrcweir             {
960*cdf0e10cSrcweir                 FormControlFactory factory( ::comphelper::getProcessServiceFactory() );
961*cdf0e10cSrcweir 
962*cdf0e10cSrcweir                 ::rtl::OUString sLabel = factory.getDefaultUniqueName_ByComponentType(
963*cdf0e10cSrcweir                     Reference< XNameAccess >( xCols, UNO_QUERY_THROW ), xNewCol );
964*cdf0e10cSrcweir                 xNewCol->setPropertyValue( FM_PROP_LABEL, makeAny( sLabel ) );
965*cdf0e10cSrcweir                 xNewCol->setPropertyValue( FM_PROP_NAME, makeAny( sLabel ) );
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir                 factory.initializeControlModel( DocumentClassification::classifyHostDocument( xCols ), xNewCol );
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir                 xCols->insertByIndex( nPos, makeAny( xNewCol ) );
970*cdf0e10cSrcweir             }
971*cdf0e10cSrcweir         }
972*cdf0e10cSrcweir         catch( const Exception& )
973*cdf0e10cSrcweir         {
974*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
975*cdf0e10cSrcweir         }
976*cdf0e10cSrcweir 	}
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir     SfxViewFrame* pCurrentFrame = SfxViewFrame::Current();
979*cdf0e10cSrcweir     OSL_ENSURE( pCurrentFrame, "FmGridHeader::PostExecuteColumnContextMenu: no view frame -> no bindings -> no property browser!" );
980*cdf0e10cSrcweir     if ( pCurrentFrame )
981*cdf0e10cSrcweir     {
982*cdf0e10cSrcweir         if ( eInspectorAction == eUpdateInspector )
983*cdf0e10cSrcweir         {
984*cdf0e10cSrcweir             if ( !pCurrentFrame->HasChildWindow( SID_FM_SHOW_PROPERTIES ) )
985*cdf0e10cSrcweir                 eInspectorAction = eNone;
986*cdf0e10cSrcweir         }
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir         if ( eInspectorAction != eNone )
989*cdf0e10cSrcweir         {
990*cdf0e10cSrcweir             FmInterfaceItem aIFaceItem( SID_FM_SHOW_PROPERTY_BROWSER, xColumnToInspect );
991*cdf0e10cSrcweir             SfxBoolItem aShowItem( SID_FM_SHOW_PROPERTIES, eInspectorAction == eCloseInspector ? sal_False : sal_True );
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir             pCurrentFrame->GetBindings().GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON,
994*cdf0e10cSrcweir                                       &aIFaceItem, &aShowItem, 0L );
995*cdf0e10cSrcweir         }
996*cdf0e10cSrcweir     }
997*cdf0e10cSrcweir }
998*cdf0e10cSrcweir 
999*cdf0e10cSrcweir //------------------------------------------------------------------------------
1000*cdf0e10cSrcweir void FmGridHeader::triggerColumnContextMenu( const ::Point& _rPreferredPos )
1001*cdf0e10cSrcweir {
1002*cdf0e10cSrcweir 	// the affected col
1003*cdf0e10cSrcweir 	sal_uInt16 nColId = GetItemId( _rPreferredPos );
1004*cdf0e10cSrcweir 
1005*cdf0e10cSrcweir 	// the menu
1006*cdf0e10cSrcweir 	PopupMenu aContextMenu( SVX_RES( RID_SVXMNU_COLS ) );
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir 	// let derivees modify the menu
1009*cdf0e10cSrcweir 	PreExecuteColumnContextMenu( nColId, aContextMenu );
1010*cdf0e10cSrcweir 	aContextMenu.RemoveDisabledEntries( sal_True, sal_True );
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir 	// execute the menu
1013*cdf0e10cSrcweir 	sal_uInt16 nResult = aContextMenu.Execute( this, _rPreferredPos );
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir 	// let derivees handle the result
1016*cdf0e10cSrcweir 	PostExecuteColumnContextMenu( nColId, aContextMenu, nResult );
1017*cdf0e10cSrcweir }
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir //------------------------------------------------------------------------------
1020*cdf0e10cSrcweir void FmGridHeader::Command(const CommandEvent& rEvt)
1021*cdf0e10cSrcweir {
1022*cdf0e10cSrcweir 	switch (rEvt.GetCommand())
1023*cdf0e10cSrcweir 	{
1024*cdf0e10cSrcweir 		case COMMAND_CONTEXTMENU:
1025*cdf0e10cSrcweir 		{
1026*cdf0e10cSrcweir 			if (!rEvt.IsMouseEvent())
1027*cdf0e10cSrcweir 				return;
1028*cdf0e10cSrcweir 
1029*cdf0e10cSrcweir 			triggerColumnContextMenu( rEvt.GetMousePosPixel() );
1030*cdf0e10cSrcweir 		}
1031*cdf0e10cSrcweir 		break;
1032*cdf0e10cSrcweir 		default:
1033*cdf0e10cSrcweir 			EditBrowserHeader::Command(rEvt);
1034*cdf0e10cSrcweir 	}
1035*cdf0e10cSrcweir }
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir //------------------------------------------------------------------------------
1038*cdf0e10cSrcweir FmGridControl::FmGridControl(
1039*cdf0e10cSrcweir 				Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxFactory,
1040*cdf0e10cSrcweir 				Window* pParent,
1041*cdf0e10cSrcweir 				FmXGridPeer* _pPeer,
1042*cdf0e10cSrcweir 				WinBits nBits)
1043*cdf0e10cSrcweir 		:DbGridControl(_rxFactory, pParent, nBits)
1044*cdf0e10cSrcweir         ,m_pPeer(_pPeer)
1045*cdf0e10cSrcweir         ,m_nCurrentSelectedColumn(-1)
1046*cdf0e10cSrcweir 		,m_nMarkedColumnId(BROWSER_INVALIDID)
1047*cdf0e10cSrcweir         ,m_bSelecting(sal_False)
1048*cdf0e10cSrcweir         ,m_bInColumnMove(sal_False)
1049*cdf0e10cSrcweir {
1050*cdf0e10cSrcweir     EnableInteractiveRowHeight( );
1051*cdf0e10cSrcweir }
1052*cdf0e10cSrcweir 
1053*cdf0e10cSrcweir //------------------------------------------------------------------------------
1054*cdf0e10cSrcweir void FmGridControl::Command(const CommandEvent& _rEvt)
1055*cdf0e10cSrcweir {
1056*cdf0e10cSrcweir 	if ( COMMAND_CONTEXTMENU == _rEvt.GetCommand() )
1057*cdf0e10cSrcweir 	{
1058*cdf0e10cSrcweir 		FmGridHeader* pMyHeader = static_cast< FmGridHeader* >( GetHeaderBar() );
1059*cdf0e10cSrcweir         if ( pMyHeader && !_rEvt.IsMouseEvent() )
1060*cdf0e10cSrcweir 		{	// context menu requested by keyboard
1061*cdf0e10cSrcweir 			if	( 1 == GetSelectColumnCount() || IsDesignMode() )
1062*cdf0e10cSrcweir 			{
1063*cdf0e10cSrcweir 				sal_uInt16 nSelId = GetColumnId(
1064*cdf0e10cSrcweir                     sal::static_int_cast< sal_uInt16 >( FirstSelectedColumn() ) );
1065*cdf0e10cSrcweir 				::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, sal_False ) );
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir                 Point aRelativePos( pMyHeader->ScreenToOutputPixel( OutputToScreenPixel( aColRect.TopCenter() ) ) );
1068*cdf0e10cSrcweir                 pMyHeader->triggerColumnContextMenu( aRelativePos, FmGridHeader::AccessControl() );
1069*cdf0e10cSrcweir 
1070*cdf0e10cSrcweir 				// handled
1071*cdf0e10cSrcweir 				return;
1072*cdf0e10cSrcweir 			}
1073*cdf0e10cSrcweir 		}
1074*cdf0e10cSrcweir 	}
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir 	DbGridControl::Command( _rEvt );
1077*cdf0e10cSrcweir }
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir // ::com::sun::star::beans::XPropertyChangeListener
1080*cdf0e10cSrcweir //------------------------------------------------------------------------------
1081*cdf0e10cSrcweir void FmGridControl::propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt)
1082*cdf0e10cSrcweir {
1083*cdf0e10cSrcweir 	if (evt.PropertyName == FM_PROP_ROWCOUNT)
1084*cdf0e10cSrcweir 	{
1085*cdf0e10cSrcweir 		// if we're not in the main thread call AdjustRows asynchronously
1086*cdf0e10cSrcweir 		implAdjustInSolarThread(sal_True);
1087*cdf0e10cSrcweir 		return;
1088*cdf0e10cSrcweir 	}
1089*cdf0e10cSrcweir 
1090*cdf0e10cSrcweir 	const DbGridRowRef& xRow = GetCurrentRow();
1091*cdf0e10cSrcweir 	// waehrend Positionierung wird kein abgleich  der Properties vorgenommen
1092*cdf0e10cSrcweir 	Reference<XPropertySet> xSet(evt.Source,UNO_QUERY);
1093*cdf0e10cSrcweir 	if (xRow.Is() && (::cppu::any2bool(xSet->getPropertyValue(FM_PROP_ISNEW))|| CompareBookmark(getDataSource()->getBookmark(), xRow->GetBookmark())))
1094*cdf0e10cSrcweir 	{
1095*cdf0e10cSrcweir 		if (evt.PropertyName == FM_PROP_ISMODIFIED)
1096*cdf0e10cSrcweir 		{
1097*cdf0e10cSrcweir 			// modified or clean ?
1098*cdf0e10cSrcweir 			GridRowStatus eStatus = ::comphelper::getBOOL(evt.NewValue) ? GRS_MODIFIED : GRS_CLEAN;
1099*cdf0e10cSrcweir 			if (eStatus != xRow->GetStatus())
1100*cdf0e10cSrcweir 			{
1101*cdf0e10cSrcweir 				xRow->SetStatus(eStatus);
1102*cdf0e10cSrcweir 				vos::OGuard aGuard( Application::GetSolarMutex() );
1103*cdf0e10cSrcweir 				RowModified(GetCurrentPos());
1104*cdf0e10cSrcweir 			}
1105*cdf0e10cSrcweir 		}
1106*cdf0e10cSrcweir 	}
1107*cdf0e10cSrcweir }
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir //------------------------------------------------------------------------------
1110*cdf0e10cSrcweir void FmGridControl::SetDesignMode(sal_Bool bMode)
1111*cdf0e10cSrcweir {
1112*cdf0e10cSrcweir 	sal_Bool bOldMode = IsDesignMode();
1113*cdf0e10cSrcweir 	DbGridControl::SetDesignMode(bMode);
1114*cdf0e10cSrcweir 	if (bOldMode != bMode)
1115*cdf0e10cSrcweir 	{
1116*cdf0e10cSrcweir 		if (!bMode)
1117*cdf0e10cSrcweir 		{
1118*cdf0e10cSrcweir 			// selection aufheben
1119*cdf0e10cSrcweir 			markColumn(USHRT_MAX);
1120*cdf0e10cSrcweir 		}
1121*cdf0e10cSrcweir 		else
1122*cdf0e10cSrcweir 		{
1123*cdf0e10cSrcweir 			Reference< ::com::sun::star::container::XIndexContainer >  xColumns(GetPeer()->getColumns());
1124*cdf0e10cSrcweir 			Reference< ::com::sun::star::view::XSelectionSupplier >  xSelSupplier(xColumns, UNO_QUERY);
1125*cdf0e10cSrcweir 			if (xSelSupplier.is())
1126*cdf0e10cSrcweir 			{
1127*cdf0e10cSrcweir 				Any aSelection = xSelSupplier->getSelection();
1128*cdf0e10cSrcweir 				Reference< ::com::sun::star::beans::XPropertySet >	xColumn;
1129*cdf0e10cSrcweir 				if (aSelection.getValueType().getTypeClass() == TypeClass_INTERFACE)
1130*cdf0e10cSrcweir 					::cppu::extractInterface(xColumn, aSelection);
1131*cdf0e10cSrcweir 				Reference< XInterface >  xCurrent;
1132*cdf0e10cSrcweir 				for (sal_uInt16 i=0; i<xColumns->getCount(); ++i)
1133*cdf0e10cSrcweir 				{
1134*cdf0e10cSrcweir 					::cppu::extractInterface(xCurrent, xColumns->getByIndex(i));
1135*cdf0e10cSrcweir 					if (xCurrent == xColumn)
1136*cdf0e10cSrcweir 					{
1137*cdf0e10cSrcweir 						markColumn(GetColumnIdFromModelPos(i));
1138*cdf0e10cSrcweir 						break;
1139*cdf0e10cSrcweir 					}
1140*cdf0e10cSrcweir 				}
1141*cdf0e10cSrcweir 			}
1142*cdf0e10cSrcweir 		}
1143*cdf0e10cSrcweir 	}
1144*cdf0e10cSrcweir }
1145*cdf0e10cSrcweir 
1146*cdf0e10cSrcweir //------------------------------------------------------------------------------
1147*cdf0e10cSrcweir void FmGridControl::DeleteSelectedRows()
1148*cdf0e10cSrcweir {
1149*cdf0e10cSrcweir 	if (!m_pSeekCursor)
1150*cdf0e10cSrcweir 		return;
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir 	// how many rows are selected?
1153*cdf0e10cSrcweir 	sal_Int32 nSelectedRows = GetSelectRowCount();
1154*cdf0e10cSrcweir 
1155*cdf0e10cSrcweir     // the current line should be deleted but it is currently in edit mode
1156*cdf0e10cSrcweir 	if ( IsCurrentAppending() )
1157*cdf0e10cSrcweir         return;
1158*cdf0e10cSrcweir     // is the insert row selected
1159*cdf0e10cSrcweir 	if (GetEmptyRow().Is() && IsRowSelected(GetRowCount() - 1))
1160*cdf0e10cSrcweir 		nSelectedRows -= 1;
1161*cdf0e10cSrcweir 
1162*cdf0e10cSrcweir 	// nothing to do
1163*cdf0e10cSrcweir 	if (nSelectedRows <= 0)
1164*cdf0e10cSrcweir 		return;
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 	// try to confirm the delete
1167*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatchProvider >  xDispatcher = (::com::sun::star::frame::XDispatchProvider*)GetPeer();
1168*cdf0e10cSrcweir 	if (xDispatcher.is())
1169*cdf0e10cSrcweir 	{
1170*cdf0e10cSrcweir 		::com::sun::star::util::URL aUrl;
1171*cdf0e10cSrcweir 		aUrl.Complete = FMURL_CONFIRM_DELETION;
1172*cdf0e10cSrcweir 		// #100312# ------------
1173*cdf0e10cSrcweir 		Reference< ::com::sun::star::util::XURLTransformer > xTransformer(
1174*cdf0e10cSrcweir 			::comphelper::getProcessServiceFactory()->createInstance(
1175*cdf0e10cSrcweir 			::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")), UNO_QUERY);
1176*cdf0e10cSrcweir 		if( xTransformer.is() )
1177*cdf0e10cSrcweir 			xTransformer->parseStrict( aUrl );
1178*cdf0e10cSrcweir 
1179*cdf0e10cSrcweir 		Reference< ::com::sun::star::frame::XDispatch >  xDispatch = xDispatcher->queryDispatch(aUrl, rtl::OUString(), 0);
1180*cdf0e10cSrcweir 		Reference< ::com::sun::star::form::XConfirmDeleteListener >  xConfirm(xDispatch, UNO_QUERY);
1181*cdf0e10cSrcweir 		if (xConfirm.is())
1182*cdf0e10cSrcweir 		{
1183*cdf0e10cSrcweir 			::com::sun::star::sdb::RowChangeEvent aEvent;
1184*cdf0e10cSrcweir 			aEvent.Source = (Reference< XInterface > )(*getDataSource());
1185*cdf0e10cSrcweir 			aEvent.Rows = nSelectedRows;
1186*cdf0e10cSrcweir 			aEvent.Action = ::com::sun::star::sdb::RowChangeAction::DELETE;
1187*cdf0e10cSrcweir 			if (!xConfirm->confirmDelete(aEvent))
1188*cdf0e10cSrcweir 				return;
1189*cdf0e10cSrcweir 		}
1190*cdf0e10cSrcweir 	}
1191*cdf0e10cSrcweir 
1192*cdf0e10cSrcweir 	const MultiSelection* pRowSelection = GetSelection();
1193*cdf0e10cSrcweir 	if ( pRowSelection && pRowSelection->IsAllSelected() )
1194*cdf0e10cSrcweir 	{
1195*cdf0e10cSrcweir 		BeginCursorAction();
1196*cdf0e10cSrcweir 		CursorWrapper* pCursor = getDataSource();
1197*cdf0e10cSrcweir 		Reference< XResultSetUpdate >  xUpdateCursor((Reference< XInterface >)*pCursor, UNO_QUERY);
1198*cdf0e10cSrcweir 		try
1199*cdf0e10cSrcweir 		{
1200*cdf0e10cSrcweir 			pCursor->beforeFirst();
1201*cdf0e10cSrcweir 			while( pCursor->next() )
1202*cdf0e10cSrcweir 				xUpdateCursor->deleteRow();
1203*cdf0e10cSrcweir 
1204*cdf0e10cSrcweir 			SetUpdateMode(sal_False);
1205*cdf0e10cSrcweir 			SetNoSelection();
1206*cdf0e10cSrcweir 
1207*cdf0e10cSrcweir 			xUpdateCursor->moveToInsertRow();
1208*cdf0e10cSrcweir 		}
1209*cdf0e10cSrcweir 		catch(const Exception&)
1210*cdf0e10cSrcweir 		{
1211*cdf0e10cSrcweir 			OSL_ENSURE(0,"Exception caught while deleting rows!");
1212*cdf0e10cSrcweir 		}
1213*cdf0e10cSrcweir 		// An den DatenCursor anpassen
1214*cdf0e10cSrcweir 		AdjustDataSource(sal_True);
1215*cdf0e10cSrcweir 		EndCursorAction();
1216*cdf0e10cSrcweir 		SetUpdateMode(sal_True);
1217*cdf0e10cSrcweir 	}
1218*cdf0e10cSrcweir 	else
1219*cdf0e10cSrcweir 	{
1220*cdf0e10cSrcweir 		Reference< ::com::sun::star::sdbcx::XDeleteRows >  xDeleteThem((Reference< XInterface >)*getDataSource(), UNO_QUERY);
1221*cdf0e10cSrcweir 
1222*cdf0e10cSrcweir 		// colect the bookmarks of the selected rows
1223*cdf0e10cSrcweir 		Sequence < Any> aBookmarks = getSelectionBookmarks();
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 		// determine the next row to position after deletion
1226*cdf0e10cSrcweir 		Any aBookmark;
1227*cdf0e10cSrcweir 		sal_Bool bNewPos = sal_False;
1228*cdf0e10cSrcweir 		// if the current row isn't selected we take the row as row after deletion
1229*cdf0e10cSrcweir         OSL_ENSURE( GetCurrentRow().Is(), "FmGridControl::DeleteSelectedRows: no current row here?" );
1230*cdf0e10cSrcweir             // crash reports suggest it can happen we don't have a current row - how?
1231*cdf0e10cSrcweir             // #154303# / 2008-04-23 / frank.schoenheit@sun.com
1232*cdf0e10cSrcweir 		if ( !IsRowSelected( GetCurrentPos() ) && !IsCurrentAppending() && GetCurrentRow().Is() )
1233*cdf0e10cSrcweir 		{
1234*cdf0e10cSrcweir 			aBookmark = GetCurrentRow()->GetBookmark();
1235*cdf0e10cSrcweir 			bNewPos   = sal_True;
1236*cdf0e10cSrcweir 		}
1237*cdf0e10cSrcweir 		else
1238*cdf0e10cSrcweir 		{
1239*cdf0e10cSrcweir 			// we look for the first row after the selected block for selection
1240*cdf0e10cSrcweir 			long nIdx = LastSelectedRow() + 1;
1241*cdf0e10cSrcweir 			if (nIdx < GetRowCount() - 1)
1242*cdf0e10cSrcweir 			{
1243*cdf0e10cSrcweir 				// there is a next row to position on
1244*cdf0e10cSrcweir 				if (SeekCursor(nIdx))
1245*cdf0e10cSrcweir 				{
1246*cdf0e10cSrcweir 					GetSeekRow()->SetState(m_pSeekCursor, sal_True);
1247*cdf0e10cSrcweir 
1248*cdf0e10cSrcweir 					bNewPos = sal_True;
1249*cdf0e10cSrcweir 					// if it's not the row for inserting we keep the bookmark
1250*cdf0e10cSrcweir 					if (!IsInsertionRow(nIdx))
1251*cdf0e10cSrcweir 						aBookmark = m_pSeekCursor->getBookmark();
1252*cdf0e10cSrcweir 				}
1253*cdf0e10cSrcweir 			}
1254*cdf0e10cSrcweir 			else
1255*cdf0e10cSrcweir 			{
1256*cdf0e10cSrcweir 				// we look for the first row before the selected block for selection after deletion
1257*cdf0e10cSrcweir 				nIdx = FirstSelectedRow() - 1;
1258*cdf0e10cSrcweir 				if (nIdx >= 0 && SeekCursor(nIdx))
1259*cdf0e10cSrcweir 				{
1260*cdf0e10cSrcweir 					GetSeekRow()->SetState(m_pSeekCursor, sal_True);
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir 					bNewPos = sal_True;
1263*cdf0e10cSrcweir 					aBookmark = m_pSeekCursor->getBookmark();
1264*cdf0e10cSrcweir 				}
1265*cdf0e10cSrcweir 			}
1266*cdf0e10cSrcweir 		}
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir 		// Sind alle Zeilen Selectiert
1269*cdf0e10cSrcweir 		// Zweite bedingung falls keine einguegeZeile existiert
1270*cdf0e10cSrcweir 		sal_Bool bAllSelected = GetTotalCount() == nSelectedRows || GetRowCount() == nSelectedRows;
1271*cdf0e10cSrcweir 
1272*cdf0e10cSrcweir 		BeginCursorAction();
1273*cdf0e10cSrcweir 
1274*cdf0e10cSrcweir 		// now delete the row
1275*cdf0e10cSrcweir 		Sequence <sal_Int32> aDeletedRows;
1276*cdf0e10cSrcweir         SetUpdateMode( sal_False );
1277*cdf0e10cSrcweir 		try
1278*cdf0e10cSrcweir 		{
1279*cdf0e10cSrcweir 			aDeletedRows = xDeleteThem->deleteRows(aBookmarks);
1280*cdf0e10cSrcweir 		}
1281*cdf0e10cSrcweir 		catch(SQLException&)
1282*cdf0e10cSrcweir 		{
1283*cdf0e10cSrcweir 		}
1284*cdf0e10cSrcweir         SetUpdateMode( sal_True );
1285*cdf0e10cSrcweir 
1286*cdf0e10cSrcweir 		// how many rows are deleted?
1287*cdf0e10cSrcweir 		sal_Int32 nDeletedRows = 0;
1288*cdf0e10cSrcweir 		const sal_Int32* pSuccess = aDeletedRows.getConstArray();
1289*cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++)
1290*cdf0e10cSrcweir 		{
1291*cdf0e10cSrcweir 			if (pSuccess[i])
1292*cdf0e10cSrcweir 				++nDeletedRows;
1293*cdf0e10cSrcweir 		}
1294*cdf0e10cSrcweir 
1295*cdf0e10cSrcweir 		// sind Zeilen geloescht worden?
1296*cdf0e10cSrcweir 		if (nDeletedRows)
1297*cdf0e10cSrcweir 		{
1298*cdf0e10cSrcweir 			SetUpdateMode(sal_False);
1299*cdf0e10cSrcweir 			SetNoSelection();
1300*cdf0e10cSrcweir 			try
1301*cdf0e10cSrcweir 			{
1302*cdf0e10cSrcweir 				// did we delete all the rows than try to move to the next possible row
1303*cdf0e10cSrcweir 				if (nDeletedRows == aDeletedRows.getLength())
1304*cdf0e10cSrcweir 				{
1305*cdf0e10cSrcweir 					// there exists a new position to move on
1306*cdf0e10cSrcweir 					if (bNewPos)
1307*cdf0e10cSrcweir 					{
1308*cdf0e10cSrcweir 						if (aBookmark.hasValue())
1309*cdf0e10cSrcweir 							getDataSource()->moveToBookmark(aBookmark);
1310*cdf0e10cSrcweir 						// no valid bookmark so move to the insert row
1311*cdf0e10cSrcweir 						else
1312*cdf0e10cSrcweir 						{
1313*cdf0e10cSrcweir 							Reference< XResultSetUpdate >  xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY);
1314*cdf0e10cSrcweir 							xUpdateCursor->moveToInsertRow();
1315*cdf0e10cSrcweir 						}
1316*cdf0e10cSrcweir 					}
1317*cdf0e10cSrcweir 					else
1318*cdf0e10cSrcweir 					{
1319*cdf0e10cSrcweir 						Reference< ::com::sun::star::beans::XPropertySet >	xSet((Reference< XInterface >)*m_pDataCursor, UNO_QUERY);
1320*cdf0e10cSrcweir 
1321*cdf0e10cSrcweir                         sal_Int32 nRecordCount(0);
1322*cdf0e10cSrcweir 						xSet->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount;
1323*cdf0e10cSrcweir                         if ( m_pDataCursor->rowDeleted() )
1324*cdf0e10cSrcweir                             --nRecordCount;
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir 						// there are no rows left and we have an insert row
1327*cdf0e10cSrcweir 						if (!nRecordCount && GetEmptyRow().Is())
1328*cdf0e10cSrcweir 						{
1329*cdf0e10cSrcweir 							Reference< XResultSetUpdate >  xUpdateCursor((Reference< XInterface >)*m_pDataCursor, UNO_QUERY);
1330*cdf0e10cSrcweir 							xUpdateCursor->moveToInsertRow();
1331*cdf0e10cSrcweir 						}
1332*cdf0e10cSrcweir 						else if (nRecordCount)
1333*cdf0e10cSrcweir 							// move to the first row
1334*cdf0e10cSrcweir 							getDataSource()->first();
1335*cdf0e10cSrcweir 					}
1336*cdf0e10cSrcweir 				}
1337*cdf0e10cSrcweir 				// not all the rows where deleted, so move to the first row which remained in the resultset
1338*cdf0e10cSrcweir 				else
1339*cdf0e10cSrcweir 				{
1340*cdf0e10cSrcweir 					for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++)
1341*cdf0e10cSrcweir 					{
1342*cdf0e10cSrcweir 						if (!pSuccess[i])
1343*cdf0e10cSrcweir 						{
1344*cdf0e10cSrcweir 							getDataSource()->moveToBookmark(aBookmarks.getConstArray()[i]);
1345*cdf0e10cSrcweir 							break;
1346*cdf0e10cSrcweir 						}
1347*cdf0e10cSrcweir 					}
1348*cdf0e10cSrcweir 				}
1349*cdf0e10cSrcweir 			}
1350*cdf0e10cSrcweir 			catch(const Exception&)
1351*cdf0e10cSrcweir 			{
1352*cdf0e10cSrcweir 				try
1353*cdf0e10cSrcweir 				{
1354*cdf0e10cSrcweir 					// positioning went wrong so try to move to the first row
1355*cdf0e10cSrcweir 					getDataSource()->first();
1356*cdf0e10cSrcweir 				}
1357*cdf0e10cSrcweir 				catch(const Exception&)
1358*cdf0e10cSrcweir 				{
1359*cdf0e10cSrcweir 				}
1360*cdf0e10cSrcweir 			}
1361*cdf0e10cSrcweir 
1362*cdf0e10cSrcweir 			// An den DatenCursor anpassen
1363*cdf0e10cSrcweir 			AdjustDataSource(sal_True);
1364*cdf0e10cSrcweir 
1365*cdf0e10cSrcweir 			// es konnten nicht alle Zeilen geloescht werden
1366*cdf0e10cSrcweir 			// da nie nicht geloeschten wieder selektieren
1367*cdf0e10cSrcweir 			if (nDeletedRows < nSelectedRows)
1368*cdf0e10cSrcweir 			{
1369*cdf0e10cSrcweir 				// waren alle selektiert
1370*cdf0e10cSrcweir 				if (bAllSelected)
1371*cdf0e10cSrcweir 				{
1372*cdf0e10cSrcweir 					SelectAll();
1373*cdf0e10cSrcweir 					if (IsInsertionRow(GetRowCount() - 1))	// einfuegeZeile nicht
1374*cdf0e10cSrcweir 						SelectRow(GetRowCount() - 1, sal_False);
1375*cdf0e10cSrcweir 				}
1376*cdf0e10cSrcweir 				else
1377*cdf0e10cSrcweir 				{
1378*cdf0e10cSrcweir 					// select the remaining rows
1379*cdf0e10cSrcweir 					for (sal_Int32 i = 0; i < aDeletedRows.getLength(); i++)
1380*cdf0e10cSrcweir 					{
1381*cdf0e10cSrcweir 						try
1382*cdf0e10cSrcweir 						{
1383*cdf0e10cSrcweir 							if (!pSuccess[i])
1384*cdf0e10cSrcweir 							{
1385*cdf0e10cSrcweir 								m_pSeekCursor->moveToBookmark(m_pDataCursor->getBookmark());
1386*cdf0e10cSrcweir 								SetSeekPos(m_pSeekCursor->getRow() - 1);
1387*cdf0e10cSrcweir 								SelectRow(GetSeekPos());
1388*cdf0e10cSrcweir 							}
1389*cdf0e10cSrcweir 						}
1390*cdf0e10cSrcweir 						catch(const Exception&)
1391*cdf0e10cSrcweir 						{
1392*cdf0e10cSrcweir 							// keep the seekpos in all cases
1393*cdf0e10cSrcweir 							SetSeekPos(m_pSeekCursor->getRow() - 1);
1394*cdf0e10cSrcweir 						}
1395*cdf0e10cSrcweir 					}
1396*cdf0e10cSrcweir 				}
1397*cdf0e10cSrcweir 			}
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir 			EndCursorAction();
1400*cdf0e10cSrcweir 			SetUpdateMode(sal_True);
1401*cdf0e10cSrcweir 		}
1402*cdf0e10cSrcweir 		else // Zeile konnte nicht geloescht werden
1403*cdf0e10cSrcweir 		{
1404*cdf0e10cSrcweir 			EndCursorAction();
1405*cdf0e10cSrcweir 			try
1406*cdf0e10cSrcweir 			{
1407*cdf0e10cSrcweir 				// currentrow is the insert row?
1408*cdf0e10cSrcweir 				if (!IsCurrentAppending())
1409*cdf0e10cSrcweir 					getDataSource()->refreshRow();
1410*cdf0e10cSrcweir 			}
1411*cdf0e10cSrcweir 			catch(const Exception&)
1412*cdf0e10cSrcweir 			{
1413*cdf0e10cSrcweir 			}
1414*cdf0e10cSrcweir 		}
1415*cdf0e10cSrcweir 	}
1416*cdf0e10cSrcweir 
1417*cdf0e10cSrcweir 	// if there is no selection anymore we can start editing
1418*cdf0e10cSrcweir 	if (!GetSelectRowCount())
1419*cdf0e10cSrcweir 		ActivateCell();
1420*cdf0e10cSrcweir }
1421*cdf0e10cSrcweir 
1422*cdf0e10cSrcweir 
1423*cdf0e10cSrcweir // XCurrentRecordListener
1424*cdf0e10cSrcweir //------------------------------------------------------------------------------
1425*cdf0e10cSrcweir void FmGridControl::positioned(const ::com::sun::star::lang::EventObject& /*rEvent*/)
1426*cdf0e10cSrcweir {
1427*cdf0e10cSrcweir 	TRACE_RANGE("FmGridControl::positioned");
1428*cdf0e10cSrcweir 	// position on the data source (force it to be done in the main thread)
1429*cdf0e10cSrcweir 	implAdjustInSolarThread(sal_False);
1430*cdf0e10cSrcweir }
1431*cdf0e10cSrcweir 
1432*cdf0e10cSrcweir //------------------------------------------------------------------------------
1433*cdf0e10cSrcweir sal_Bool FmGridControl::commit()
1434*cdf0e10cSrcweir {
1435*cdf0e10cSrcweir 	// Commit nur ausfuehren, wenn nicht bereits ein Update vom ::com::sun::star::form::component::GridControl ausgefuehrt
1436*cdf0e10cSrcweir 	// wird
1437*cdf0e10cSrcweir 	if (!IsUpdating())
1438*cdf0e10cSrcweir 	{
1439*cdf0e10cSrcweir 		if (Controller().Is() && Controller()->IsModified())
1440*cdf0e10cSrcweir 		{
1441*cdf0e10cSrcweir 			if (!SaveModified())
1442*cdf0e10cSrcweir 				return sal_False;
1443*cdf0e10cSrcweir 		}
1444*cdf0e10cSrcweir 	}
1445*cdf0e10cSrcweir 	return sal_True;
1446*cdf0e10cSrcweir }
1447*cdf0e10cSrcweir 
1448*cdf0e10cSrcweir //------------------------------------------------------------------------------
1449*cdf0e10cSrcweir void FmGridControl::inserted(const ::com::sun::star::lang::EventObject& /*rEvent*/)
1450*cdf0e10cSrcweir {
1451*cdf0e10cSrcweir 	const DbGridRowRef& xRow = GetCurrentRow();
1452*cdf0e10cSrcweir 	if (!xRow.Is())
1453*cdf0e10cSrcweir 		return;
1454*cdf0e10cSrcweir 
1455*cdf0e10cSrcweir 	// Zeile ist eingefuegt worden, dann den status und mode zuruecksetzen
1456*cdf0e10cSrcweir 	xRow->SetState(m_pDataCursor, sal_False);
1457*cdf0e10cSrcweir 	xRow->SetNew(sal_False);
1458*cdf0e10cSrcweir 
1459*cdf0e10cSrcweir }
1460*cdf0e10cSrcweir 
1461*cdf0e10cSrcweir // XCancelUpdateRecordListener
1462*cdf0e10cSrcweir //------------------------------------------------------------------------------
1463*cdf0e10cSrcweir void FmGridControl::restored(const ::com::sun::star::lang::EventObject& rEvent)
1464*cdf0e10cSrcweir {
1465*cdf0e10cSrcweir 	if (!GetCurrentRow().Is())
1466*cdf0e10cSrcweir 		return;
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir 	sal_Bool bAppending = GetCurrentRow()->IsNew();
1469*cdf0e10cSrcweir 	sal_Bool bDirty 	= GetCurrentRow()->IsModified();
1470*cdf0e10cSrcweir 	if (bAppending && (EditBrowseBox::IsModified() || bDirty))
1471*cdf0e10cSrcweir 	{
1472*cdf0e10cSrcweir 		if (Controller().Is())
1473*cdf0e10cSrcweir 			Controller()->ClearModified();
1474*cdf0e10cSrcweir 
1475*cdf0e10cSrcweir 		// jetzt die Zeile herausnehmen
1476*cdf0e10cSrcweir 		RowRemoved(GetRowCount() - 1, 1, sal_True);
1477*cdf0e10cSrcweir 		GetNavigationBar().InvalidateAll();
1478*cdf0e10cSrcweir 	}
1479*cdf0e10cSrcweir 
1480*cdf0e10cSrcweir 	positioned(rEvent);
1481*cdf0e10cSrcweir }
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir //------------------------------------------------------------------------------
1484*cdf0e10cSrcweir BrowserHeader* FmGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
1485*cdf0e10cSrcweir {
1486*cdf0e10cSrcweir     DBG_ASSERT( pParent == this, "FmGridControl::imp_CreateHeaderBar: parent?" );
1487*cdf0e10cSrcweir     return new FmGridHeader( pParent );
1488*cdf0e10cSrcweir }
1489*cdf0e10cSrcweir 
1490*cdf0e10cSrcweir //------------------------------------------------------------------------------
1491*cdf0e10cSrcweir void FmGridControl::markColumn(sal_uInt16 nId)
1492*cdf0e10cSrcweir {
1493*cdf0e10cSrcweir 	if (GetHeaderBar() && m_nMarkedColumnId != nId)
1494*cdf0e10cSrcweir 	{
1495*cdf0e10cSrcweir 		// deselektieren
1496*cdf0e10cSrcweir 		if (m_nMarkedColumnId != BROWSER_INVALIDID)
1497*cdf0e10cSrcweir 		{
1498*cdf0e10cSrcweir 			HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(m_nMarkedColumnId) & ~HIB_FLAT;
1499*cdf0e10cSrcweir 			GetHeaderBar()->SetItemBits(m_nMarkedColumnId, aBits);
1500*cdf0e10cSrcweir 		}
1501*cdf0e10cSrcweir 
1502*cdf0e10cSrcweir 
1503*cdf0e10cSrcweir 		if (nId != BROWSER_INVALIDID)
1504*cdf0e10cSrcweir 		{
1505*cdf0e10cSrcweir 			HeaderBarItemBits aBits = GetHeaderBar()->GetItemBits(nId) | HIB_FLAT;
1506*cdf0e10cSrcweir 			GetHeaderBar()->SetItemBits(nId, aBits);
1507*cdf0e10cSrcweir 		}
1508*cdf0e10cSrcweir 		m_nMarkedColumnId = nId;
1509*cdf0e10cSrcweir 	}
1510*cdf0e10cSrcweir }
1511*cdf0e10cSrcweir 
1512*cdf0e10cSrcweir //------------------------------------------------------------------------------
1513*cdf0e10cSrcweir sal_Bool FmGridControl::isColumnMarked(sal_uInt16 nId) const
1514*cdf0e10cSrcweir {
1515*cdf0e10cSrcweir 	return m_nMarkedColumnId == nId;
1516*cdf0e10cSrcweir }
1517*cdf0e10cSrcweir 
1518*cdf0e10cSrcweir //------------------------------------------------------------------------------
1519*cdf0e10cSrcweir long FmGridControl::QueryMinimumRowHeight()
1520*cdf0e10cSrcweir {
1521*cdf0e10cSrcweir     long nMinimalLogicHeight = 20; // 0.2 cm
1522*cdf0e10cSrcweir     long nMinimalPixelHeight = LogicToPixel( Point( 0, nMinimalLogicHeight ), MAP_10TH_MM ).Y();
1523*cdf0e10cSrcweir     return CalcZoom( nMinimalPixelHeight );
1524*cdf0e10cSrcweir }
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir //------------------------------------------------------------------------------
1527*cdf0e10cSrcweir void FmGridControl::RowHeightChanged()
1528*cdf0e10cSrcweir {
1529*cdf0e10cSrcweir     DbGridControl::RowHeightChanged();
1530*cdf0e10cSrcweir 
1531*cdf0e10cSrcweir     Reference< XPropertySet > xModel( GetPeer()->getColumns(), UNO_QUERY );
1532*cdf0e10cSrcweir     DBG_ASSERT( xModel.is(), "FmGridControl::RowHeightChanged: no model!" );
1533*cdf0e10cSrcweir     if ( xModel.is() )
1534*cdf0e10cSrcweir     {
1535*cdf0e10cSrcweir         try
1536*cdf0e10cSrcweir         {
1537*cdf0e10cSrcweir 			sal_Int32 nUnzoomedPixelHeight = CalcReverseZoom( GetDataRowHeight() );
1538*cdf0e10cSrcweir 			Any aProperty = makeAny( (sal_Int32)PixelToLogic( Point( 0, nUnzoomedPixelHeight ), MAP_10TH_MM ).Y() );
1539*cdf0e10cSrcweir             xModel->setPropertyValue( FM_PROP_ROWHEIGHT, aProperty );
1540*cdf0e10cSrcweir         }
1541*cdf0e10cSrcweir         catch( const Exception& )
1542*cdf0e10cSrcweir         {
1543*cdf0e10cSrcweir         	OSL_ENSURE( sal_False, "FmGridControl::RowHeightChanged: caught an exception!" );
1544*cdf0e10cSrcweir         }
1545*cdf0e10cSrcweir     }
1546*cdf0e10cSrcweir }
1547*cdf0e10cSrcweir 
1548*cdf0e10cSrcweir //------------------------------------------------------------------------------
1549*cdf0e10cSrcweir void FmGridControl::ColumnResized(sal_uInt16 nId)
1550*cdf0e10cSrcweir {
1551*cdf0e10cSrcweir 	DbGridControl::ColumnResized(nId);
1552*cdf0e10cSrcweir 
1553*cdf0e10cSrcweir 	// Wert ans model uebergeben
1554*cdf0e10cSrcweir 	DbGridColumn* pCol = DbGridControl::GetColumns().GetObject(GetModelColumnPos(nId));
1555*cdf0e10cSrcweir 	Reference< ::com::sun::star::beans::XPropertySet >	xColModel(pCol->getModel());
1556*cdf0e10cSrcweir 	if (xColModel.is())
1557*cdf0e10cSrcweir 	{
1558*cdf0e10cSrcweir 		Any aWidth;
1559*cdf0e10cSrcweir 		sal_Int32 nColumnWidth = GetColumnWidth(nId);
1560*cdf0e10cSrcweir 		nColumnWidth = CalcReverseZoom(nColumnWidth);
1561*cdf0e10cSrcweir 		// Umrechnen in 10THMM
1562*cdf0e10cSrcweir 		aWidth <<= (sal_Int32)PixelToLogic(Point(nColumnWidth,0),MAP_10TH_MM).X();
1563*cdf0e10cSrcweir 		xColModel->setPropertyValue(FM_PROP_WIDTH, aWidth);
1564*cdf0e10cSrcweir 	}
1565*cdf0e10cSrcweir }
1566*cdf0e10cSrcweir 
1567*cdf0e10cSrcweir //------------------------------------------------------------------------------
1568*cdf0e10cSrcweir void FmGridControl::CellModified()
1569*cdf0e10cSrcweir {
1570*cdf0e10cSrcweir 	DbGridControl::CellModified();
1571*cdf0e10cSrcweir 	GetPeer()->CellModified();
1572*cdf0e10cSrcweir }
1573*cdf0e10cSrcweir 
1574*cdf0e10cSrcweir //------------------------------------------------------------------------------
1575*cdf0e10cSrcweir void FmGridControl::BeginCursorAction()
1576*cdf0e10cSrcweir {
1577*cdf0e10cSrcweir 	DbGridControl::BeginCursorAction();
1578*cdf0e10cSrcweir 	m_pPeer->stopCursorListening();
1579*cdf0e10cSrcweir }
1580*cdf0e10cSrcweir 
1581*cdf0e10cSrcweir //------------------------------------------------------------------------------
1582*cdf0e10cSrcweir void FmGridControl::EndCursorAction()
1583*cdf0e10cSrcweir {
1584*cdf0e10cSrcweir 	m_pPeer->startCursorListening();
1585*cdf0e10cSrcweir 	DbGridControl::EndCursorAction();
1586*cdf0e10cSrcweir }
1587*cdf0e10cSrcweir 
1588*cdf0e10cSrcweir //------------------------------------------------------------------------------
1589*cdf0e10cSrcweir void FmGridControl::ColumnMoved(sal_uInt16 nId)
1590*cdf0e10cSrcweir {
1591*cdf0e10cSrcweir 	m_bInColumnMove = sal_True;
1592*cdf0e10cSrcweir 
1593*cdf0e10cSrcweir 	DbGridControl::ColumnMoved(nId);
1594*cdf0e10cSrcweir 	Reference< ::com::sun::star::container::XIndexContainer >  xColumns(GetPeer()->getColumns());
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir 	if (xColumns.is())
1597*cdf0e10cSrcweir 	{
1598*cdf0e10cSrcweir 		// suchen der Spalte und verschieben im Model
1599*cdf0e10cSrcweir 		// ColumnPos holen
1600*cdf0e10cSrcweir 		DbGridColumn* pCol = DbGridControl::GetColumns().GetObject(GetModelColumnPos(nId));
1601*cdf0e10cSrcweir 		Reference< ::com::sun::star::beans::XPropertySet >	xCol;
1602*cdf0e10cSrcweir 
1603*cdf0e10cSrcweir 		// Einfuegen muß sich an den Column Positionen orientieren
1604*cdf0e10cSrcweir 		sal_Int32 i;
1605*cdf0e10cSrcweir 		Reference< XInterface > xCurrent;
1606*cdf0e10cSrcweir 		for (i = 0; !xCol.is() && i < xColumns->getCount(); i++)
1607*cdf0e10cSrcweir 		{
1608*cdf0e10cSrcweir 			::cppu::extractInterface(xCurrent, xColumns->getByIndex(i));
1609*cdf0e10cSrcweir 			if (xCurrent == pCol->getModel())
1610*cdf0e10cSrcweir 			{
1611*cdf0e10cSrcweir 				xCol = pCol->getModel();
1612*cdf0e10cSrcweir 				break;
1613*cdf0e10cSrcweir 			}
1614*cdf0e10cSrcweir 		}
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir 		DBG_ASSERT(i < xColumns->getCount(), "Falscher ::com::sun::star::sdbcx::Index");
1617*cdf0e10cSrcweir 		xColumns->removeByIndex(i);
1618*cdf0e10cSrcweir 		Any aElement;
1619*cdf0e10cSrcweir 		aElement <<= xCol;
1620*cdf0e10cSrcweir 		xColumns->insertByIndex(GetModelColumnPos(nId), aElement);
1621*cdf0e10cSrcweir 		pCol->setModel(xCol);
1622*cdf0e10cSrcweir 		// if the column which is shown here is selected ...
1623*cdf0e10cSrcweir 		if ( isColumnSelected(nId,pCol) )
1624*cdf0e10cSrcweir 			markColumn(nId); // ... -> mark it
1625*cdf0e10cSrcweir 	}
1626*cdf0e10cSrcweir 
1627*cdf0e10cSrcweir 	m_bInColumnMove = sal_False;
1628*cdf0e10cSrcweir }
1629*cdf0e10cSrcweir 
1630*cdf0e10cSrcweir //------------------------------------------------------------------------------
1631*cdf0e10cSrcweir void FmGridControl::InitColumnsByModels(const Reference< ::com::sun::star::container::XIndexContainer >& xColumns)
1632*cdf0e10cSrcweir {
1633*cdf0e10cSrcweir 	// Spalten wieder neu setzen
1634*cdf0e10cSrcweir 	// wenn es nur eine HandleColumn gibt, dann nicht
1635*cdf0e10cSrcweir 	if (GetModelColCount())
1636*cdf0e10cSrcweir 	{
1637*cdf0e10cSrcweir 		RemoveColumns();
1638*cdf0e10cSrcweir 		InsertHandleColumn();
1639*cdf0e10cSrcweir 	}
1640*cdf0e10cSrcweir 
1641*cdf0e10cSrcweir 	if (!xColumns.is())
1642*cdf0e10cSrcweir 		return;
1643*cdf0e10cSrcweir 
1644*cdf0e10cSrcweir 	SetUpdateMode(sal_False);
1645*cdf0e10cSrcweir 
1646*cdf0e10cSrcweir 	// Einfuegen mu� sich an den Column Positionen orientieren
1647*cdf0e10cSrcweir 	sal_Int32 i;
1648*cdf0e10cSrcweir 	String aName;
1649*cdf0e10cSrcweir 	Any aWidth;
1650*cdf0e10cSrcweir 	for (i = 0; i < xColumns->getCount(); ++i)
1651*cdf0e10cSrcweir 	{
1652*cdf0e10cSrcweir 		Reference< ::com::sun::star::beans::XPropertySet > xCol;
1653*cdf0e10cSrcweir 		::cppu::extractInterface(xCol, xColumns->getByIndex(i));
1654*cdf0e10cSrcweir 
1655*cdf0e10cSrcweir 		aName  = (const sal_Unicode*)::comphelper::getString(xCol->getPropertyValue(FM_PROP_LABEL));
1656*cdf0e10cSrcweir 
1657*cdf0e10cSrcweir 		aWidth = xCol->getPropertyValue(FM_PROP_WIDTH);
1658*cdf0e10cSrcweir 		sal_Int32 nWidth = 0;
1659*cdf0e10cSrcweir 		if (aWidth >>= nWidth)
1660*cdf0e10cSrcweir 			nWidth = LogicToPixel(Point(nWidth,0),MAP_10TH_MM).X();
1661*cdf0e10cSrcweir 
1662*cdf0e10cSrcweir 		AppendColumn(aName, (sal_uInt16)nWidth);
1663*cdf0e10cSrcweir 		DbGridColumn* pCol = DbGridControl::GetColumns().GetObject(i);
1664*cdf0e10cSrcweir 		pCol->setModel(xCol);
1665*cdf0e10cSrcweir 	}
1666*cdf0e10cSrcweir 
1667*cdf0e10cSrcweir 	// und jetzt noch die hidden columns rausnehmen
1668*cdf0e10cSrcweir 	// (wir haben das nicht gleich in der oberen Schleife gemacht, da wir dann Probleme mit den
1669*cdf0e10cSrcweir 	// IDs der Spalten bekommen haetten : AppendColumn vergibt die automatisch, die Spalte _nach_
1670*cdf0e10cSrcweir 	// einer versteckten braucht aber eine um eine erhoehte ID ....
1671*cdf0e10cSrcweir 	Any aHidden;
1672*cdf0e10cSrcweir 	for (i = 0; i < xColumns->getCount(); ++i)
1673*cdf0e10cSrcweir 	{
1674*cdf0e10cSrcweir 		Reference< ::com::sun::star::beans::XPropertySet > xCol;
1675*cdf0e10cSrcweir 		::cppu::extractInterface(xCol, xColumns->getByIndex(i));
1676*cdf0e10cSrcweir 		aHidden = xCol->getPropertyValue(FM_PROP_HIDDEN);
1677*cdf0e10cSrcweir 		if (::comphelper::getBOOL(aHidden))
1678*cdf0e10cSrcweir 			HideColumn(GetColumnIdFromModelPos((sal_uInt16)i));
1679*cdf0e10cSrcweir 	}
1680*cdf0e10cSrcweir 
1681*cdf0e10cSrcweir 	SetUpdateMode(sal_True);
1682*cdf0e10cSrcweir }
1683*cdf0e10cSrcweir 
1684*cdf0e10cSrcweir //------------------------------------------------------------------------------
1685*cdf0e10cSrcweir void FmGridControl::InitColumnByField(
1686*cdf0e10cSrcweir 	DbGridColumn* _pColumn, const Reference< XPropertySet >& _rxColumnModel,
1687*cdf0e10cSrcweir 	const Reference< XNameAccess >& _rxFieldsByNames, const Reference< XIndexAccess >& _rxFieldsByIndex )
1688*cdf0e10cSrcweir {
1689*cdf0e10cSrcweir 	DBG_ASSERT( _rxFieldsByNames == _rxFieldsByIndex, "FmGridControl::InitColumnByField: invalid container interfaces!" );
1690*cdf0e10cSrcweir 
1691*cdf0e10cSrcweir 	// lookup the column which belongs to the control source
1692*cdf0e10cSrcweir 	::rtl::OUString sFieldName;
1693*cdf0e10cSrcweir 	_rxColumnModel->getPropertyValue( FM_PROP_CONTROLSOURCE ) >>= sFieldName;
1694*cdf0e10cSrcweir     Reference< XPropertySet > xField;
1695*cdf0e10cSrcweir     _rxColumnModel->getPropertyValue( FM_PROP_BOUNDFIELD ) >>= xField;
1696*cdf0e10cSrcweir 
1697*cdf0e10cSrcweir 
1698*cdf0e10cSrcweir 	if ( !xField.is() && /*sFieldName.getLength() && */_rxFieldsByNames->hasByName( sFieldName ) ) // #i93452# do not check for name length
1699*cdf0e10cSrcweir 		_rxFieldsByNames->getByName( sFieldName ) >>= xField;
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir 	// determine the position of this column
1702*cdf0e10cSrcweir 	sal_Int32 nFieldPos = -1;
1703*cdf0e10cSrcweir 	if ( xField.is() )
1704*cdf0e10cSrcweir 	{
1705*cdf0e10cSrcweir 		Reference< XPropertySet > xCheck;
1706*cdf0e10cSrcweir 		sal_Int32 nFieldCount = _rxFieldsByIndex->getCount();
1707*cdf0e10cSrcweir 		for ( sal_Int32 i = 0; i < nFieldCount; ++i)
1708*cdf0e10cSrcweir 		{
1709*cdf0e10cSrcweir 			_rxFieldsByIndex->getByIndex( i ) >>= xCheck;
1710*cdf0e10cSrcweir 			if ( xField.get() == xCheck.get() )
1711*cdf0e10cSrcweir 			{
1712*cdf0e10cSrcweir 				nFieldPos = i;
1713*cdf0e10cSrcweir 				break;
1714*cdf0e10cSrcweir 			}
1715*cdf0e10cSrcweir 		}
1716*cdf0e10cSrcweir 	}
1717*cdf0e10cSrcweir 
1718*cdf0e10cSrcweir 	if ( xField.is() && ( nFieldPos >= 0 ) )
1719*cdf0e10cSrcweir 	{
1720*cdf0e10cSrcweir 		// some data types are not allowed
1721*cdf0e10cSrcweir 		sal_Int32 nDataType = DataType::OTHER;
1722*cdf0e10cSrcweir 		xField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType;
1723*cdf0e10cSrcweir 
1724*cdf0e10cSrcweir 		sal_Bool bIllegalType = sal_False;
1725*cdf0e10cSrcweir 		switch ( nDataType )
1726*cdf0e10cSrcweir 		{
1727*cdf0e10cSrcweir 			case DataType::BLOB:
1728*cdf0e10cSrcweir 			case DataType::LONGVARBINARY:
1729*cdf0e10cSrcweir 			case DataType::BINARY:
1730*cdf0e10cSrcweir 			case DataType::VARBINARY:
1731*cdf0e10cSrcweir 			case DataType::OTHER:
1732*cdf0e10cSrcweir 				bIllegalType = sal_True;
1733*cdf0e10cSrcweir 				break;
1734*cdf0e10cSrcweir 		}
1735*cdf0e10cSrcweir 
1736*cdf0e10cSrcweir 		if ( bIllegalType )
1737*cdf0e10cSrcweir 		{
1738*cdf0e10cSrcweir 			_pColumn->SetObject( (sal_Int16)nFieldPos );
1739*cdf0e10cSrcweir 			return;
1740*cdf0e10cSrcweir 		}
1741*cdf0e10cSrcweir /*
1742*cdf0e10cSrcweir 		// handle readonly columns
1743*cdf0e10cSrcweir 		sal_Bool bReadOnly = sal_True;
1744*cdf0e10cSrcweir 		xField->getPropertyValue( FM_PROP_ISREADONLY ) >>= bReadOnly;
1745*cdf0e10cSrcweir 		_pColumn->SetReadOnly( bReadOnly );
1746*cdf0e10cSrcweir */
1747*cdf0e10cSrcweir 	}
1748*cdf0e10cSrcweir 
1749*cdf0e10cSrcweir 	// the control type is determined by the ColumnServiceName
1750*cdf0e10cSrcweir 	static ::rtl::OUString s_sPropColumnServiceName( RTL_CONSTASCII_USTRINGPARAM( "ColumnServiceName" ) );
1751*cdf0e10cSrcweir 	if ( !::comphelper::hasProperty( s_sPropColumnServiceName, _rxColumnModel ) )
1752*cdf0e10cSrcweir 		return;
1753*cdf0e10cSrcweir 
1754*cdf0e10cSrcweir 	_pColumn->setModel( _rxColumnModel );
1755*cdf0e10cSrcweir 
1756*cdf0e10cSrcweir 	::rtl::OUString sColumnServiceName;
1757*cdf0e10cSrcweir 	_rxColumnModel->getPropertyValue( s_sPropColumnServiceName ) >>= sColumnServiceName;
1758*cdf0e10cSrcweir 
1759*cdf0e10cSrcweir 	sal_Int32 nTypeId = getColumnTypeByModelName( sColumnServiceName );
1760*cdf0e10cSrcweir 	_pColumn->CreateControl( nFieldPos, xField, nTypeId );
1761*cdf0e10cSrcweir }
1762*cdf0e10cSrcweir 
1763*cdf0e10cSrcweir //------------------------------------------------------------------------------
1764*cdf0e10cSrcweir void FmGridControl::InitColumnsByFields(const Reference< ::com::sun::star::container::XIndexAccess >& _rxFields)
1765*cdf0e10cSrcweir {
1766*cdf0e10cSrcweir 	if ( !_rxFields.is() )
1767*cdf0e10cSrcweir 		return;
1768*cdf0e10cSrcweir 
1769*cdf0e10cSrcweir 	// Spalten initialisieren
1770*cdf0e10cSrcweir 	Reference< XIndexContainer > xColumns( GetPeer()->getColumns() );
1771*cdf0e10cSrcweir 	Reference< XNameAccess > xFieldsAsNames( _rxFields, UNO_QUERY );
1772*cdf0e10cSrcweir 
1773*cdf0e10cSrcweir 	// Einfuegen muss sich an den Column Positionen orientieren
1774*cdf0e10cSrcweir 	for (sal_Int32 i = 0; i < xColumns->getCount(); i++)
1775*cdf0e10cSrcweir 	{
1776*cdf0e10cSrcweir 		DbGridColumn* pCol = GetColumns().GetObject(i);
1777*cdf0e10cSrcweir 		OSL_ENSURE(pCol,"No grid column!");
1778*cdf0e10cSrcweir 		if ( pCol )
1779*cdf0e10cSrcweir 		{
1780*cdf0e10cSrcweir 			Reference< XPropertySet > xColumnModel;
1781*cdf0e10cSrcweir 			::cppu::extractInterface( xColumnModel, xColumns->getByIndex( i ) );
1782*cdf0e10cSrcweir 
1783*cdf0e10cSrcweir 			InitColumnByField( pCol, xColumnModel, xFieldsAsNames, _rxFields );
1784*cdf0e10cSrcweir 		}
1785*cdf0e10cSrcweir 	}
1786*cdf0e10cSrcweir }
1787*cdf0e10cSrcweir 
1788*cdf0e10cSrcweir //------------------------------------------------------------------------------
1789*cdf0e10cSrcweir void FmGridControl::HideColumn(sal_uInt16 nId)
1790*cdf0e10cSrcweir {
1791*cdf0e10cSrcweir 	DbGridControl::HideColumn(nId);
1792*cdf0e10cSrcweir 
1793*cdf0e10cSrcweir 	sal_uInt16 nPos = GetModelColumnPos(nId);
1794*cdf0e10cSrcweir 	if (nPos == (sal_uInt16)-1)
1795*cdf0e10cSrcweir 		return;
1796*cdf0e10cSrcweir 
1797*cdf0e10cSrcweir 	DbGridColumn* pColumn = GetColumns().GetObject(nPos);
1798*cdf0e10cSrcweir 	if (pColumn->IsHidden())
1799*cdf0e10cSrcweir 		GetPeer()->columnHidden(pColumn);
1800*cdf0e10cSrcweir 
1801*cdf0e10cSrcweir 	if (nId == m_nMarkedColumnId)
1802*cdf0e10cSrcweir 		m_nMarkedColumnId = (sal_uInt16)-1;
1803*cdf0e10cSrcweir }
1804*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1805*cdf0e10cSrcweir sal_Bool FmGridControl::isColumnSelected(sal_uInt16 /*nId*/,DbGridColumn* _pColumn)
1806*cdf0e10cSrcweir {
1807*cdf0e10cSrcweir 	OSL_ENSURE(_pColumn,"Column can not be null!");
1808*cdf0e10cSrcweir 	sal_Bool bSelected = sal_False;
1809*cdf0e10cSrcweir 	// if the column which is shown here is selected ...
1810*cdf0e10cSrcweir 	Reference< ::com::sun::star::view::XSelectionSupplier >  xSelSupplier(GetPeer()->getColumns(), UNO_QUERY);
1811*cdf0e10cSrcweir 	if ( xSelSupplier.is() )
1812*cdf0e10cSrcweir 	{
1813*cdf0e10cSrcweir 		Reference< ::com::sun::star::beans::XPropertySet >	xColumn;
1814*cdf0e10cSrcweir 		xSelSupplier->getSelection() >>= xColumn;
1815*cdf0e10cSrcweir 		bSelected = (xColumn.get() == _pColumn->getModel().get());
1816*cdf0e10cSrcweir 	}
1817*cdf0e10cSrcweir 	return bSelected;
1818*cdf0e10cSrcweir }
1819*cdf0e10cSrcweir 
1820*cdf0e10cSrcweir //------------------------------------------------------------------------------
1821*cdf0e10cSrcweir void FmGridControl::ShowColumn(sal_uInt16 nId)
1822*cdf0e10cSrcweir {
1823*cdf0e10cSrcweir 	DbGridControl::ShowColumn(nId);
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir 	sal_uInt16 nPos = GetModelColumnPos(nId);
1826*cdf0e10cSrcweir 	if (nPos == (sal_uInt16)-1)
1827*cdf0e10cSrcweir 		return;
1828*cdf0e10cSrcweir 
1829*cdf0e10cSrcweir 	DbGridColumn* pColumn = GetColumns().GetObject(nPos);
1830*cdf0e10cSrcweir 	if (!pColumn->IsHidden())
1831*cdf0e10cSrcweir 		GetPeer()->columnVisible(pColumn);
1832*cdf0e10cSrcweir 
1833*cdf0e10cSrcweir 	// if the column which is shown here is selected ...
1834*cdf0e10cSrcweir 	if ( isColumnSelected(nId,pColumn) )
1835*cdf0e10cSrcweir 		markColumn(nId); // ... -> mark it
1836*cdf0e10cSrcweir }
1837*cdf0e10cSrcweir 
1838*cdf0e10cSrcweir //------------------------------------------------------------------------------
1839*cdf0e10cSrcweir sal_Bool FmGridControl::selectBookmarks(const Sequence< Any >& _rBookmarks)
1840*cdf0e10cSrcweir {
1841*cdf0e10cSrcweir 	vos::OGuard aGuard( Application::GetSolarMutex() );
1842*cdf0e10cSrcweir 		// need to lock the SolarMutex so that no paint call disturbs us ...
1843*cdf0e10cSrcweir 
1844*cdf0e10cSrcweir 	if ( !m_pSeekCursor )
1845*cdf0e10cSrcweir 	{
1846*cdf0e10cSrcweir 		DBG_ERROR( "FmGridControl::selectBookmarks: no seek cursor!" );
1847*cdf0e10cSrcweir 		return sal_False;
1848*cdf0e10cSrcweir 	}
1849*cdf0e10cSrcweir 
1850*cdf0e10cSrcweir 	const Any* pBookmark = _rBookmarks.getConstArray();
1851*cdf0e10cSrcweir 	const Any* pBookmarkEnd = pBookmark + _rBookmarks.getLength();
1852*cdf0e10cSrcweir 
1853*cdf0e10cSrcweir 	SetNoSelection();
1854*cdf0e10cSrcweir 
1855*cdf0e10cSrcweir 	sal_Bool bAllSuccessfull = sal_True;
1856*cdf0e10cSrcweir 	try
1857*cdf0e10cSrcweir 	{
1858*cdf0e10cSrcweir 		for (; pBookmark != pBookmarkEnd; ++pBookmark)
1859*cdf0e10cSrcweir 		{
1860*cdf0e10cSrcweir 			// move the seek cursor to the row given
1861*cdf0e10cSrcweir 			if (m_pSeekCursor->moveToBookmark(*pBookmark))
1862*cdf0e10cSrcweir 				SelectRow( m_pSeekCursor->getRow() - 1);
1863*cdf0e10cSrcweir 			else
1864*cdf0e10cSrcweir 				bAllSuccessfull = sal_False;
1865*cdf0e10cSrcweir 		}
1866*cdf0e10cSrcweir 	}
1867*cdf0e10cSrcweir 	catch(Exception&)
1868*cdf0e10cSrcweir 	{
1869*cdf0e10cSrcweir 		DBG_ERROR("FmGridControl::selectBookmarks: could not move to one of the bookmarks!");
1870*cdf0e10cSrcweir 		return sal_False;
1871*cdf0e10cSrcweir 	}
1872*cdf0e10cSrcweir 
1873*cdf0e10cSrcweir 	return bAllSuccessfull;
1874*cdf0e10cSrcweir }
1875*cdf0e10cSrcweir 
1876*cdf0e10cSrcweir //------------------------------------------------------------------------------
1877*cdf0e10cSrcweir Sequence< Any> FmGridControl::getSelectionBookmarks()
1878*cdf0e10cSrcweir {
1879*cdf0e10cSrcweir 	// lock our update so no paint-triggered seeks interfere ...
1880*cdf0e10cSrcweir 	SetUpdateMode(sal_False);
1881*cdf0e10cSrcweir 
1882*cdf0e10cSrcweir 	sal_Int32 nSelectedRows = GetSelectRowCount(), i = 0;
1883*cdf0e10cSrcweir 	Sequence< Any> aBookmarks(nSelectedRows);
1884*cdf0e10cSrcweir 	if ( nSelectedRows )
1885*cdf0e10cSrcweir 	{
1886*cdf0e10cSrcweir 		Any* pBookmarks = (Any*)aBookmarks.getArray();
1887*cdf0e10cSrcweir 
1888*cdf0e10cSrcweir 		// (I'm not sure if the problem isn't deeper : The szenario : a large table displayed by a grid with a
1889*cdf0e10cSrcweir 		// thread-safe cursor (dBase). On loading the sdb-cursor started a counting thread. While this counting progress
1890*cdf0e10cSrcweir 		// was running, I tried do delete 3 records from within the grid. Deletion caused a SeekCursor, which did a
1891*cdf0e10cSrcweir 		// m_pSeekCursor->moveRelative and a m_pSeekCursor->getPosition.
1892*cdf0e10cSrcweir 		// Unfortunally the first call caused a propertyChanged(RECORDCOUNT) which resulted in a repaint of the
1893*cdf0e10cSrcweir 		// navigation bar and the grid. The latter itself will result in SeekRow calls. So after (successfully) returning
1894*cdf0e10cSrcweir 		// from the moveRelative the getPosition returns an invalid value. And so the SeekCursor fails.
1895*cdf0e10cSrcweir 		// In the consequence ALL parts of code where two calls to the seek cursor are done, while the second call _relys_ on
1896*cdf0e10cSrcweir 		// the first one, should be secured against recursion, with a broad-minded interpretion of "recursion" : if any of these
1897*cdf0e10cSrcweir 		// code parts is executed, no other should be accessible. But this sounds very difficult to achieve ....
1898*cdf0e10cSrcweir 		// )
1899*cdf0e10cSrcweir 
1900*cdf0e10cSrcweir 		// The next problem caused by the same behaviuor (SeekCursor causes a propertyChanged) : when adjusting rows we implicitly
1901*cdf0e10cSrcweir 		// change our selection. So a "FirstSelected(); SeekCursor(); NextSelected();" may produce unpredictable results.
1902*cdf0e10cSrcweir 		// That's why we _first_ collect the indicies of the selected rows and _then_ their bookmarks.
1903*cdf0e10cSrcweir 		long nIdx = FirstSelectedRow();
1904*cdf0e10cSrcweir 		while (nIdx >= 0)
1905*cdf0e10cSrcweir 		{
1906*cdf0e10cSrcweir 			// (we misuse the bookmarks array for this ...)
1907*cdf0e10cSrcweir 			pBookmarks[i++] <<= (sal_Int32)nIdx;
1908*cdf0e10cSrcweir 			nIdx = NextSelectedRow();
1909*cdf0e10cSrcweir 		}
1910*cdf0e10cSrcweir 		DBG_ASSERT(i == nSelectedRows, "FmGridControl::DeleteSelectedRows : could not collect the row indicies !");
1911*cdf0e10cSrcweir 
1912*cdf0e10cSrcweir 		for (i=0; i<nSelectedRows; ++i)
1913*cdf0e10cSrcweir 		{
1914*cdf0e10cSrcweir 			nIdx = ::comphelper::getINT32(pBookmarks[i]);
1915*cdf0e10cSrcweir 			if (IsInsertionRow(nIdx))
1916*cdf0e10cSrcweir 			{
1917*cdf0e10cSrcweir 				// leerzeile nicht loeschen
1918*cdf0e10cSrcweir 				aBookmarks.realloc(--nSelectedRows);
1919*cdf0e10cSrcweir 				SelectRow(nIdx,sal_False);			// selection aufheben fuer leerzeile
1920*cdf0e10cSrcweir 				break;
1921*cdf0e10cSrcweir 			}
1922*cdf0e10cSrcweir 
1923*cdf0e10cSrcweir 			// Zunaechst den DatenCursor auf den selektierten Satz pos.
1924*cdf0e10cSrcweir 			if (SeekCursor(nIdx))
1925*cdf0e10cSrcweir 			{
1926*cdf0e10cSrcweir 				GetSeekRow()->SetState(m_pSeekCursor, sal_True);
1927*cdf0e10cSrcweir 
1928*cdf0e10cSrcweir 				pBookmarks[i] = m_pSeekCursor->getBookmark();
1929*cdf0e10cSrcweir 			}
1930*cdf0e10cSrcweir 	#ifdef DBG_UTIL
1931*cdf0e10cSrcweir 			else
1932*cdf0e10cSrcweir 				DBG_ERROR("FmGridControl::DeleteSelectedRows : a bookmark could not be determined !");
1933*cdf0e10cSrcweir 	#endif
1934*cdf0e10cSrcweir 		}
1935*cdf0e10cSrcweir 	}
1936*cdf0e10cSrcweir 	SetUpdateMode(sal_True);
1937*cdf0e10cSrcweir 
1938*cdf0e10cSrcweir 	// if one of the SeekCursor-calls failed ....
1939*cdf0e10cSrcweir 	aBookmarks.realloc(i);
1940*cdf0e10cSrcweir 
1941*cdf0e10cSrcweir 	// (the alternative : while collecting the bookmarks lock our propertyChanged, this should resolve both our problems.
1942*cdf0e10cSrcweir 	// but this would be incompatible as we need a locking flag, then ...)
1943*cdf0e10cSrcweir 
1944*cdf0e10cSrcweir 	return aBookmarks;
1945*cdf0e10cSrcweir }
1946*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1947*cdf0e10cSrcweir namespace
1948*cdf0e10cSrcweir {
1949*cdf0e10cSrcweir 	::rtl::OUString getColumnPropertyFromPeer(FmXGridPeer* _pPeer,sal_Int32 _nPosition,const ::rtl::OUString& _sPropName)
1950*cdf0e10cSrcweir 	{
1951*cdf0e10cSrcweir 		::rtl::OUString sRetText;
1952*cdf0e10cSrcweir 		if ( _pPeer && _nPosition != -1)
1953*cdf0e10cSrcweir 		{
1954*cdf0e10cSrcweir 			Reference<XIndexContainer> xIndex = _pPeer->getColumns();
1955*cdf0e10cSrcweir 			if ( xIndex.is() && xIndex->getCount() > _nPosition )
1956*cdf0e10cSrcweir 			{
1957*cdf0e10cSrcweir 				Reference<XPropertySet> xProp;
1958*cdf0e10cSrcweir 				xIndex->getByIndex( _nPosition ) >>= xProp;
1959*cdf0e10cSrcweir 				if ( xProp.is() )
1960*cdf0e10cSrcweir 					xProp->getPropertyValue( _sPropName ) >>= sRetText;
1961*cdf0e10cSrcweir 			}
1962*cdf0e10cSrcweir 		}
1963*cdf0e10cSrcweir 		return sRetText;
1964*cdf0e10cSrcweir 	}
1965*cdf0e10cSrcweir }
1966*cdf0e10cSrcweir // Object data and state ------------------------------------------------------
1967*cdf0e10cSrcweir ::rtl::OUString FmGridControl::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const
1968*cdf0e10cSrcweir {
1969*cdf0e10cSrcweir     ::rtl::OUString sRetText;
1970*cdf0e10cSrcweir     switch( _eObjType )
1971*cdf0e10cSrcweir     {
1972*cdf0e10cSrcweir         case ::svt::BBTYPE_BROWSEBOX:
1973*cdf0e10cSrcweir             if ( GetPeer() )
1974*cdf0e10cSrcweir 			{
1975*cdf0e10cSrcweir 				Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY);
1976*cdf0e10cSrcweir 				if ( xProp.is() )
1977*cdf0e10cSrcweir 					xProp->getPropertyValue(FM_PROP_NAME) >>= sRetText;
1978*cdf0e10cSrcweir 			}
1979*cdf0e10cSrcweir 			break;
1980*cdf0e10cSrcweir         case ::svt::BBTYPE_COLUMNHEADERCELL:
1981*cdf0e10cSrcweir 			sRetText = getColumnPropertyFromPeer(
1982*cdf0e10cSrcweir                 GetPeer(),
1983*cdf0e10cSrcweir                 GetModelColumnPos(
1984*cdf0e10cSrcweir                     sal::static_int_cast< sal_uInt16 >(_nPosition)),
1985*cdf0e10cSrcweir                 FM_PROP_LABEL);
1986*cdf0e10cSrcweir 			break;
1987*cdf0e10cSrcweir 		default:
1988*cdf0e10cSrcweir 			sRetText = DbGridControl::GetAccessibleObjectName(_eObjType,_nPosition);
1989*cdf0e10cSrcweir     }
1990*cdf0e10cSrcweir     return sRetText;
1991*cdf0e10cSrcweir }
1992*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1993*cdf0e10cSrcweir 
1994*cdf0e10cSrcweir ::rtl::OUString FmGridControl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition ) const
1995*cdf0e10cSrcweir {
1996*cdf0e10cSrcweir     ::rtl::OUString sRetText;
1997*cdf0e10cSrcweir     switch( _eObjType )
1998*cdf0e10cSrcweir     {
1999*cdf0e10cSrcweir         case ::svt::BBTYPE_BROWSEBOX:
2000*cdf0e10cSrcweir 			if ( GetPeer() )
2001*cdf0e10cSrcweir 			{
2002*cdf0e10cSrcweir 				Reference<XPropertySet> xProp(GetPeer()->getColumns(),UNO_QUERY);
2003*cdf0e10cSrcweir 				if ( xProp.is() )
2004*cdf0e10cSrcweir                 {
2005*cdf0e10cSrcweir 					xProp->getPropertyValue(FM_PROP_HELPTEXT) >>= sRetText;
2006*cdf0e10cSrcweir                     if ( !sRetText.getLength() )
2007*cdf0e10cSrcweir                         xProp->getPropertyValue(FM_PROP_DESCRIPTION) >>= sRetText;
2008*cdf0e10cSrcweir                 }
2009*cdf0e10cSrcweir 			}
2010*cdf0e10cSrcweir 			break;
2011*cdf0e10cSrcweir 		case ::svt::BBTYPE_COLUMNHEADERCELL:
2012*cdf0e10cSrcweir 			sRetText = getColumnPropertyFromPeer(
2013*cdf0e10cSrcweir                 GetPeer(),
2014*cdf0e10cSrcweir                 GetModelColumnPos(
2015*cdf0e10cSrcweir                     sal::static_int_cast< sal_uInt16 >(_nPosition)),
2016*cdf0e10cSrcweir                 FM_PROP_HELPTEXT);
2017*cdf0e10cSrcweir             if ( !sRetText.getLength() )
2018*cdf0e10cSrcweir                 sRetText = getColumnPropertyFromPeer(
2019*cdf0e10cSrcweir                             GetPeer(),
2020*cdf0e10cSrcweir                             GetModelColumnPos(
2021*cdf0e10cSrcweir                                 sal::static_int_cast< sal_uInt16 >(_nPosition)),
2022*cdf0e10cSrcweir                             FM_PROP_DESCRIPTION);
2023*cdf0e10cSrcweir 
2024*cdf0e10cSrcweir 			break;
2025*cdf0e10cSrcweir 		default:
2026*cdf0e10cSrcweir             sRetText = DbGridControl::GetAccessibleObjectDescription(_eObjType,_nPosition);
2027*cdf0e10cSrcweir     }
2028*cdf0e10cSrcweir     return sRetText;
2029*cdf0e10cSrcweir }
2030*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2031*cdf0e10cSrcweir void FmGridControl::Select()
2032*cdf0e10cSrcweir {
2033*cdf0e10cSrcweir 	DbGridControl::Select();
2034*cdf0e10cSrcweir 	// ... betrifft das unsere Spalten ?
2035*cdf0e10cSrcweir 	const MultiSelection* pColumnSelection = GetColumnSelection();
2036*cdf0e10cSrcweir 
2037*cdf0e10cSrcweir 	sal_uInt16 nSelectedColumn =
2038*cdf0e10cSrcweir 		pColumnSelection && pColumnSelection->GetSelectCount()
2039*cdf0e10cSrcweir 			? sal::static_int_cast< sal_uInt16 >(
2040*cdf0e10cSrcweir                 ((MultiSelection*)pColumnSelection)->FirstSelected())
2041*cdf0e10cSrcweir 			: SAL_MAX_UINT16;
2042*cdf0e10cSrcweir 	// die HandleColumn wird nicht selektiert
2043*cdf0e10cSrcweir 	switch (nSelectedColumn)
2044*cdf0e10cSrcweir 	{
2045*cdf0e10cSrcweir 		case SAL_MAX_UINT16: break;	// no selection
2046*cdf0e10cSrcweir 		case  0	: nSelectedColumn = SAL_MAX_UINT16; break;
2047*cdf0e10cSrcweir                     // handle col can't be seledted
2048*cdf0e10cSrcweir 		default	:
2049*cdf0e10cSrcweir 			// get the model col pos instead of the view col pos
2050*cdf0e10cSrcweir 			nSelectedColumn = GetModelColumnPos(GetColumnIdFromViewPos(nSelectedColumn - 1));
2051*cdf0e10cSrcweir 			break;
2052*cdf0e10cSrcweir 	}
2053*cdf0e10cSrcweir 
2054*cdf0e10cSrcweir 	if (nSelectedColumn != m_nCurrentSelectedColumn)
2055*cdf0e10cSrcweir 	{
2056*cdf0e10cSrcweir 		// VOR dem Aufruf des select am SelectionSupplier !
2057*cdf0e10cSrcweir 		m_nCurrentSelectedColumn = nSelectedColumn;
2058*cdf0e10cSrcweir 
2059*cdf0e10cSrcweir 		if (!m_bSelecting)
2060*cdf0e10cSrcweir 		{
2061*cdf0e10cSrcweir 			m_bSelecting = sal_True;
2062*cdf0e10cSrcweir 
2063*cdf0e10cSrcweir 			try
2064*cdf0e10cSrcweir 			{
2065*cdf0e10cSrcweir 				Reference< XIndexAccess >  xColumns(GetPeer()->getColumns(), UNO_QUERY);
2066*cdf0e10cSrcweir 				Reference< XSelectionSupplier >  xSelSupplier(xColumns, UNO_QUERY);
2067*cdf0e10cSrcweir 				if (xSelSupplier.is())
2068*cdf0e10cSrcweir 				{
2069*cdf0e10cSrcweir 					if (nSelectedColumn != SAL_MAX_UINT16)
2070*cdf0e10cSrcweir 					{
2071*cdf0e10cSrcweir 						Reference< XPropertySet >  xColumn;
2072*cdf0e10cSrcweir 						::cppu::extractInterface(xColumn,xColumns->getByIndex(nSelectedColumn));
2073*cdf0e10cSrcweir 						xSelSupplier->select(makeAny(xColumn));
2074*cdf0e10cSrcweir 					}
2075*cdf0e10cSrcweir 					else
2076*cdf0e10cSrcweir 					{
2077*cdf0e10cSrcweir 						xSelSupplier->select(Any());
2078*cdf0e10cSrcweir 					}
2079*cdf0e10cSrcweir 				}
2080*cdf0e10cSrcweir 			}
2081*cdf0e10cSrcweir 			catch(Exception&)
2082*cdf0e10cSrcweir 			{
2083*cdf0e10cSrcweir 			}
2084*cdf0e10cSrcweir 
2085*cdf0e10cSrcweir 
2086*cdf0e10cSrcweir 			m_bSelecting = sal_False;
2087*cdf0e10cSrcweir 		}
2088*cdf0e10cSrcweir 	}
2089*cdf0e10cSrcweir }
2090*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2091*cdf0e10cSrcweir sal_Int32 FmGridControl::GetSelectedColumn() const
2092*cdf0e10cSrcweir {
2093*cdf0e10cSrcweir 	return m_nCurrentSelectedColumn;
2094*cdf0e10cSrcweir }
2095*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2096*cdf0e10cSrcweir void FmGridControl::KeyInput( const KeyEvent& rKEvt )
2097*cdf0e10cSrcweir {
2098*cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
2099*cdf0e10cSrcweir 	const KeyCode& rKeyCode = rKEvt.GetKeyCode();
2100*cdf0e10cSrcweir 	if (	IsDesignMode()
2101*cdf0e10cSrcweir 		&&	!rKeyCode.IsShift()
2102*cdf0e10cSrcweir 		&&	!rKeyCode.IsMod1()
2103*cdf0e10cSrcweir 		&&	!rKeyCode.IsMod2()
2104*cdf0e10cSrcweir 		&&	GetParent() )
2105*cdf0e10cSrcweir 	{
2106*cdf0e10cSrcweir 		switch ( rKeyCode.GetCode() )
2107*cdf0e10cSrcweir 		{
2108*cdf0e10cSrcweir 			case KEY_ESCAPE:
2109*cdf0e10cSrcweir 				GetParent()->GrabFocus();
2110*cdf0e10cSrcweir 				bDone = sal_True;
2111*cdf0e10cSrcweir 				break;
2112*cdf0e10cSrcweir 			case KEY_DELETE:
2113*cdf0e10cSrcweir 				if ( GetSelectColumnCount() && GetPeer() && m_nCurrentSelectedColumn >= 0 )
2114*cdf0e10cSrcweir 				{
2115*cdf0e10cSrcweir 					Reference< ::com::sun::star::container::XIndexContainer >  xCols(GetPeer()->getColumns());
2116*cdf0e10cSrcweir 					if ( xCols.is() )
2117*cdf0e10cSrcweir 					{
2118*cdf0e10cSrcweir 						try
2119*cdf0e10cSrcweir 						{
2120*cdf0e10cSrcweir 							if ( m_nCurrentSelectedColumn < xCols->getCount() )
2121*cdf0e10cSrcweir 							{
2122*cdf0e10cSrcweir 								Reference< XInterface >  xCol;
2123*cdf0e10cSrcweir 								xCols->getByIndex(m_nCurrentSelectedColumn) >>= xCol;
2124*cdf0e10cSrcweir 								xCols->removeByIndex(m_nCurrentSelectedColumn);
2125*cdf0e10cSrcweir 								::comphelper::disposeComponent(xCol);
2126*cdf0e10cSrcweir 							}
2127*cdf0e10cSrcweir 						}
2128*cdf0e10cSrcweir 						catch(const Exception&)
2129*cdf0e10cSrcweir 						{
2130*cdf0e10cSrcweir 							OSL_ENSURE(0,"exception occured while deleting a column");
2131*cdf0e10cSrcweir 						}
2132*cdf0e10cSrcweir 					}
2133*cdf0e10cSrcweir 				}
2134*cdf0e10cSrcweir 				bDone = sal_True;
2135*cdf0e10cSrcweir 				break;
2136*cdf0e10cSrcweir 		}
2137*cdf0e10cSrcweir 	}
2138*cdf0e10cSrcweir 	if ( !bDone )
2139*cdf0e10cSrcweir 		DbGridControl::KeyInput( rKEvt );
2140*cdf0e10cSrcweir }
2141*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2142*cdf0e10cSrcweir 
2143*cdf0e10cSrcweir 
2144*cdf0e10cSrcweir 
2145