1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmgridcl.cxx,v $
10 * $Revision: 1.64.94.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 #include "fmgridif.hxx"
36 #include "fmitems.hxx"
38 #include "fmresids.hrc"
39 #include "fmservs.hxx"
41 #include "formcontrolfactory.hxx"
42 #include "gridcell.hxx"
43 #include "gridcols.hxx"
44 #include "svx/dbaexchange.hxx"
45 #include "svx/dialmgr.hxx"
46 #include "svx/dialogs.hrc"
47 #include "svx/fmgridcl.hxx"
48 #include "svx/svxdlg.hxx"
49 #include "svx/svxids.hrc"
52 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
53 #include <com/sun/star/form/XFormComponent.hpp>
54 #include <com/sun/star/form/XGridColumnFactory.hpp>
55 #include <com/sun/star/io/XPersistObject.hpp>
56 #include <com/sun/star/sdb/CommandType.hpp>
57 #include <com/sun/star/sdb/RowChangeAction.hpp>
58 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
59 #include <com/sun/star/sdbc/DataType.hpp>
60 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
61 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
62 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
63 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
64 #include <com/sun/star/uno/XNamingService.hpp>
65 #include <com/sun/star/util/XNumberFormats.hpp>
66 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
67 #include <com/sun/star/util/XURLTransformer.hpp>
68 #include <com/sun/star/view/XSelectionSupplier.hpp>
70 #ifndef _SVSTDARR_STRINGSDTOR
71 #define _SVSTDARR_STRINGSDTOR
72 #define _SVSTDARR_ULONGS
73 #include <svtools/svstdarr.hxx>
76 #include <comphelper/extract.hxx>
77 #include <comphelper/numbers.hxx>
78 #include <comphelper/processfactory.hxx>
79 #include <comphelper/property.hxx>
80 #include <connectivity/dbtools.hxx>
81 #include <sfx2/dispatch.hxx>
82 #include <sfx2/viewfrm.hxx>
83 #include <svtools/eitem.hxx>
84 #include <svtools/fmtfield.hxx>
85 #include <svtools/numuno.hxx>
86 #include <tools/multisel.hxx>
87 #include <tools/shl.hxx>
88 #include <tools/diagnose_ex.h>
89 #include <vcl/help.hxx>
90 #include <vcl/image.hxx>
91 #include <vcl/longcurr.hxx>
92 #include <vcl/menu.hxx>
96 using namespace ::com::sun::star::uno
;
97 using namespace ::com::sun::star::view
;
98 using namespace ::com::sun::star::beans
;
99 using namespace ::com::sun::star::lang
;
100 using namespace ::com::sun::star::sdbcx
;
101 using namespace ::com::sun::star::sdbc
;
102 using namespace ::com::sun::star::sdb
;
103 using namespace ::com::sun::star::form
;
104 using namespace ::com::sun::star::util
;
105 using namespace ::com::sun::star::container
;
106 using namespace ::cppu
;
107 using namespace ::svxform
;
108 using namespace ::svx
;
110 //==============================================================================
111 //------------------------------------------------------------------------------
112 ::rtl::OUString
FieldServiceFromId(sal_Int32 nID
)
116 case SID_FM_EDIT
: return FM_COL_TEXTFIELD
;
117 case SID_FM_COMBOBOX
: return FM_COL_COMBOBOX
;
118 case SID_FM_LISTBOX
: return FM_COL_LISTBOX
;
119 case SID_FM_CHECKBOX
: return FM_COL_CHECKBOX
;
120 case SID_FM_DATEFIELD
: return FM_COL_DATEFIELD
;
121 case SID_FM_TIMEFIELD
: return FM_COL_TIMEFIELD
;
122 case SID_FM_NUMERICFIELD
: return FM_COL_NUMERICFIELD
;
123 case SID_FM_CURRENCYFIELD
: return FM_COL_CURRENCYFIELD
;
124 case SID_FM_PATTERNFIELD
: return FM_COL_PATTERNFIELD
;
125 case SID_FM_FORMATTEDFIELD
: return FM_COL_FORMATTEDFIELD
;
127 return ::rtl::OUString();
130 //==============================================================================
131 struct FmGridHeaderData
133 ODataAccessDescriptor aDropData
;
135 sal_Int8 nDropAction
;
136 Reference
< XInterface
> xDroppedStatement
;
137 Reference
< XInterface
> xDroppedResultSet
;
140 //==============================================================================
141 //------------------------------------------------------------------------------
142 const sal_Int16 nChangeTypeOffset
= 1000;
143 void SetMenuItem(const ImageList
& rList
, sal_uInt16 nID
, Menu
* pMenu
, Menu
& rNewMenu
, sal_Bool bDesignMode
= sal_True
, sal_Int16 nOffset
= nChangeTypeOffset
)
145 pMenu
->SetItemImage(nID
, rList
.GetImage(nID
));
146 pMenu
->EnableItem(nID
, bDesignMode
);
147 rNewMenu
.InsertItem(nID
+ nOffset
, pMenu
->GetItemText(nID
));
148 rNewMenu
.SetItemImage(nID
+ nOffset
, rList
.GetImage(nID
));
149 rNewMenu
.SetHelpId(nID
+ nOffset
, pMenu
->GetHelpId(nID
));
150 rNewMenu
.EnableItem(nID
+ nOffset
, bDesignMode
);
153 //------------------------------------------------------------------------------
154 FmGridHeader::FmGridHeader( BrowseBox
* pParent
, WinBits nWinBits
)
155 :EditBrowserHeader(pParent
, nWinBits
)
156 ,DropTargetHelper(this)
157 ,m_pImpl(new FmGridHeaderData
)
161 //------------------------------------------------------------------------------
162 FmGridHeader::~FmGridHeader()
167 //------------------------------------------------------------------------------
168 sal_uInt16
FmGridHeader::GetModelColumnPos(sal_uInt16 nId
) const
170 return static_cast<FmGridControl
*>(GetParent())->GetModelColumnPos(nId
);
172 //---------------------------------------------------------------------------------------
173 void FmGridHeader::notifyColumnSelect(sal_uInt16 nColumnId
)
175 sal_uInt16 nPos
= GetModelColumnPos(nColumnId
);
176 Reference
< XIndexAccess
> xColumns(((FmGridControl
*)GetParent())->GetPeer()->getColumns(), UNO_QUERY
);
177 if ( nPos
< xColumns
->getCount() )
179 Reference
< XSelectionSupplier
> xSelSupplier(xColumns
, UNO_QUERY
);
180 if ( xSelSupplier
.is() )
182 Reference
< XPropertySet
> xColumn
;
183 xColumns
->getByIndex(nPos
) >>= xColumn
;
184 xSelSupplier
->select(makeAny(xColumn
));
188 //------------------------------------------------------------------------------
189 void FmGridHeader::Select()
191 EditBrowserHeader::Select();
192 notifyColumnSelect(GetCurItemId());
195 //------------------------------------------------------------------------------
196 void FmGridHeader::RequestHelp( const HelpEvent
& rHEvt
)
198 sal_uInt16 nItemId
= GetItemId( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
201 if ( rHEvt
.GetMode() & (HELPMODE_QUICK
| HELPMODE_BALLOON
) )
203 Rectangle aItemRect
= GetItemRect( nItemId
);
204 Point aPt
= OutputToScreenPixel( aItemRect
.TopLeft() );
205 aItemRect
.Left() = aPt
.X();
206 aItemRect
.Top() = aPt
.Y();
207 aPt
= OutputToScreenPixel( aItemRect
.BottomRight() );
208 aItemRect
.Right() = aPt
.X();
209 aItemRect
.Bottom() = aPt
.Y();
211 sal_uInt16 nPos
= GetModelColumnPos(nItemId
);
212 Reference
< ::com::sun::star::container::XIndexContainer
> xColumns(static_cast<FmGridControl
*>(GetParent())->GetPeer()->getColumns());
215 Reference
< ::com::sun::star::beans::XPropertySet
> xColumn
;
216 ::cppu::extractInterface(xColumn
, xColumns
->getByIndex(nPos
));
217 ::rtl::OUString aHelpText
;
218 xColumn
->getPropertyValue(FM_PROP_HELPTEXT
) >>= aHelpText
;
219 if ( aHelpText
.getLength() )
221 if ( rHEvt
.GetMode() & HELPMODE_BALLOON
)
222 Help::ShowBalloon( this, aItemRect
.Center(), aItemRect
, aHelpText
);
224 Help::ShowQuickHelp( this, aItemRect
, aHelpText
);
234 EditBrowserHeader::RequestHelp( rHEvt
);
237 //------------------------------------------------------------------------------
238 sal_Int8
FmGridHeader::AcceptDrop( const AcceptDropEvent
& rEvt
)
240 // drop allowed in design mode only
241 if (!static_cast<FmGridControl
*>(GetParent())->IsDesignMode())
242 return DND_ACTION_NONE
;
244 // search for recognized formats
245 const DataFlavorExVector
& rFlavors
= GetDataFlavorExVector();
246 if (OColumnTransferable::canExtractColumnDescriptor(rFlavors
, CTF_COLUMN_DESCRIPTOR
| CTF_FIELD_DESCRIPTOR
))
247 return rEvt
.mnAction
;
249 return DND_ACTION_NONE
;
252 //------------------------------------------------------------------------------
253 sal_Int8
FmGridHeader::ExecuteDrop( const ExecuteDropEvent
& _rEvt
)
255 if (!static_cast<FmGridControl
*>(GetParent())->IsDesignMode())
256 return DND_ACTION_NONE
;
258 TransferableDataHelper
aDroppedData(_rEvt
.maDropEvent
.Transferable
);
261 sal_Bool bColumnDescriptor
= OColumnTransferable::canExtractColumnDescriptor(aDroppedData
.GetDataFlavorExVector(), CTF_COLUMN_DESCRIPTOR
);
262 sal_Bool bFieldDescriptor
= OColumnTransferable::canExtractColumnDescriptor(aDroppedData
.GetDataFlavorExVector(), CTF_FIELD_DESCRIPTOR
);
263 if (!bColumnDescriptor
&& !bFieldDescriptor
)
265 DBG_ERROR("FmGridHeader::ExecuteDrop: should never have reached this (no extractable format)!");
266 return DND_ACTION_NONE
;
269 // extract the descriptor
270 ::rtl::OUString sDatasouce
, sCommand
, sFieldName
,sDatabaseLocation
,sConnnectionResource
;
271 sal_Int32 nCommandType
= CommandType::COMMAND
;
272 Reference
< XPreparedStatement
> xStatement
;
273 Reference
< XResultSet
> xResultSet
;
274 Reference
< XPropertySet
> xField
;
275 Reference
< XConnection
> xConnection
;
277 ODataAccessDescriptor aColumn
= OColumnTransferable::extractColumnDescriptor(aDroppedData
);
278 if (aColumn
.has(daDataSource
)) aColumn
[daDataSource
] >>= sDatasouce
;
279 if (aColumn
.has(daDatabaseLocation
)) aColumn
[daDatabaseLocation
] >>= sDatabaseLocation
;
280 if (aColumn
.has(daConnectionResource
)) aColumn
[daConnectionResource
] >>= sConnnectionResource
;
281 if (aColumn
.has(daCommand
)) aColumn
[daCommand
] >>= sCommand
;
282 if (aColumn
.has(daCommandType
)) aColumn
[daCommandType
] >>= nCommandType
;
283 if (aColumn
.has(daColumnName
)) aColumn
[daColumnName
] >>= sFieldName
;
284 if (aColumn
.has(daColumnObject
))aColumn
[daColumnObject
] >>= xField
;
285 if (aColumn
.has(daConnection
)) aColumn
[daConnection
] >>= xConnection
;
287 if ( !sFieldName
.getLength()
288 || !sCommand
.getLength()
289 || ( !sDatasouce
.getLength()
290 && !sDatabaseLocation
.getLength()
295 DBG_ERROR( "FmGridHeader::ExecuteDrop: somebody started a nonsense drag operation!!" );
296 return DND_ACTION_NONE
;
302 if (!xConnection
.is())
303 { // the transferable did not contain the connection -> build an own one
306 ::rtl::OUString
sSignificantSource( sDatasouce
.getLength() ? sDatasouce
: sDatabaseLocation
);
307 xConnection
= OStaticDataAccessTools().getConnection_withFeedback(sSignificantSource
, ::rtl::OUString(),::rtl::OUString(),static_cast<FmGridControl
*>(GetParent())->getServiceManager());
309 catch(NoSuchElementException
&)
310 { // allowed, means sDatasouce isn't a valid data source name ....
314 DBG_ERROR("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
317 if (!xConnection
.is())
319 DBG_ERROR("FmGridHeader::ExecuteDrop: could not retrieve the database access object !");
320 return DND_ACTION_NONE
;
324 // try to obtain the column object
328 Reference
< XServiceInfo
> xServiceInfo(xConnection
, UNO_QUERY
);
329 DBG_ASSERT(xServiceInfo
.is() && xServiceInfo
->supportsService(SRV_SDB_CONNECTION
), "FmGridHeader::ExecuteDrop: invalid connection (no database access connection !)");
332 Reference
< XNameAccess
> xFields
;
333 switch (nCommandType
)
335 case CommandType::TABLE
:
337 Reference
< XTablesSupplier
> xSupplyTables(xConnection
, UNO_QUERY
);
338 Reference
< XColumnsSupplier
> xSupplyColumns
;
339 xSupplyTables
->getTables()->getByName(sCommand
) >>= xSupplyColumns
;
340 xFields
= xSupplyColumns
->getColumns();
343 case CommandType::QUERY
:
345 Reference
< XQueriesSupplier
> xSupplyQueries(xConnection
, UNO_QUERY
);
346 Reference
< XColumnsSupplier
> xSupplyColumns
;
347 xSupplyQueries
->getQueries()->getByName(sCommand
) >>= xSupplyColumns
;
348 xFields
= xSupplyColumns
->getColumns();
353 xStatement
= xConnection
->prepareStatement(sCommand
);
354 // not interested in any results
356 Reference
< XPropertySet
> xStatProps(xStatement
,UNO_QUERY
);
357 xStatProps
->setPropertyValue(rtl::OUString::createFromAscii("MaxRows"), makeAny(sal_Int32(0)));
359 xResultSet
= xStatement
->executeQuery();
360 Reference
< XColumnsSupplier
> xSupplyCols(xResultSet
, UNO_QUERY
);
361 if (xSupplyCols
.is())
362 xFields
= xSupplyCols
->getColumns();
366 if (xFields
.is() && xFields
->hasByName(sFieldName
))
367 xFields
->getByName(sFieldName
) >>= xField
;
371 ::comphelper::disposeComponent(xStatement
);
372 return DND_ACTION_NONE
;
376 // do the drop asynchronously
377 // (85957 - UI actions within the drop are not allowed, but we want to open a popup menu)
378 m_pImpl
->aDropData
= aColumn
;
379 m_pImpl
->aDropData
[daConnection
] <<= xConnection
;
380 m_pImpl
->aDropData
[daColumnObject
] <<= xField
;
382 m_pImpl
->nDropAction
= _rEvt
.mnAction
;
383 m_pImpl
->aDropPosPixel
= _rEvt
.maPosPixel
;
384 m_pImpl
->xDroppedStatement
= xStatement
;
385 m_pImpl
->xDroppedResultSet
= xResultSet
;
387 PostUserEvent(LINK(this, FmGridHeader
, OnAsyncExecuteDrop
));
391 DBG_ERROR("FmGridHeader::ExecuteDrop: caught an exception while creatin' the column !");
392 ::comphelper::disposeComponent(xStatement
);
396 return DND_ACTION_LINK
;
399 //------------------------------------------------------------------------------
400 IMPL_LINK( FmGridHeader
, OnAsyncExecuteDrop
, void*, /*NOTINTERESTEDIN*/ )
402 ::rtl::OUString sCommand
, sFieldName
,sURL
;
403 sal_Int32 nCommandType
= CommandType::COMMAND
;
404 Reference
< XPropertySet
> xField
;
405 Reference
< XConnection
> xConnection
;
407 ::rtl::OUString sDatasouce
= m_pImpl
->aDropData
.getDataSource();
408 if ( !sDatasouce
.getLength() && m_pImpl
->aDropData
.has(daConnectionResource
) )
409 m_pImpl
->aDropData
[daConnectionResource
] >>= sURL
;
410 m_pImpl
->aDropData
[daCommand
] >>= sCommand
;
411 m_pImpl
->aDropData
[daCommandType
] >>= nCommandType
;
412 m_pImpl
->aDropData
[daColumnName
] >>= sFieldName
;
413 m_pImpl
->aDropData
[daConnection
] >>= xConnection
;
414 m_pImpl
->aDropData
[daColumnObject
] >>= xField
;
418 // need number formats
419 Reference
< XNumberFormatsSupplier
> xSupplier
= OStaticDataAccessTools().getNumberFormats(xConnection
, sal_True
);
420 Reference
< XNumberFormats
> xNumberFormats
;
422 xNumberFormats
= xSupplier
->getNumberFormats();
423 if (!xNumberFormats
.is())
425 ::comphelper::disposeComponent(m_pImpl
->xDroppedResultSet
);
426 ::comphelper::disposeComponent(m_pImpl
->xDroppedStatement
);
430 // Vom Feld werden nun zwei Informationen benoetigt:
431 // a.) Name des Feldes fuer Label und ControlSource
432 // b.) FormatKey, um festzustellen, welches Feld erzeugt werden soll
433 sal_Int32 nDataType
= 0;
434 xField
->getPropertyValue(FM_PROP_FIELDTYPE
) >>= nDataType
;
435 // diese Datentypen koennen im Gridcontrol nicht verarbeitet werden
438 case DataType::LONGVARBINARY
:
439 case DataType::BINARY
:
440 case DataType::VARBINARY
:
441 case DataType::OTHER
:
442 ::comphelper::disposeComponent(m_pImpl
->xDroppedResultSet
);
443 ::comphelper::disposeComponent(m_pImpl
->xDroppedStatement
);
447 // Erstellen der Column
448 Reference
< XIndexContainer
> xCols(static_cast<FmGridControl
*>(GetParent())->GetPeer()->getColumns());
449 Reference
< XGridColumnFactory
> xFactory(xCols
, UNO_QUERY
);
451 Point aPos
= OutputToScreenPixel(m_pImpl
->aDropPosPixel
);
452 sal_uInt16 nColId
= GetItemId(m_pImpl
->aDropPosPixel
);
453 // EinfuegePosition, immer vor der aktuellen Spalte
454 sal_uInt16 nPos
= GetModelColumnPos(nColId
);
455 Reference
< XPropertySet
> xCol
, xSecondCol
;
457 // erzeugen der Column in abhaengigkeit vom type, default textfeld
458 SvULongs aPossibleTypes
;
462 case DataType::BOOLEAN
:
463 aPossibleTypes
.Insert(SID_FM_CHECKBOX
, aPossibleTypes
.Count());
465 case DataType::TINYINT
:
466 case DataType::SMALLINT
:
467 case DataType::INTEGER
:
468 aPossibleTypes
.Insert(SID_FM_NUMERICFIELD
, aPossibleTypes
.Count());
469 aPossibleTypes
.Insert(SID_FM_FORMATTEDFIELD
, aPossibleTypes
.Count());
472 case DataType::DOUBLE
:
473 case DataType::NUMERIC
:
474 case DataType::DECIMAL
:
475 aPossibleTypes
.Insert(SID_FM_FORMATTEDFIELD
, aPossibleTypes
.Count());
476 aPossibleTypes
.Insert(SID_FM_NUMERICFIELD
, aPossibleTypes
.Count());
478 case DataType::TIMESTAMP
:
479 aPossibleTypes
.Insert(SID_FM_TWOFIELDS_DATE_N_TIME
, aPossibleTypes
.Count());
480 aPossibleTypes
.Insert(SID_FM_DATEFIELD
, aPossibleTypes
.Count());
481 aPossibleTypes
.Insert(SID_FM_TIMEFIELD
, aPossibleTypes
.Count());
482 aPossibleTypes
.Insert(SID_FM_FORMATTEDFIELD
, aPossibleTypes
.Count());
485 aPossibleTypes
.Insert(SID_FM_DATEFIELD
, aPossibleTypes
.Count());
486 aPossibleTypes
.Insert(SID_FM_FORMATTEDFIELD
, aPossibleTypes
.Count());
489 aPossibleTypes
.Insert(SID_FM_TIMEFIELD
, aPossibleTypes
.Count());
490 aPossibleTypes
.Insert(SID_FM_FORMATTEDFIELD
, aPossibleTypes
.Count());
493 case DataType::VARCHAR
:
494 case DataType::LONGVARCHAR
:
496 aPossibleTypes
.Insert(SID_FM_EDIT
, aPossibleTypes
.Count());
497 aPossibleTypes
.Insert(SID_FM_FORMATTEDFIELD
, aPossibleTypes
.Count());
500 // if it's a currency field, a a "currency field" option
503 if ( ::comphelper::hasProperty(FM_PROP_ISCURRENCY
, xField
)
504 && ::comphelper::getBOOL(xField
->getPropertyValue(FM_PROP_ISCURRENCY
)))
505 aPossibleTypes
.Insert(SID_FM_CURRENCYFIELD
, 0);
509 DBG_ERROR("FmGridHeader::ExecuteDrop: Exception occured!");
512 sal_Int32 nPreferedType
= -1;
513 sal_Bool bDateNTimeCol
= sal_False
;
514 if (aPossibleTypes
.Count() != 0)
516 nPreferedType
= aPossibleTypes
[0];
517 if ((m_pImpl
->nDropAction
== DND_ACTION_LINK
) && (aPossibleTypes
.Count() > 1))
519 ImageList
aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL
) );
521 PopupMenu
aInsertMenu(SVX_RES(RID_SVXMNU_COLS
));
523 PopupMenu
* pMenu
= aInsertMenu
.GetPopupMenu(SID_FM_INSERTCOL
);
524 for (sal_uInt32 i
=0; i
<aPossibleTypes
.Count(); ++i
)
525 SetMenuItem(aImageList
, sal_uInt16(aPossibleTypes
[(sal_uInt16
)i
]), pMenu
, aTypeMenu
, sal_True
, 0);
526 nPreferedType
= aTypeMenu
.Execute(this, m_pImpl
->aDropPosPixel
);
529 bDateNTimeCol
= nPreferedType
== SID_FM_TWOFIELDS_DATE_N_TIME
;
530 sal_uInt16 nColCount
= bDateNTimeCol
? 2 : 1;
531 ::rtl::OUString sFieldService
;
535 nPreferedType
= nColCount
? SID_FM_DATEFIELD
: SID_FM_TIMEFIELD
;
537 sFieldService
= FieldServiceFromId(nPreferedType
);
538 Reference
< XPropertySet
> xThisRoundCol
;
539 if ( sFieldService
.getLength() )
540 xThisRoundCol
= xFactory
->createColumn(sFieldService
);
542 xSecondCol
= xThisRoundCol
;
544 xCol
= xThisRoundCol
;
548 if (!xCol
.is() || (bDateNTimeCol
&& !xSecondCol
.is()))
550 ::comphelper::disposeComponent(xCol
); // in case only the creation of the second column failed
551 ::comphelper::disposeComponent(m_pImpl
->xDroppedResultSet
);
552 ::comphelper::disposeComponent(m_pImpl
->xDroppedStatement
);
558 String
sTimePostfix( SVX_RES( RID_STR_POSTFIX_TIME
) );
559 xCol
->setPropertyValue(FM_PROP_LABEL
, makeAny( ::rtl::OUString( sFieldName
+ sTimePostfix
) ) );
561 String
sDatePostfix( SVX_RES( RID_STR_POSTFIX_DATE
) );
562 xSecondCol
->setPropertyValue(FM_PROP_LABEL
, makeAny( ::rtl::OUString( sFieldName
+ sDatePostfix
) ) );
565 xCol
->setPropertyValue(FM_PROP_LABEL
, makeAny(sFieldName
));
567 FormControlFactory
aControlFactory( ::comphelper::getProcessServiceFactory() );
568 aControlFactory
.initializeControlModel( DocumentClassification::classifyHostDocument( xCols
), xCol
);
569 aControlFactory
.initializeFieldDependentProperties( xField
, xCol
, xNumberFormats
);
571 xCol
->setPropertyValue(FM_PROP_CONTROLSOURCE
, makeAny(sFieldName
));
572 if ( xSecondCol
.is() )
573 xSecondCol
->setPropertyValue(FM_PROP_CONTROLSOURCE
, makeAny(sFieldName
));
577 String sRealName
,sPurePostfix
;
579 String aPostfix
[] = {
580 String( SVX_RES( RID_STR_POSTFIX_DATE
) ),
581 String( SVX_RES( RID_STR_POSTFIX_TIME
) )
584 for ( size_t i
=0; i
<2; ++i
)
586 sPurePostfix
= aPostfix
[i
];
587 sPurePostfix
.EraseLeadingChars(' ');
588 sPurePostfix
.EraseLeadingChars('(');
589 sPurePostfix
.EraseTrailingChars(')');
590 sRealName
= sFieldName
;
592 sRealName
+= sPurePostfix
;
594 xSecondCol
->setPropertyValue(FM_PROP_NAME
, makeAny(::rtl::OUString(sRealName
)));
596 xCol
->setPropertyValue(FM_PROP_NAME
, makeAny(::rtl::OUString(sRealName
)));
600 xCol
->setPropertyValue(FM_PROP_NAME
, makeAny(sFieldName
));
605 xCols
->insertByIndex(nPos
, aElement
);
609 aElement
<<= xSecondCol
;
610 xCols
->insertByIndex(nPos
== (sal_uInt16
)-1 ? nPos
: ++nPos
, aElement
);
613 // ist die component::Form an die Datenbankangebunden?
614 Reference
< XFormComponent
> xFormCp(xCols
, UNO_QUERY
);
615 Reference
< XPropertySet
> xForm(xFormCp
->getParent(), UNO_QUERY
);
618 if (!::comphelper::getString(xForm
->getPropertyValue(FM_PROP_DATASOURCE
)).getLength())
620 if ( sDatasouce
.getLength() )
621 xForm
->setPropertyValue(FM_PROP_DATASOURCE
, makeAny(sDatasouce
));
623 xForm
->setPropertyValue(FM_PROP_URL
, makeAny(sURL
));
626 if (!::comphelper::getString(xForm
->getPropertyValue(FM_PROP_COMMAND
)).getLength())
628 xForm
->setPropertyValue(FM_PROP_COMMAND
, makeAny(sCommand
));
630 switch (nCommandType
)
632 case CommandType::TABLE
:
633 aCommandType
<<= (sal_Int32
)CommandType::TABLE
;
635 case CommandType::QUERY
:
636 aCommandType
<<= (sal_Int32
)CommandType::QUERY
;
639 aCommandType
<<= (sal_Int32
)CommandType::COMMAND
;
640 xForm
->setPropertyValue(FM_PROP_ESCAPE_PROCESSING
, bool2any((sal_Bool
)(2 == nCommandType
)));
643 xForm
->setPropertyValue(FM_PROP_COMMANDTYPE
, aCommandType
);
649 DBG_ERROR("FmGridHeader::OnAsyncExecuteDrop: caught an exception while creatin' the column !");
650 ::comphelper::disposeComponent(m_pImpl
->xDroppedResultSet
);
651 ::comphelper::disposeComponent(m_pImpl
->xDroppedStatement
);
655 ::comphelper::disposeComponent(m_pImpl
->xDroppedResultSet
);
656 ::comphelper::disposeComponent(m_pImpl
->xDroppedStatement
);
660 //------------------------------------------------------------------------------
661 void FmGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId
, PopupMenu
& rMenu
)
663 sal_Bool bDesignMode
= static_cast<FmGridControl
*>(GetParent())->IsDesignMode();
665 Reference
< ::com::sun::star::container::XIndexContainer
> xCols(static_cast<FmGridControl
*>(GetParent())->GetPeer()->getColumns());
666 // Aufbau des Insert Menues
667 // mark the column if nColId != HEADERBAR_ITEM_NOTFOUND
670 sal_uInt16 nPos2
= GetModelColumnPos(nColId
);
672 Reference
< ::com::sun::star::container::XIndexContainer
> xColumns(static_cast<FmGridControl
*>(GetParent())->GetPeer()->getColumns());
673 Reference
< ::com::sun::star::beans::XPropertySet
> xColumn
;
674 ::cppu::extractInterface(xColumn
, xColumns
->getByIndex(nPos2
));
675 Reference
< ::com::sun::star::view::XSelectionSupplier
> xSelSupplier(xColumns
, UNO_QUERY
);
676 if (xSelSupplier
.is())
677 xSelSupplier
->select(makeAny(xColumn
));
680 // EinfuegePosition, immer vor der aktuellen Spalte
681 sal_uInt16 nPos
= GetModelColumnPos(nColId
);
682 sal_Bool bMarked
= nColId
&& static_cast<FmGridControl
*>(GetParent())->isColumnMarked(nColId
);
684 ImageList
aImageList( SVX_RES(RID_SVXIMGLIST_FMEXPL
) );
685 PopupMenu
* pControlMenu
= new PopupMenu
;
687 PopupMenu
* pMenu
= rMenu
.GetPopupMenu(SID_FM_INSERTCOL
);
690 SetMenuItem(aImageList
, SID_FM_EDIT
, pMenu
, *pControlMenu
, bDesignMode
);
691 SetMenuItem(aImageList
, SID_FM_CHECKBOX
, pMenu
, *pControlMenu
, bDesignMode
);
692 SetMenuItem(aImageList
, SID_FM_COMBOBOX
, pMenu
, *pControlMenu
, bDesignMode
);
693 SetMenuItem(aImageList
, SID_FM_LISTBOX
, pMenu
, *pControlMenu
, bDesignMode
);
694 SetMenuItem(aImageList
, SID_FM_DATEFIELD
, pMenu
, *pControlMenu
, bDesignMode
);
695 SetMenuItem(aImageList
, SID_FM_TIMEFIELD
, pMenu
, *pControlMenu
, bDesignMode
);
696 SetMenuItem(aImageList
, SID_FM_NUMERICFIELD
, pMenu
, *pControlMenu
, bDesignMode
);
697 SetMenuItem(aImageList
, SID_FM_CURRENCYFIELD
, pMenu
, *pControlMenu
, bDesignMode
);
698 SetMenuItem(aImageList
, SID_FM_PATTERNFIELD
, pMenu
, *pControlMenu
, bDesignMode
);
699 SetMenuItem(aImageList
, SID_FM_FORMATTEDFIELD
, pMenu
, *pControlMenu
, bDesignMode
);
702 if (pMenu
&& xCols
.is() && nColId
)
704 Reference
< ::com::sun::star::beans::XPropertySet
> xSet
;
705 ::cppu::extractInterface(xSet
, xCols
->getByIndex(nPos
));
707 xSet
->getPropertyValue(FM_PROP_CLASSID
) >>= nClassId
;
709 Reference
< ::com::sun::star::io::XPersistObject
> xServiceQuestion(xSet
, UNO_QUERY
);
710 sal_Int32 nColType
= xServiceQuestion
.is() ? getColumnTypeByModelName(xServiceQuestion
->getServiceName()) : 0;
711 if (nColType
== TYPE_TEXTFIELD
)
712 { // edit fields and formatted fields have the same service name, thus getColumnTypeByModelName returns TYPE_TEXTFIELD
713 // in both cases. And as columns don't have an ::com::sun::star::lang::XServiceInfo interface, we have to distinguish both
714 // types via the existence of special properties
715 Reference
< ::com::sun::star::beans::XPropertySet
> xProps(xSet
, UNO_QUERY
);
718 Reference
< ::com::sun::star::beans::XPropertySetInfo
> xPropsInfo
= xProps
->getPropertySetInfo();
719 if (xPropsInfo
.is() && xPropsInfo
->hasPropertyByName(FM_PROP_FORMATSSUPPLIER
))
720 nColType
= TYPE_FORMATTEDFIELD
;
724 pControlMenu
->EnableItem(SID_FM_EDIT
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_TEXTFIELD
));
725 pControlMenu
->EnableItem(SID_FM_COMBOBOX
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_COMBOBOX
));
726 pControlMenu
->EnableItem(SID_FM_LISTBOX
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_LISTBOX
));
727 pControlMenu
->EnableItem(SID_FM_CHECKBOX
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_CHECKBOX
));
728 pControlMenu
->EnableItem(SID_FM_DATEFIELD
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_DATEFIELD
));
729 pControlMenu
->EnableItem(SID_FM_NUMERICFIELD
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_NUMERICFIELD
));
730 pControlMenu
->EnableItem(SID_FM_TIMEFIELD
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_TIMEFIELD
));
731 pControlMenu
->EnableItem(SID_FM_CURRENCYFIELD
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_CURRENCYFIELD
));
732 pControlMenu
->EnableItem(SID_FM_PATTERNFIELD
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_PATTERNFIELD
));
733 pControlMenu
->EnableItem(SID_FM_FORMATTEDFIELD
+ nChangeTypeOffset
, bDesignMode
&& (nColType
!= TYPE_FORMATTEDFIELD
));
734 rMenu
.SetPopupMenu(SID_FM_CHANGECOL
, pControlMenu
);
737 rMenu
.EnableItem(SID_FM_INSERTCOL
, bDesignMode
&& xCols
.is());
738 rMenu
.EnableItem(SID_FM_DELETECOL
, bDesignMode
&& bMarked
&& xCols
.is());
739 rMenu
.EnableItem(SID_FM_CHANGECOL
, bDesignMode
&& bMarked
&& xCols
.is());
740 rMenu
.EnableItem(SID_FM_SHOW_PROPERTY_BROWSER
, bDesignMode
&& bMarked
&& xCols
.is());
742 PopupMenu
* pShowColsMenu
= rMenu
.GetPopupMenu(SID_FM_SHOWCOLS
);
743 sal_uInt16 nHiddenCols
= 0;
748 // check for hidden cols
749 Reference
< ::com::sun::star::beans::XPropertySet
> xCurCol
;
751 for (sal_uInt16 i
=0; i
<xCols
->getCount(); ++i
)
753 ::cppu::extractInterface(xCurCol
, xCols
->getByIndex(i
));
754 DBG_ASSERT(xCurCol
.is(), "FmGridHeader::PreExecuteColumnContextMenu : the Peer has invalid columns !");
755 aHidden
= xCurCol
->getPropertyValue(FM_PROP_HIDDEN
);
756 DBG_ASSERT(aHidden
.getValueType().getTypeClass() == TypeClass_BOOLEAN
,
757 "FmGridHeader::PreExecuteColumnContextMenu : the property 'hidden' should be boolean !");
758 if (::comphelper::getBOOL(aHidden
))
760 // put the column name into the 'show col' menu
761 if (nHiddenCols
< 16)
762 { // (only the first 16 items to keep the menu rather small)
763 aName
= xCurCol
->getPropertyValue(FM_PROP_LABEL
);
764 pShowColsMenu
->InsertItem(nHiddenCols
+ 1, ::comphelper::getString(aName
), 0, nHiddenCols
);
765 // the ID is arbitrary, but should be unique within the whole menu
771 pShowColsMenu
->EnableItem(SID_FM_SHOWCOLS_MORE
, xCols
.is() && (nHiddenCols
> 16));
772 pShowColsMenu
->EnableItem(SID_FM_SHOWALLCOLS
, xCols
.is() && (nHiddenCols
> 0));
775 // allow the 'hide column' item ?
776 sal_Bool bAllowHide
= bMarked
; // a column is marked
777 bAllowHide
= bAllowHide
|| (!bDesignMode
&& (nPos
!= (sal_uInt16
)-1)); // OR we are in alive mode and have hit a column
778 bAllowHide
= bAllowHide
&& xCols
.is(); // AND we have a column container
779 bAllowHide
= bAllowHide
&& (xCols
->getCount()-nHiddenCols
> 1); // AND there are at least two visible columns
780 rMenu
.EnableItem(SID_FM_HIDECOL
, bAllowHide
);
782 sal_Bool bChecked
= sal_False
;
786 SfxViewFrame
* pCurrentFrame
= SfxViewFrame::Current();
787 SfxItemState eState
= SFX_ITEM_UNKNOWN
;
788 // ask the bindings of the current view frame (which should be the one we're residing in) for the state
791 SfxPoolItem
* pItem
= NULL
;
792 eState
= pCurrentFrame
->GetBindings().QueryState(SID_FM_CTL_PROPERTIES
, pItem
);
794 if (eState
>= SFX_ITEM_AVAILABLE
&& pItem
)
796 bChecked
= pItem
->ISA(SfxBoolItem
) && ((SfxBoolItem
*)pItem
)->GetValue();
797 rMenu
.CheckItem(SID_FM_SHOW_PROPERTY_BROWSER
,bChecked
);
804 enum InspectorAction
{ eOpenInspector
, eCloseInspector
, eUpdateInspector
, eNone
};
806 //------------------------------------------------------------------------------
807 void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId
, const PopupMenu
& rMenu
, sal_uInt16 nExecutionResult
)
809 Reference
< ::com::sun::star::container::XIndexContainer
> xCols(static_cast<FmGridControl
*>(GetParent())->GetPeer()->getColumns());
810 sal_uInt16 nPos
= GetModelColumnPos(nColId
);
812 // remove and delet the menu we inserted in PreExecuteColumnContextMenu
813 PopupMenu
* pControlMenu
= rMenu
.GetPopupMenu(SID_FM_CHANGECOL
);
816 ::rtl::OUString aFieldType
;
817 sal_Bool bReplace
= sal_False
;
818 InspectorAction eInspectorAction
= eNone
;
819 Reference
< XPropertySet
> xColumnToInspect
;
820 switch (nExecutionResult
)
822 case SID_FM_DELETECOL
:
824 Reference
< XInterface
> xCol
;
825 ::cppu::extractInterface(xCol
, xCols
->getByIndex(nPos
));
826 xCols
->removeByIndex(nPos
);
827 ::comphelper::disposeComponent(xCol
);
829 case SID_FM_SHOW_PROPERTY_BROWSER
:
830 eInspectorAction
= rMenu
.IsItemChecked( SID_FM_SHOW_PROPERTY_BROWSER
) ? eOpenInspector
: eCloseInspector
;
831 xColumnToInspect
.set( xCols
->getByIndex( nPos
), UNO_QUERY
);
833 case SID_FM_EDIT
+ nChangeTypeOffset
:
836 aFieldType
= FM_COL_TEXTFIELD
;
838 case SID_FM_COMBOBOX
+ nChangeTypeOffset
:
840 case SID_FM_COMBOBOX
:
841 aFieldType
= FM_COL_COMBOBOX
;
843 case SID_FM_LISTBOX
+ nChangeTypeOffset
:
846 aFieldType
= FM_COL_LISTBOX
;
848 case SID_FM_CHECKBOX
+ nChangeTypeOffset
:
850 case SID_FM_CHECKBOX
:
851 aFieldType
= FM_COL_CHECKBOX
;
853 case SID_FM_DATEFIELD
+ nChangeTypeOffset
:
855 case SID_FM_DATEFIELD
:
856 aFieldType
= FM_COL_DATEFIELD
;
858 case SID_FM_TIMEFIELD
+ nChangeTypeOffset
:
860 case SID_FM_TIMEFIELD
:
861 aFieldType
= FM_COL_TIMEFIELD
;
863 case SID_FM_NUMERICFIELD
+ nChangeTypeOffset
:
865 case SID_FM_NUMERICFIELD
:
866 aFieldType
= FM_COL_NUMERICFIELD
;
868 case SID_FM_CURRENCYFIELD
+ nChangeTypeOffset
:
870 case SID_FM_CURRENCYFIELD
:
871 aFieldType
= FM_COL_CURRENCYFIELD
;
873 case SID_FM_PATTERNFIELD
+ nChangeTypeOffset
:
875 case SID_FM_PATTERNFIELD
:
876 aFieldType
= FM_COL_PATTERNFIELD
;
878 case SID_FM_FORMATTEDFIELD
+ nChangeTypeOffset
:
880 case SID_FM_FORMATTEDFIELD
:
881 aFieldType
= FM_COL_FORMATTEDFIELD
;
885 Reference
< ::com::sun::star::beans::XPropertySet
> xCurCol
;
886 ::cppu::extractInterface(xCurCol
, xCols
->getByIndex(nPos
));
887 xCurCol
->setPropertyValue(FM_PROP_HIDDEN
, makeAny((sal_Bool
)sal_True
));
890 case SID_FM_SHOWCOLS_MORE
:
892 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
895 AbstractFmShowColsDialog
* pDlg
= pFact
->CreateFmShowColsDialog(NULL
, RID_SVX_DLG_SHOWGRIDCOLUMNS
);
896 DBG_ASSERT(pDlg
, "Dialogdiet fail!");//CHINA001
897 pDlg
->SetColumns(xCols
);
904 case SID_FM_SHOWALLCOLS
:
906 // just iterate through all the cols ...
907 Reference
< ::com::sun::star::beans::XPropertySet
> xCurCol
;
908 for (sal_uInt16 i
=0; i
<xCols
->getCount(); ++i
)
910 ::cppu::extractInterface(xCurCol
, xCols
->getByIndex(i
));
911 xCurCol
->setPropertyValue(FM_PROP_HIDDEN
, makeAny((sal_Bool
)sal_False
));
913 // TODO : there must be a more clever way to do this ....
914 // with the above the view is updated after every single model update ...
918 if (nExecutionResult
>0 && nExecutionResult
<=16)
919 { // it was a "show column/<colname>" command (there are at most 16 such items)
920 // search the nExecutionResult'th hidden col
921 Reference
< ::com::sun::star::beans::XPropertySet
> xCurCol
;
922 for (sal_uInt16 i
=0; i
<xCols
->getCount() && nExecutionResult
; ++i
)
924 ::cppu::extractInterface(xCurCol
, xCols
->getByIndex(i
));
925 Any aHidden
= xCurCol
->getPropertyValue(FM_PROP_HIDDEN
);
926 if (::comphelper::getBOOL(aHidden
))
927 if (!--nExecutionResult
)
929 xCurCol
->setPropertyValue(FM_PROP_HIDDEN
, makeAny((sal_Bool
)sal_False
));
937 if ( aFieldType
.getLength() )
941 Reference
< XGridColumnFactory
> xFactory( xCols
, UNO_QUERY_THROW
);
942 Reference
< XPropertySet
> xNewCol( xFactory
->createColumn( aFieldType
), UNO_SET_THROW
);
946 // ein paar Properties hinueberretten
947 Reference
< XPropertySet
> xReplaced( xCols
->getByIndex( nPos
), UNO_QUERY
);
949 OStaticDataAccessTools().TransferFormComponentProperties(
950 xReplaced
, xNewCol
, Application::GetSettings().GetUILocale() );
952 xCols
->replaceByIndex( nPos
, makeAny( xNewCol
) );
953 ::comphelper::disposeComponent( xReplaced
);
955 eInspectorAction
= eUpdateInspector
;
956 xColumnToInspect
= xNewCol
;
960 FormControlFactory
factory( ::comphelper::getProcessServiceFactory() );
962 ::rtl::OUString sLabel
= factory
.getDefaultUniqueName_ByComponentType(
963 Reference
< XNameAccess
>( xCols
, UNO_QUERY_THROW
), xNewCol
);
964 xNewCol
->setPropertyValue( FM_PROP_LABEL
, makeAny( sLabel
) );
965 xNewCol
->setPropertyValue( FM_PROP_NAME
, makeAny( sLabel
) );
967 factory
.initializeControlModel( DocumentClassification::classifyHostDocument( xCols
), xNewCol
);
969 xCols
->insertByIndex( nPos
, makeAny( xNewCol
) );
972 catch( const Exception
& )
974 DBG_UNHANDLED_EXCEPTION();
978 SfxViewFrame
* pCurrentFrame
= SfxViewFrame::Current();
979 OSL_ENSURE( pCurrentFrame
, "FmGridHeader::PostExecuteColumnContextMenu: no view frame -> no bindings -> no property browser!" );
982 if ( eInspectorAction
== eUpdateInspector
)
984 if ( !pCurrentFrame
->HasChildWindow( SID_FM_SHOW_PROPERTIES
) )
985 eInspectorAction
= eNone
;
988 if ( eInspectorAction
!= eNone
)
990 FmInterfaceItem
aIFaceItem( SID_FM_SHOW_PROPERTY_BROWSER
, xColumnToInspect
);
991 SfxBoolItem
aShowItem( SID_FM_SHOW_PROPERTIES
, eInspectorAction
== eCloseInspector
? FALSE
: TRUE
);
993 pCurrentFrame
->GetBindings().GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER
, SFX_CALLMODE_ASYNCHRON
,
994 &aIFaceItem
, &aShowItem
, 0L );
999 //------------------------------------------------------------------------------
1000 void FmGridHeader::triggerColumnContextMenu( const ::Point
& _rPreferredPos
)
1003 sal_uInt16 nColId
= GetItemId( _rPreferredPos
);
1006 PopupMenu
aContextMenu( SVX_RES( RID_SVXMNU_COLS
) );
1008 // let derivees modify the menu
1009 PreExecuteColumnContextMenu( nColId
, aContextMenu
);
1010 aContextMenu
.RemoveDisabledEntries( sal_True
, sal_True
);
1013 sal_uInt16 nResult
= aContextMenu
.Execute( this, _rPreferredPos
);
1015 // let derivees handle the result
1016 PostExecuteColumnContextMenu( nColId
, aContextMenu
, nResult
);
1019 //------------------------------------------------------------------------------
1020 void FmGridHeader::Command(const CommandEvent
& rEvt
)
1022 switch (rEvt
.GetCommand())
1024 case COMMAND_CONTEXTMENU
:
1026 if (!rEvt
.IsMouseEvent())
1029 triggerColumnContextMenu( rEvt
.GetMousePosPixel() );
1033 EditBrowserHeader::Command(rEvt
);
1037 //------------------------------------------------------------------------------
1038 FmGridControl::FmGridControl(
1039 Reference
< ::com::sun::star::lang::XMultiServiceFactory
> _rxFactory
,
1041 FmXGridPeer
* _pPeer
,
1043 :DbGridControl(_rxFactory
, pParent
, nBits
)
1045 ,m_nCurrentSelectedColumn(-1)
1046 ,m_nMarkedColumnId(BROWSER_INVALIDID
)
1047 ,m_bSelecting(sal_False
)
1048 ,m_bInColumnMove(sal_False
)
1050 EnableInteractiveRowHeight( );
1053 //------------------------------------------------------------------------------
1054 void FmGridControl::Command(const CommandEvent
& _rEvt
)
1056 if ( COMMAND_CONTEXTMENU
== _rEvt
.GetCommand() )
1058 FmGridHeader
* pMyHeader
= static_cast< FmGridHeader
* >( GetHeaderBar() );
1059 if ( pMyHeader
&& !_rEvt
.IsMouseEvent() )
1060 { // context menu requested by keyboard
1061 if ( 1 == GetSelectColumnCount() || IsDesignMode() )
1063 sal_uInt16 nSelId
= GetColumnId(
1064 sal::static_int_cast
< USHORT
>( FirstSelectedColumn() ) );
1065 ::Rectangle
aColRect( GetFieldRectPixel( 0, nSelId
, sal_False
) );
1067 Point
aRelativePos( pMyHeader
->ScreenToOutputPixel( OutputToScreenPixel( aColRect
.TopCenter() ) ) );
1068 pMyHeader
->triggerColumnContextMenu( aRelativePos
, FmGridHeader::AccessControl() );
1076 DbGridControl::Command( _rEvt
);
1079 // ::com::sun::star::beans::XPropertyChangeListener
1080 //------------------------------------------------------------------------------
1081 void FmGridControl::propertyChange(const ::com::sun::star::beans::PropertyChangeEvent
& evt
)
1083 if (evt
.PropertyName
== FM_PROP_ROWCOUNT
)
1085 // if we're not in the main thread call AdjustRows asynchronously
1086 implAdjustInSolarThread(sal_True
);
1090 const DbGridRowRef
& xRow
= GetCurrentRow();
1091 // waehrend Positionierung wird kein abgleich der Properties vorgenommen
1092 Reference
<XPropertySet
> xSet(evt
.Source
,UNO_QUERY
);
1093 if (xRow
.Is() && (::cppu::any2bool(xSet
->getPropertyValue(FM_PROP_ISNEW
))|| CompareBookmark(getDataSource()->getBookmark(), xRow
->GetBookmark())))
1095 if (evt
.PropertyName
== FM_PROP_ISMODIFIED
)
1097 // modified or clean ?
1098 GridRowStatus eStatus
= ::comphelper::getBOOL(evt
.NewValue
) ? GRS_MODIFIED
: GRS_CLEAN
;
1099 if (eStatus
!= xRow
->GetStatus())
1101 xRow
->SetStatus(eStatus
);
1102 vos::OGuard
aGuard( Application::GetSolarMutex() );
1103 RowModified(GetCurrentPos());
1109 //------------------------------------------------------------------------------
1110 void FmGridControl::SetDesignMode(sal_Bool bMode
)
1112 sal_Bool bOldMode
= IsDesignMode();
1113 DbGridControl::SetDesignMode(bMode
);
1114 if (bOldMode
!= bMode
)
1118 // selection aufheben
1119 markColumn(USHRT_MAX
);
1123 Reference
< ::com::sun::star::container::XIndexContainer
> xColumns(GetPeer()->getColumns());
1124 Reference
< ::com::sun::star::view::XSelectionSupplier
> xSelSupplier(xColumns
, UNO_QUERY
);
1125 if (xSelSupplier
.is())
1127 Any aSelection
= xSelSupplier
->getSelection();
1128 Reference
< ::com::sun::star::beans::XPropertySet
> xColumn
;
1129 if (aSelection
.getValueType().getTypeClass() == TypeClass_INTERFACE
)
1130 ::cppu::extractInterface(xColumn
, aSelection
);
1131 Reference
< XInterface
> xCurrent
;
1132 for (sal_uInt16 i
=0; i
<xColumns
->getCount(); ++i
)
1134 ::cppu::extractInterface(xCurrent
, xColumns
->getByIndex(i
));
1135 if (xCurrent
== xColumn
)
1137 markColumn(GetColumnIdFromModelPos(i
));
1146 //------------------------------------------------------------------------------
1147 void FmGridControl::DeleteSelectedRows()
1152 // how many rows are selected?
1153 sal_Int32 nSelectedRows
= GetSelectRowCount();
1155 // the current line should be deleted but it is currently in edit mode
1156 if ( IsCurrentAppending() )
1158 // is the insert row selected
1159 if (GetEmptyRow().Is() && IsRowSelected(GetRowCount() - 1))
1163 if (nSelectedRows
<= 0)
1166 // try to confirm the delete
1167 Reference
< ::com::sun::star::frame::XDispatchProvider
> xDispatcher
= (::com::sun::star::frame::XDispatchProvider
*)GetPeer();
1168 if (xDispatcher
.is())
1170 ::com::sun::star::util::URL aUrl
;
1171 aUrl
.Complete
= FMURL_CONFIRM_DELETION
;
1172 // #100312# ------------
1173 Reference
< ::com::sun::star::util::XURLTransformer
> xTransformer(
1174 ::comphelper::getProcessServiceFactory()->createInstance(
1175 ::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")), UNO_QUERY
);
1176 if( xTransformer
.is() )
1177 xTransformer
->parseStrict( aUrl
);
1179 Reference
< ::com::sun::star::frame::XDispatch
> xDispatch
= xDispatcher
->queryDispatch(aUrl
, rtl::OUString(), 0);
1180 Reference
< ::com::sun::star::form::XConfirmDeleteListener
> xConfirm(xDispatch
, UNO_QUERY
);
1183 ::com::sun::star::sdb::RowChangeEvent aEvent
;
1184 aEvent
.Source
= (Reference
< XInterface
> )(*getDataSource());
1185 aEvent
.Rows
= nSelectedRows
;
1186 aEvent
.Action
= ::com::sun::star::sdb::RowChangeAction::DELETE
;
1187 if (!xConfirm
->confirmDelete(aEvent
))
1192 const MultiSelection
* pRowSelection
= GetSelection();
1193 if ( pRowSelection
&& pRowSelection
->IsAllSelected() )
1195 BeginCursorAction();
1196 CursorWrapper
* pCursor
= getDataSource();
1197 Reference
< XResultSetUpdate
> xUpdateCursor((Reference
< XInterface
>)*pCursor
, UNO_QUERY
);
1200 pCursor
->beforeFirst();
1201 while( pCursor
->next() )
1202 xUpdateCursor
->deleteRow();
1204 SetUpdateMode(sal_False
);
1207 xUpdateCursor
->moveToInsertRow();
1209 catch(const Exception
&)
1211 OSL_ENSURE(0,"Exception caught while deleting rows!");
1213 // An den DatenCursor anpassen
1214 AdjustDataSource(sal_True
);
1216 SetUpdateMode(sal_True
);
1220 Reference
< ::com::sun::star::sdbcx::XDeleteRows
> xDeleteThem((Reference
< XInterface
>)*getDataSource(), UNO_QUERY
);
1222 // colect the bookmarks of the selected rows
1223 Sequence
< Any
> aBookmarks
= getSelectionBookmarks();
1225 // determine the next row to position after deletion
1227 sal_Bool bNewPos
= sal_False
;
1228 // if the current row isn't selected we take the row as row after deletion
1229 OSL_ENSURE( GetCurrentRow().Is(), "FmGridControl::DeleteSelectedRows: no current row here?" );
1230 // crash reports suggest it can happen we don't have a current row - how?
1231 // #154303# / 2008-04-23 / frank.schoenheit@sun.com
1232 if ( !IsRowSelected( GetCurrentPos() ) && !IsCurrentAppending() && GetCurrentRow().Is() )
1234 aBookmark
= GetCurrentRow()->GetBookmark();
1239 // we look for the first row after the selected block for selection
1240 long nIdx
= LastSelectedRow() + 1;
1241 if (nIdx
< GetRowCount() - 1)
1243 // there is a next row to position on
1244 if (SeekCursor(nIdx
))
1246 GetSeekRow()->SetState(m_pSeekCursor
, sal_True
);
1249 // if it's not the row for inserting we keep the bookmark
1250 if (!IsInsertionRow(nIdx
))
1251 aBookmark
= m_pSeekCursor
->getBookmark();
1256 // we look for the first row before the selected block for selection after deletion
1257 nIdx
= FirstSelectedRow() - 1;
1258 if (nIdx
>= 0 && SeekCursor(nIdx
))
1260 GetSeekRow()->SetState(m_pSeekCursor
, sal_True
);
1263 aBookmark
= m_pSeekCursor
->getBookmark();
1268 // Sind alle Zeilen Selectiert
1269 // Zweite bedingung falls keine einguegeZeile existiert
1270 sal_Bool bAllSelected
= GetTotalCount() == nSelectedRows
|| GetRowCount() == nSelectedRows
;
1272 BeginCursorAction();
1274 // now delete the row
1275 Sequence
<sal_Int32
> aDeletedRows
;
1276 SetUpdateMode( FALSE
);
1279 aDeletedRows
= xDeleteThem
->deleteRows(aBookmarks
);
1281 catch(SQLException
&)
1284 SetUpdateMode( TRUE
);
1286 // how many rows are deleted?
1287 sal_Int32 nDeletedRows
= 0;
1288 const sal_Int32
* pSuccess
= aDeletedRows
.getConstArray();
1289 for (sal_Int32 i
= 0; i
< aDeletedRows
.getLength(); i
++)
1295 // sind Zeilen geloescht worden?
1298 SetUpdateMode(sal_False
);
1302 // did we delete all the rows than try to move to the next possible row
1303 if (nDeletedRows
== aDeletedRows
.getLength())
1305 // there exists a new position to move on
1308 if (aBookmark
.hasValue())
1309 getDataSource()->moveToBookmark(aBookmark
);
1310 // no valid bookmark so move to the insert row
1313 Reference
< XResultSetUpdate
> xUpdateCursor((Reference
< XInterface
>)*m_pDataCursor
, UNO_QUERY
);
1314 xUpdateCursor
->moveToInsertRow();
1319 Reference
< ::com::sun::star::beans::XPropertySet
> xSet((Reference
< XInterface
>)*m_pDataCursor
, UNO_QUERY
);
1321 sal_Int32
nRecordCount(0);
1322 xSet
->getPropertyValue(FM_PROP_ROWCOUNT
) >>= nRecordCount
;
1323 if ( m_pDataCursor
->rowDeleted() )
1326 // there are no rows left and we have an insert row
1327 if (!nRecordCount
&& GetEmptyRow().Is())
1329 Reference
< XResultSetUpdate
> xUpdateCursor((Reference
< XInterface
>)*m_pDataCursor
, UNO_QUERY
);
1330 xUpdateCursor
->moveToInsertRow();
1332 else if (nRecordCount
)
1333 // move to the first row
1334 getDataSource()->first();
1337 // not all the rows where deleted, so move to the first row which remained in the resultset
1340 for (sal_Int32 i
= 0; i
< aDeletedRows
.getLength(); i
++)
1344 getDataSource()->moveToBookmark(aBookmarks
.getConstArray()[i
]);
1350 catch(const Exception
&)
1354 // positioning went wrong so try to move to the first row
1355 getDataSource()->first();
1357 catch(const Exception
&)
1362 // An den DatenCursor anpassen
1363 AdjustDataSource(sal_True
);
1365 // es konnten nicht alle Zeilen geloescht werden
1366 // da nie nicht geloeschten wieder selektieren
1367 if (nDeletedRows
< nSelectedRows
)
1369 // waren alle selektiert
1373 if (IsInsertionRow(GetRowCount() - 1)) // einfuegeZeile nicht
1374 SelectRow(GetRowCount() - 1, sal_False
);
1378 // select the remaining rows
1379 for (sal_Int32 i
= 0; i
< aDeletedRows
.getLength(); i
++)
1385 m_pSeekCursor
->moveToBookmark(m_pDataCursor
->getBookmark());
1386 SetSeekPos(m_pSeekCursor
->getRow() - 1);
1387 SelectRow(GetSeekPos());
1390 catch(const Exception
&)
1392 // keep the seekpos in all cases
1393 SetSeekPos(m_pSeekCursor
->getRow() - 1);
1400 SetUpdateMode(sal_True
);
1402 else // Zeile konnte nicht geloescht werden
1407 // currentrow is the insert row?
1408 if (!IsCurrentAppending())
1409 getDataSource()->refreshRow();
1411 catch(const Exception
&)
1417 // if there is no selection anymore we can start editing
1418 if (!GetSelectRowCount())
1423 // XCurrentRecordListener
1424 //------------------------------------------------------------------------------
1425 void FmGridControl::positioned(const ::com::sun::star::lang::EventObject
& /*rEvent*/)
1427 TRACE_RANGE("FmGridControl::positioned");
1428 // position on the data source (force it to be done in the main thread)
1429 implAdjustInSolarThread(sal_False
);
1432 //------------------------------------------------------------------------------
1433 sal_Bool
FmGridControl::commit()
1435 // Commit nur ausfuehren, wenn nicht bereits ein Update vom ::com::sun::star::form::component::GridControl ausgefuehrt
1439 if (Controller().Is() && Controller()->IsModified())
1441 if (!SaveModified())
1448 //------------------------------------------------------------------------------
1449 void FmGridControl::inserted(const ::com::sun::star::lang::EventObject
& /*rEvent*/)
1451 const DbGridRowRef
& xRow
= GetCurrentRow();
1455 // Zeile ist eingefuegt worden, dann den status und mode zuruecksetzen
1456 xRow
->SetState(m_pDataCursor
, sal_False
);
1457 xRow
->SetNew(sal_False
);
1461 // XCancelUpdateRecordListener
1462 //------------------------------------------------------------------------------
1463 void FmGridControl::restored(const ::com::sun::star::lang::EventObject
& rEvent
)
1465 if (!GetCurrentRow().Is())
1468 sal_Bool bAppending
= GetCurrentRow()->IsNew();
1469 sal_Bool bDirty
= GetCurrentRow()->IsModified();
1470 if (bAppending
&& (EditBrowseBox::IsModified() || bDirty
))
1472 if (Controller().Is())
1473 Controller()->ClearModified();
1475 // jetzt die Zeile herausnehmen
1476 RowRemoved(GetRowCount() - 1, 1, sal_True
);
1477 GetNavigationBar().InvalidateAll();
1483 //------------------------------------------------------------------------------
1484 BrowserHeader
* FmGridControl::imp_CreateHeaderBar(BrowseBox
* pParent
)
1486 DBG_ASSERT( pParent
== this, "FmGridControl::imp_CreateHeaderBar: parent?" );
1487 return new FmGridHeader( pParent
);
1490 //------------------------------------------------------------------------------
1491 void FmGridControl::markColumn(sal_uInt16 nId
)
1493 if (GetHeaderBar() && m_nMarkedColumnId
!= nId
)
1496 if (m_nMarkedColumnId
!= BROWSER_INVALIDID
)
1498 HeaderBarItemBits aBits
= GetHeaderBar()->GetItemBits(m_nMarkedColumnId
) & ~HIB_FLAT
;
1499 GetHeaderBar()->SetItemBits(m_nMarkedColumnId
, aBits
);
1503 if (nId
!= BROWSER_INVALIDID
)
1505 HeaderBarItemBits aBits
= GetHeaderBar()->GetItemBits(nId
) | HIB_FLAT
;
1506 GetHeaderBar()->SetItemBits(nId
, aBits
);
1508 m_nMarkedColumnId
= nId
;
1512 //------------------------------------------------------------------------------
1513 sal_Bool
FmGridControl::isColumnMarked(sal_uInt16 nId
) const
1515 return m_nMarkedColumnId
== nId
;
1518 //------------------------------------------------------------------------------
1519 long FmGridControl::QueryMinimumRowHeight()
1521 long nMinimalLogicHeight
= 20; // 0.2 cm
1522 long nMinimalPixelHeight
= LogicToPixel( Point( 0, nMinimalLogicHeight
), MAP_10TH_MM
).Y();
1523 return CalcZoom( nMinimalPixelHeight
);
1526 //------------------------------------------------------------------------------
1527 void FmGridControl::RowHeightChanged()
1529 DbGridControl::RowHeightChanged();
1531 Reference
< XPropertySet
> xModel( GetPeer()->getColumns(), UNO_QUERY
);
1532 DBG_ASSERT( xModel
.is(), "FmGridControl::RowHeightChanged: no model!" );
1537 sal_Int32 nUnzoomedPixelHeight
= CalcReverseZoom( GetDataRowHeight() );
1538 Any aProperty
= makeAny( (sal_Int32
)PixelToLogic( Point( 0, nUnzoomedPixelHeight
), MAP_10TH_MM
).Y() );
1539 xModel
->setPropertyValue( FM_PROP_ROWHEIGHT
, aProperty
);
1541 catch( const Exception
& )
1543 OSL_ENSURE( sal_False
, "FmGridControl::RowHeightChanged: caught an exception!" );
1548 //------------------------------------------------------------------------------
1549 void FmGridControl::ColumnResized(sal_uInt16 nId
)
1551 DbGridControl::ColumnResized(nId
);
1553 // Wert ans model uebergeben
1554 DbGridColumn
* pCol
= DbGridControl::GetColumns().GetObject(GetModelColumnPos(nId
));
1555 Reference
< ::com::sun::star::beans::XPropertySet
> xColModel(pCol
->getModel());
1559 sal_Int32 nColumnWidth
= GetColumnWidth(nId
);
1560 nColumnWidth
= CalcReverseZoom(nColumnWidth
);
1561 // Umrechnen in 10THMM
1562 aWidth
<<= (sal_Int32
)PixelToLogic(Point(nColumnWidth
,0),MAP_10TH_MM
).X();
1563 xColModel
->setPropertyValue(FM_PROP_WIDTH
, aWidth
);
1567 //------------------------------------------------------------------------------
1568 void FmGridControl::CellModified()
1570 DbGridControl::CellModified();
1571 GetPeer()->CellModified();
1574 //------------------------------------------------------------------------------
1575 void FmGridControl::BeginCursorAction()
1577 DbGridControl::BeginCursorAction();
1578 m_pPeer
->stopCursorListening();
1581 //------------------------------------------------------------------------------
1582 void FmGridControl::EndCursorAction()
1584 m_pPeer
->startCursorListening();
1585 DbGridControl::EndCursorAction();
1588 //------------------------------------------------------------------------------
1589 void FmGridControl::ColumnMoved(sal_uInt16 nId
)
1591 m_bInColumnMove
= sal_True
;
1593 DbGridControl::ColumnMoved(nId
);
1594 Reference
< ::com::sun::star::container::XIndexContainer
> xColumns(GetPeer()->getColumns());
1598 // suchen der Spalte und verschieben im Model
1600 DbGridColumn
* pCol
= DbGridControl::GetColumns().GetObject(GetModelColumnPos(nId
));
1601 Reference
< ::com::sun::star::beans::XPropertySet
> xCol
;
1603 // Einfuegen muß sich an den Column Positionen orientieren
1605 Reference
< XInterface
> xCurrent
;
1606 for (i
= 0; !xCol
.is() && i
< xColumns
->getCount(); i
++)
1608 ::cppu::extractInterface(xCurrent
, xColumns
->getByIndex(i
));
1609 if (xCurrent
== pCol
->getModel())
1611 xCol
= pCol
->getModel();
1616 DBG_ASSERT(i
< xColumns
->getCount(), "Falscher ::com::sun::star::sdbcx::Index");
1617 xColumns
->removeByIndex(i
);
1620 xColumns
->insertByIndex(GetModelColumnPos(nId
), aElement
);
1621 pCol
->setModel(xCol
);
1622 // if the column which is shown here is selected ...
1623 if ( isColumnSelected(nId
,pCol
) )
1624 markColumn(nId
); // ... -> mark it
1627 m_bInColumnMove
= sal_False
;
1630 //------------------------------------------------------------------------------
1631 void FmGridControl::InitColumnsByModels(const Reference
< ::com::sun::star::container::XIndexContainer
>& xColumns
)
1633 // Spalten wieder neu setzen
1634 // wenn es nur eine HandleColumn gibt, dann nicht
1635 if (GetModelColCount())
1638 InsertHandleColumn();
1644 SetUpdateMode(sal_False
);
1646 // Einfuegen mu� sich an den Column Positionen orientieren
1650 for (i
= 0; i
< xColumns
->getCount(); ++i
)
1652 Reference
< ::com::sun::star::beans::XPropertySet
> xCol
;
1653 ::cppu::extractInterface(xCol
, xColumns
->getByIndex(i
));
1655 aName
= (const sal_Unicode
*)::comphelper::getString(xCol
->getPropertyValue(FM_PROP_LABEL
));
1657 aWidth
= xCol
->getPropertyValue(FM_PROP_WIDTH
);
1658 sal_Int32 nWidth
= 0;
1659 if (aWidth
>>= nWidth
)
1660 nWidth
= LogicToPixel(Point(nWidth
,0),MAP_10TH_MM
).X();
1662 AppendColumn(aName
, (sal_uInt16
)nWidth
);
1663 DbGridColumn
* pCol
= DbGridControl::GetColumns().GetObject(i
);
1664 pCol
->setModel(xCol
);
1667 // und jetzt noch die hidden columns rausnehmen
1668 // (wir haben das nicht gleich in der oberen Schleife gemacht, da wir dann Probleme mit den
1669 // IDs der Spalten bekommen haetten : AppendColumn vergibt die automatisch, die Spalte _nach_
1670 // einer versteckten braucht aber eine um eine erhoehte ID ....
1672 for (i
= 0; i
< xColumns
->getCount(); ++i
)
1674 Reference
< ::com::sun::star::beans::XPropertySet
> xCol
;
1675 ::cppu::extractInterface(xCol
, xColumns
->getByIndex(i
));
1676 aHidden
= xCol
->getPropertyValue(FM_PROP_HIDDEN
);
1677 if (::comphelper::getBOOL(aHidden
))
1678 HideColumn(GetColumnIdFromModelPos((sal_uInt16
)i
));
1681 SetUpdateMode(sal_True
);
1684 //------------------------------------------------------------------------------
1685 void FmGridControl::InitColumnByField(
1686 DbGridColumn
* _pColumn
, const Reference
< XPropertySet
>& _rxColumnModel
,
1687 const Reference
< XNameAccess
>& _rxFieldsByNames
, const Reference
< XIndexAccess
>& _rxFieldsByIndex
)
1689 DBG_ASSERT( _rxFieldsByNames
== _rxFieldsByIndex
, "FmGridControl::InitColumnByField: invalid container interfaces!" );
1691 // lookup the column which belongs to the control source
1692 ::rtl::OUString sFieldName
;
1693 _rxColumnModel
->getPropertyValue( FM_PROP_CONTROLSOURCE
) >>= sFieldName
;
1694 Reference
< XPropertySet
> xField
;
1695 _rxColumnModel
->getPropertyValue( FM_PROP_BOUNDFIELD
) >>= xField
;
1698 if ( !xField
.is() && /*sFieldName.getLength() && */_rxFieldsByNames
->hasByName( sFieldName
) ) // #i93452# do not check for name length
1699 _rxFieldsByNames
->getByName( sFieldName
) >>= xField
;
1701 // determine the position of this column
1702 sal_Int32 nFieldPos
= -1;
1705 Reference
< XPropertySet
> xCheck
;
1706 sal_Int32 nFieldCount
= _rxFieldsByIndex
->getCount();
1707 for ( sal_Int32 i
= 0; i
< nFieldCount
; ++i
)
1709 _rxFieldsByIndex
->getByIndex( i
) >>= xCheck
;
1710 if ( xField
.get() == xCheck
.get() )
1718 if ( xField
.is() && ( nFieldPos
>= 0 ) )
1720 // some data types are not allowed
1721 sal_Int32 nDataType
= DataType::OTHER
;
1722 xField
->getPropertyValue( FM_PROP_FIELDTYPE
) >>= nDataType
;
1724 sal_Bool bIllegalType
= sal_False
;
1725 switch ( nDataType
)
1727 case DataType::LONGVARBINARY
:
1728 case DataType::BINARY
:
1729 case DataType::VARBINARY
:
1730 case DataType::OTHER
:
1731 bIllegalType
= sal_True
;
1737 _pColumn
->SetObject( (sal_Int16
)nFieldPos
);
1741 // handle readonly columns
1742 sal_Bool bReadOnly
= sal_True
;
1743 xField
->getPropertyValue( FM_PROP_ISREADONLY
) >>= bReadOnly
;
1744 _pColumn
->SetReadOnly( bReadOnly
);
1747 // the control type is determined by the ColumnServiceName
1748 static ::rtl::OUString
s_sPropColumnServiceName( RTL_CONSTASCII_USTRINGPARAM( "ColumnServiceName" ) );
1749 if ( !::comphelper::hasProperty( s_sPropColumnServiceName
, _rxColumnModel
) )
1752 _pColumn
->setModel( _rxColumnModel
);
1754 ::rtl::OUString sColumnServiceName
;
1755 _rxColumnModel
->getPropertyValue( s_sPropColumnServiceName
) >>= sColumnServiceName
;
1757 sal_Int32 nTypeId
= getColumnTypeByModelName( sColumnServiceName
);
1758 _pColumn
->CreateControl( nFieldPos
, xField
, nTypeId
);
1761 //------------------------------------------------------------------------------
1762 void FmGridControl::InitColumnsByFields(const Reference
< ::com::sun::star::container::XIndexAccess
>& _rxFields
)
1764 if ( !_rxFields
.is() )
1767 // Spalten initialisieren
1768 Reference
< XIndexContainer
> xColumns( GetPeer()->getColumns() );
1769 Reference
< XNameAccess
> xFieldsAsNames( _rxFields
, UNO_QUERY
);
1771 // Einfuegen mu� sich an den Column Positionen orientieren
1772 for (sal_Int32 i
= 0; i
< xColumns
->getCount(); i
++)
1774 DbGridColumn
* pCol
= GetColumns().GetObject(i
);
1775 Reference
< XPropertySet
> xColumnModel
;
1776 ::cppu::extractInterface( xColumnModel
, xColumns
->getByIndex( i
) );
1778 InitColumnByField( pCol
, xColumnModel
, xFieldsAsNames
, _rxFields
);
1782 //------------------------------------------------------------------------------
1783 void FmGridControl::HideColumn(sal_uInt16 nId
)
1785 DbGridControl::HideColumn(nId
);
1787 sal_uInt16 nPos
= GetModelColumnPos(nId
);
1788 if (nPos
== (sal_uInt16
)-1)
1791 DbGridColumn
* pColumn
= GetColumns().GetObject(nPos
);
1792 if (pColumn
->IsHidden())
1793 GetPeer()->columnHidden(pColumn
);
1795 if (nId
== m_nMarkedColumnId
)
1796 m_nMarkedColumnId
= (sal_uInt16
)-1;
1798 // -----------------------------------------------------------------------------
1799 sal_Bool
FmGridControl::isColumnSelected(sal_uInt16
/*nId*/,DbGridColumn
* _pColumn
)
1801 OSL_ENSURE(_pColumn
,"Column can not be null!");
1802 sal_Bool bSelected
= sal_False
;
1803 // if the column which is shown here is selected ...
1804 Reference
< ::com::sun::star::view::XSelectionSupplier
> xSelSupplier(GetPeer()->getColumns(), UNO_QUERY
);
1805 if ( xSelSupplier
.is() )
1807 Reference
< ::com::sun::star::beans::XPropertySet
> xColumn
;
1808 xSelSupplier
->getSelection() >>= xColumn
;
1809 bSelected
= (xColumn
.get() == _pColumn
->getModel().get());
1814 //------------------------------------------------------------------------------
1815 void FmGridControl::ShowColumn(sal_uInt16 nId
)
1817 DbGridControl::ShowColumn(nId
);
1819 sal_uInt16 nPos
= GetModelColumnPos(nId
);
1820 if (nPos
== (sal_uInt16
)-1)
1823 DbGridColumn
* pColumn
= GetColumns().GetObject(nPos
);
1824 if (!pColumn
->IsHidden())
1825 GetPeer()->columnVisible(pColumn
);
1827 // if the column which is shown here is selected ...
1828 if ( isColumnSelected(nId
,pColumn
) )
1829 markColumn(nId
); // ... -> mark it
1832 //------------------------------------------------------------------------------
1833 sal_Bool
FmGridControl::selectBookmarks(const Sequence
< Any
>& _rBookmarks
)
1835 vos::OGuard
aGuard( Application::GetSolarMutex() );
1836 // need to lock the SolarMutex so that no paint call disturbs us ...
1838 if ( !m_pSeekCursor
)
1840 DBG_ERROR( "FmGridControl::selectBookmarks: no seek cursor!" );
1844 const Any
* pBookmark
= _rBookmarks
.getConstArray();
1845 const Any
* pBookmarkEnd
= pBookmark
+ _rBookmarks
.getLength();
1849 sal_Bool bAllSuccessfull
= sal_True
;
1852 for (; pBookmark
!= pBookmarkEnd
; ++pBookmark
)
1854 // move the seek cursor to the row given
1855 if (m_pSeekCursor
->moveToBookmark(*pBookmark
))
1856 SelectRow( m_pSeekCursor
->getRow() - 1);
1858 bAllSuccessfull
= sal_False
;
1863 DBG_ERROR("FmGridControl::selectBookmarks: could not move to one of the bookmarks!");
1867 return bAllSuccessfull
;
1870 //------------------------------------------------------------------------------
1871 Sequence
< Any
> FmGridControl::getSelectionBookmarks()
1873 // lock our update so no paint-triggered seeks interfere ...
1874 SetUpdateMode(sal_False
);
1876 sal_Int32 nSelectedRows
= GetSelectRowCount(), i
= 0;
1877 Sequence
< Any
> aBookmarks(nSelectedRows
);
1878 if ( nSelectedRows
)
1880 Any
* pBookmarks
= (Any
*)aBookmarks
.getArray();
1882 // (I'm not sure if the problem isn't deeper : The szenario : a large table displayed by a grid with a
1883 // thread-safe cursor (dBase). On loading the sdb-cursor started a counting thread. While this counting progress
1884 // was running, I tried do delete 3 records from within the grid. Deletion caused a SeekCursor, which did a
1885 // m_pSeekCursor->moveRelative and a m_pSeekCursor->getPosition.
1886 // Unfortunally the first call caused a propertyChanged(RECORDCOUNT) which resulted in a repaint of the
1887 // navigation bar and the grid. The latter itself will result in SeekRow calls. So after (successfully) returning
1888 // from the moveRelative the getPosition returns an invalid value. And so the SeekCursor fails.
1889 // In the consequence ALL parts of code where two calls to the seek cursor are done, while the second call _relys_ on
1890 // the first one, should be secured against recursion, with a broad-minded interpretion of "recursion" : if any of these
1891 // code parts is executed, no other should be accessible. But this sounds very difficult to achieve ....
1894 // The next problem caused by the same behaviuor (SeekCursor causes a propertyChanged) : when adjusting rows we implicitly
1895 // change our selection. So a "FirstSelected(); SeekCursor(); NextSelected();" may produce unpredictable results.
1896 // That's why we _first_ collect the indicies of the selected rows and _then_ their bookmarks.
1897 long nIdx
= FirstSelectedRow();
1900 // (we misuse the bookmarks array for this ...)
1901 pBookmarks
[i
++] <<= (sal_Int32
)nIdx
;
1902 nIdx
= NextSelectedRow();
1904 DBG_ASSERT(i
== nSelectedRows
, "FmGridControl::DeleteSelectedRows : could not collect the row indicies !");
1906 for (i
=0; i
<nSelectedRows
; ++i
)
1908 nIdx
= ::comphelper::getINT32(pBookmarks
[i
]);
1909 if (IsInsertionRow(nIdx
))
1911 // leerzeile nicht loeschen
1912 aBookmarks
.realloc(--nSelectedRows
);
1913 SelectRow(nIdx
,sal_False
); // selection aufheben fuer leerzeile
1917 // Zunaechst den DatenCursor auf den selektierten Satz pos.
1918 if (SeekCursor(nIdx
))
1920 GetSeekRow()->SetState(m_pSeekCursor
, sal_True
);
1922 pBookmarks
[i
] = m_pSeekCursor
->getBookmark();
1926 DBG_ERROR("FmGridControl::DeleteSelectedRows : a bookmark could not be determined !");
1930 SetUpdateMode(sal_True
);
1932 // if one of the SeekCursor-calls failed ....
1933 aBookmarks
.realloc(i
);
1935 // (the alternative : while collecting the bookmarks lock our propertyChanged, this should resolve both our problems.
1936 // but this would be incompatible as we need a locking flag, then ...)
1940 // -----------------------------------------------------------------------------
1943 ::rtl::OUString
getColumnPropertyFromPeer(FmXGridPeer
* _pPeer
,sal_Int32 _nPosition
,const ::rtl::OUString
& _sPropName
)
1945 ::rtl::OUString sRetText
;
1946 if ( _pPeer
&& _nPosition
!= -1)
1948 Reference
<XIndexContainer
> xIndex
= _pPeer
->getColumns();
1949 if ( xIndex
.is() && xIndex
->getCount() > _nPosition
)
1951 Reference
<XPropertySet
> xProp
;
1952 xIndex
->getByIndex( _nPosition
) >>= xProp
;
1954 xProp
->getPropertyValue( _sPropName
) >>= sRetText
;
1960 // Object data and state ------------------------------------------------------
1961 ::rtl::OUString
FmGridControl::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eObjType
,sal_Int32 _nPosition
) const
1963 ::rtl::OUString sRetText
;
1966 case ::svt::BBTYPE_BROWSEBOX
:
1969 Reference
<XPropertySet
> xProp(GetPeer()->getColumns(),UNO_QUERY
);
1971 xProp
->getPropertyValue(FM_PROP_NAME
) >>= sRetText
;
1974 case ::svt::BBTYPE_COLUMNHEADERCELL
:
1975 sRetText
= getColumnPropertyFromPeer(
1978 sal::static_int_cast
< sal_uInt16
>(_nPosition
)),
1982 sRetText
= DbGridControl::GetAccessibleObjectName(_eObjType
,_nPosition
);
1986 // -----------------------------------------------------------------------------
1988 ::rtl::OUString
FmGridControl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eObjType
,sal_Int32 _nPosition
) const
1990 ::rtl::OUString sRetText
;
1993 case ::svt::BBTYPE_BROWSEBOX
:
1996 Reference
<XPropertySet
> xProp(GetPeer()->getColumns(),UNO_QUERY
);
1998 xProp
->getPropertyValue(FM_PROP_HELPTEXT
) >>= sRetText
;
2001 case ::svt::BBTYPE_COLUMNHEADERCELL
:
2002 sRetText
= getColumnPropertyFromPeer(
2005 sal::static_int_cast
< sal_uInt16
>(_nPosition
)),
2009 sRetText
= DbGridControl::GetAccessibleObjectDescription(_eObjType
,_nPosition
);
2013 // -----------------------------------------------------------------------------
2014 void FmGridControl::Select()
2016 DbGridControl::Select();
2017 // ... betrifft das unsere Spalten ?
2018 const MultiSelection
* pColumnSelection
= GetColumnSelection();
2020 sal_uInt16 nSelectedColumn
=
2021 pColumnSelection
&& pColumnSelection
->GetSelectCount()
2022 ? sal::static_int_cast
< sal_uInt16
>(
2023 ((MultiSelection
*)pColumnSelection
)->FirstSelected())
2025 // die HandleColumn wird nicht selektiert
2026 switch (nSelectedColumn
)
2028 case -1 : break; // no selection
2029 case 0 : nSelectedColumn
= SAL_MAX_UINT16
; break;
2030 // handle col can't be seledted
2032 // get the model col pos instead of the view col pos
2033 nSelectedColumn
= GetModelColumnPos(GetColumnIdFromViewPos(nSelectedColumn
- 1));
2037 if (nSelectedColumn
!= m_nCurrentSelectedColumn
)
2039 // VOR dem Aufruf des select am SelectionSupplier !
2040 m_nCurrentSelectedColumn
= nSelectedColumn
;
2044 m_bSelecting
= sal_True
;
2048 Reference
< XIndexAccess
> xColumns(GetPeer()->getColumns(), UNO_QUERY
);
2049 Reference
< XSelectionSupplier
> xSelSupplier(xColumns
, UNO_QUERY
);
2050 if (xSelSupplier
.is())
2052 if (nSelectedColumn
!= SAL_MAX_UINT16
)
2054 Reference
< XPropertySet
> xColumn
;
2055 ::cppu::extractInterface(xColumn
,xColumns
->getByIndex(nSelectedColumn
));
2056 xSelSupplier
->select(makeAny(xColumn
));
2060 xSelSupplier
->select(Any());
2069 m_bSelecting
= sal_False
;
2073 // -----------------------------------------------------------------------------
2074 sal_Int32
FmGridControl::GetSelectedColumn() const
2076 return m_nCurrentSelectedColumn
;
2078 // -----------------------------------------------------------------------------
2079 void FmGridControl::KeyInput( const KeyEvent
& rKEvt
)
2081 sal_Bool bDone
= sal_False
;
2082 const KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
2084 && !rKeyCode
.IsShift()
2085 && !rKeyCode
.IsMod1()
2086 && !rKeyCode
.IsMod2()
2089 switch ( rKeyCode
.GetCode() )
2092 GetParent()->GrabFocus();
2096 if ( GetSelectColumnCount() && GetPeer() && m_nCurrentSelectedColumn
>= 0 )
2098 Reference
< ::com::sun::star::container::XIndexContainer
> xCols(GetPeer()->getColumns());
2103 if ( m_nCurrentSelectedColumn
< xCols
->getCount() )
2105 Reference
< XInterface
> xCol
;
2106 xCols
->getByIndex(m_nCurrentSelectedColumn
) >>= xCol
;
2107 xCols
->removeByIndex(m_nCurrentSelectedColumn
);
2108 ::comphelper::disposeComponent(xCol
);
2111 catch(const Exception
&)
2113 OSL_ENSURE(0,"exception occured while deleting a column");
2122 DbGridControl::KeyInput( rKEvt
);
2124 // -----------------------------------------------------------------------------