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