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