1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include <svx/fmgridif.hxx>
26 #include <fmservs.hxx>
27 #include <svx/fmtools.hxx>
29 #include <formcontrolfactory.hxx>
30 #include <gridcell.hxx>
31 #include <sdbdatacolumn.hxx>
32 #include <svx/fmgridcl.hxx>
33 #include <tools/urlobj.hxx>
35 #include <com/sun/star/awt/PosSize.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/form/FormComponentType.hpp>
38 #include <com/sun/star/form/XFormComponent.hpp>
39 #include <com/sun/star/form/XLoadable.hpp>
40 #include <com/sun/star/form/XReset.hpp>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
43 #include <com/sun/star/lang/NoSupportException.hpp>
44 #include <com/sun/star/sdbc/ResultSetType.hpp>
45 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
46 #include <com/sun/star/util/URLTransformer.hpp>
47 #include <com/sun/star/util/XURLTransformer.hpp>
48 #include <com/sun/star/view/XSelectionSupplier.hpp>
49 #include <com/sun/star/sdbcx/XRowLocate.hpp>
51 #include <comphelper/enumhelper.hxx>
52 #include <comphelper/processfactory.hxx>
53 #include <comphelper/property.hxx>
54 #include <comphelper/sequence.hxx>
55 #include <comphelper/types.hxx>
56 #include <cppuhelper/supportsservice.hxx>
57 #include <cppuhelper/queryinterface.hxx>
58 #include <o3tl/safeint.hxx>
59 #include <vcl/unohelp.hxx>
60 #include <vcl/svapp.hxx>
61 #include <tools/debug.hxx>
62 #include <comphelper/diagnose_ex.hxx>
63 #include <sal/macros.h>
65 using namespace ::svxform
;
66 using namespace ::com::sun::star::container
;
67 using namespace ::com::sun::star::sdb
;
68 using namespace ::com::sun::star::sdbc
;
69 using namespace ::com::sun::star::uno
;
70 using namespace ::com::sun::star::view
;
71 using namespace ::com::sun::star::beans
;
72 using namespace ::com::sun::star::lang
;
73 using namespace ::com::sun::star::form
;
74 using namespace ::com::sun::star::util
;
75 using namespace ::com::sun::star
;
77 using ::com::sun::star::sdbcx::XColumnsSupplier
;
78 using ::com::sun::star::frame::XDispatchProviderInterceptor
;
79 using ::com::sun::star::frame::XDispatchProvider
;
80 using ::com::sun::star::accessibility::XAccessible
;
81 using ::com::sun::star::accessibility::XAccessibleContext
;
82 using ::com::sun::star::sdb::XRowSetSupplier
;
83 using ::com::sun::star::awt::XVclWindowPeer
;
86 static css::awt::FontDescriptor
ImplCreateFontDescriptor( const vcl::Font
& rFont
)
88 css::awt::FontDescriptor aFD
;
89 aFD
.Name
= rFont
.GetFamilyName();
90 aFD
.StyleName
= rFont
.GetStyleName();
91 aFD
.Height
= static_cast<sal_Int16
>(rFont
.GetFontSize().Height());
92 aFD
.Width
= static_cast<sal_Int16
>(rFont
.GetFontSize().Width());
93 aFD
.Family
= static_cast<sal_Int16
>(rFont
.GetFamilyType());
94 aFD
.CharSet
= rFont
.GetCharSet();
95 aFD
.Pitch
= static_cast<sal_Int16
>(rFont
.GetPitch());
96 aFD
.CharacterWidth
= vcl::unohelper::ConvertFontWidth( rFont
.GetWidthType() );
97 aFD
.Weight
= vcl::unohelper::ConvertFontWeight( rFont
.GetWeight() );
98 aFD
.Slant
= vcl::unohelper::ConvertFontSlant( rFont
.GetItalic() );
99 aFD
.Underline
= static_cast<sal_Int16
>(rFont
.GetUnderline());
100 aFD
.Strikeout
= static_cast<sal_Int16
>(rFont
.GetStrikeout());
101 aFD
.Orientation
= toDegrees(rFont
.GetOrientation());
102 aFD
.Kerning
= rFont
.IsKerning();
103 aFD
.WordLineMode
= rFont
.IsWordLineMode();
104 aFD
.Type
= 0; // ??? => only to metric...
109 static vcl::Font
ImplCreateFont( const css::awt::FontDescriptor
& rDescr
)
112 aFont
.SetFamilyName( rDescr
.Name
);
113 aFont
.SetStyleName( rDescr
.StyleName
);
114 aFont
.SetFontSize( ::Size( rDescr
.Width
, rDescr
.Height
) );
115 aFont
.SetFamily( static_cast<FontFamily
>(rDescr
.Family
) );
116 aFont
.SetCharSet( static_cast<rtl_TextEncoding
>(rDescr
.CharSet
) );
117 aFont
.SetPitch( static_cast<FontPitch
>(rDescr
.Pitch
) );
118 aFont
.SetWidthType( vcl::unohelper::ConvertFontWidth( rDescr
.CharacterWidth
) );
119 aFont
.SetWeight( vcl::unohelper::ConvertFontWeight( rDescr
.Weight
) );
120 aFont
.SetItalic( static_cast<FontItalic
>(rDescr
.Slant
) );
121 aFont
.SetUnderline( static_cast<::FontLineStyle
>(rDescr
.Underline
) );
122 aFont
.SetStrikeout( static_cast<::FontStrikeout
>(rDescr
.Strikeout
) );
123 aFont
.SetOrientation( Degree10(static_cast<sal_Int16
>(rDescr
.Orientation
* 10)) );
124 aFont
.SetKerning( static_cast<FontKerning
>(rDescr
.Kerning
) );
125 aFont
.SetWordLineMode( rDescr
.WordLineMode
);
129 FmXModifyMultiplexer::FmXModifyMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
130 :OWeakSubObject( rSource
)
131 ,OInterfaceContainerHelper3( _rMutex
)
136 Any SAL_CALL
FmXModifyMultiplexer::queryInterface(const Type
& _rType
)
138 Any aReturn
= ::cppu::queryInterface(_rType
,
139 static_cast< css::util::XModifyListener
*>(this),
140 static_cast< XEventListener
*>(this)
143 if (!aReturn
.hasValue())
144 aReturn
= OWeakSubObject::queryInterface( _rType
);
150 void FmXModifyMultiplexer::disposing(const EventObject
& )
155 void FmXModifyMultiplexer::modified(const EventObject
& e
)
157 EventObject
aMulti( e
);
158 aMulti
.Source
= &m_rParent
;
159 notifyEach( &XModifyListener::modified
, aMulti
);
162 FmXUpdateMultiplexer::FmXUpdateMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
163 :OWeakSubObject( rSource
)
164 ,OInterfaceContainerHelper3( _rMutex
)
169 Any SAL_CALL
FmXUpdateMultiplexer::queryInterface(const Type
& _rType
)
171 Any aReturn
= ::cppu::queryInterface(_rType
,
172 static_cast< XUpdateListener
*>(this),
173 static_cast< XEventListener
*>(this)
176 if (!aReturn
.hasValue())
177 aReturn
= OWeakSubObject::queryInterface( _rType
);
183 void FmXUpdateMultiplexer::disposing(const EventObject
& )
188 sal_Bool
FmXUpdateMultiplexer::approveUpdate(const EventObject
&e
)
190 EventObject
aMulti( e
);
191 aMulti
.Source
= &m_rParent
;
196 ::comphelper::OInterfaceIteratorHelper3
aIter(*this);
197 while ( bResult
&& aIter
.hasMoreElements() )
198 bResult
= aIter
.next()->approveUpdate( aMulti
);
205 void FmXUpdateMultiplexer::updated(const EventObject
&e
)
207 EventObject
aMulti( e
);
208 aMulti
.Source
= &m_rParent
;
209 notifyEach( &XUpdateListener::updated
, aMulti
);
212 FmXSelectionMultiplexer::FmXSelectionMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
213 :OWeakSubObject( rSource
)
214 ,OInterfaceContainerHelper3( _rMutex
)
219 Any SAL_CALL
FmXSelectionMultiplexer::queryInterface(const Type
& _rType
)
221 Any aReturn
= ::cppu::queryInterface(_rType
,
222 static_cast< XSelectionChangeListener
*>(this),
223 static_cast< XEventListener
*>(this)
226 if (!aReturn
.hasValue())
227 aReturn
= OWeakSubObject::queryInterface( _rType
);
233 void FmXSelectionMultiplexer::disposing(const EventObject
& )
238 void SAL_CALL
FmXSelectionMultiplexer::selectionChanged( const EventObject
& _rEvent
)
240 EventObject
aMulti(_rEvent
);
241 aMulti
.Source
= &m_rParent
;
242 notifyEach( &XSelectionChangeListener::selectionChanged
, aMulti
);
245 FmXContainerMultiplexer::FmXContainerMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
246 :OWeakSubObject( rSource
)
247 ,OInterfaceContainerHelper3( _rMutex
)
252 Any SAL_CALL
FmXContainerMultiplexer::queryInterface(const Type
& _rType
)
254 Any aReturn
= ::cppu::queryInterface(_rType
,
255 static_cast< XContainerListener
*>(this),
256 static_cast< XEventListener
*>(this)
259 if (!aReturn
.hasValue())
260 aReturn
= OWeakSubObject::queryInterface( _rType
);
266 void FmXContainerMultiplexer::disposing(const EventObject
& )
270 void FmXContainerMultiplexer::elementInserted(const ContainerEvent
& e
)
272 ContainerEvent
aMulti( e
);
273 aMulti
.Source
= &m_rParent
;
274 notifyEach( &XContainerListener::elementInserted
, aMulti
);
278 void FmXContainerMultiplexer::elementRemoved(const ContainerEvent
& e
)
280 ContainerEvent
aMulti( e
);
281 aMulti
.Source
= &m_rParent
;
282 notifyEach( &XContainerListener::elementRemoved
, aMulti
);
286 void FmXContainerMultiplexer::elementReplaced(const ContainerEvent
& e
)
288 ContainerEvent
aMulti( e
);
289 aMulti
.Source
= &m_rParent
;
290 notifyEach( &XContainerListener::elementReplaced
, aMulti
);
293 FmXGridControlMultiplexer::FmXGridControlMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
294 :OWeakSubObject( rSource
)
295 ,OInterfaceContainerHelper3( _rMutex
)
300 Any SAL_CALL
FmXGridControlMultiplexer::queryInterface(const Type
& _rType
)
302 Any aReturn
= ::cppu::queryInterface( _rType
,
303 static_cast< XGridControlListener
*>(this)
306 if (!aReturn
.hasValue())
307 aReturn
= OWeakSubObject::queryInterface( _rType
);
313 void FmXGridControlMultiplexer::disposing( const EventObject
& )
318 void SAL_CALL
FmXGridControlMultiplexer::columnChanged( const EventObject
& _event
)
320 EventObject
aForwardedEvent( _event
);
321 aForwardedEvent
.Source
= &m_rParent
;
322 notifyEach( &XGridControlListener::columnChanged
, aForwardedEvent
);
329 Reference
< XInterface
> FmXGridControl_NewInstance_Impl(const Reference
< XMultiServiceFactory
>& _rxFactory
)
331 return *(new FmXGridControl( comphelper::getComponentContext(_rxFactory
) ));
334 FmXGridControl::FmXGridControl(const Reference
< XComponentContext
>& _rxContext
)
335 :m_aModifyListeners(*this, GetMutex())
336 ,m_aUpdateListeners(*this, GetMutex())
337 ,m_aContainerListeners(*this, GetMutex())
338 ,m_aSelectionListeners(*this, GetMutex())
339 ,m_aGridControlListeners(*this, GetMutex())
341 ,m_xContext(_rxContext
)
346 FmXGridControl::~FmXGridControl()
351 Any SAL_CALL
FmXGridControl::queryAggregation(const Type
& _rType
)
353 Any aReturn
= FmXGridControl_BASE::queryInterface(_rType
);
355 if (!aReturn
.hasValue())
356 aReturn
= UnoControl::queryAggregation( _rType
);
361 Sequence
< Type
> SAL_CALL
FmXGridControl::getTypes( )
363 return comphelper::concatSequences(UnoControl::getTypes(),FmXGridControl_BASE::getTypes());
367 Sequence
<sal_Int8
> SAL_CALL
FmXGridControl::getImplementationId( )
369 return css::uno::Sequence
<sal_Int8
>();
373 sal_Bool SAL_CALL
FmXGridControl::supportsService(const OUString
& ServiceName
)
375 return cppu::supportsService(this, ServiceName
);
378 OUString SAL_CALL
FmXGridControl::getImplementationName()
380 return u
"com.sun.star.form.FmXGridControl"_ustr
;
383 css::uno::Sequence
<OUString
> SAL_CALL
FmXGridControl::getSupportedServiceNames()
385 return { FM_SUN_CONTROL_GRIDCONTROL
, u
"com.sun.star.awt.UnoControl"_ustr
};
389 void SAL_CALL
FmXGridControl::dispose()
391 SolarMutexGuard aGuard
;
394 aEvt
.Source
= getXWeak();
395 m_aModifyListeners
.disposeAndClear(aEvt
);
396 m_aUpdateListeners
.disposeAndClear(aEvt
);
397 m_aContainerListeners
.disposeAndClear(aEvt
);
399 UnoControl::dispose();
403 OUString
FmXGridControl::GetComponentServiceName() const
405 return u
"DBGrid"_ustr
;
409 sal_Bool SAL_CALL
FmXGridControl::setModel(const Reference
< css::awt::XControlModel
>& rModel
)
411 SolarMutexGuard aGuard
;
413 if (!UnoControl::setModel(rModel
))
416 Reference
< XGridPeer
> xGridPeer(getPeer(), UNO_QUERY
);
419 Reference
< XIndexContainer
> xCols(mxModel
, UNO_QUERY
);
420 xGridPeer
->setColumns(xCols
);
426 rtl::Reference
<FmXGridPeer
> FmXGridControl::imp_CreatePeer(vcl::Window
* pParent
)
428 rtl::Reference
<FmXGridPeer
> pReturn
= new FmXGridPeer(m_xContext
);
430 // translate properties into WinBits
431 WinBits nStyle
= WB_TABSTOP
;
432 Reference
< XPropertySet
> xModelSet(getModel(), UNO_QUERY
);
437 if (::comphelper::getINT16(xModelSet
->getPropertyValue(FM_PROP_BORDER
)))
440 catch(const Exception
&)
442 OSL_FAIL("Can not get style");
446 pReturn
->Create(pParent
, nStyle
);
451 void SAL_CALL
FmXGridControl::createPeer(const Reference
< css::awt::XToolkit
>& /*rToolkit*/, const Reference
< css::awt::XWindowPeer
>& rParentPeer
)
454 throw DisposedException( OUString(), *this );
456 DBG_ASSERT(/*(0 == m_nPeerCreationLevel) && */!mbCreatingPeer
, "FmXGridControl::createPeer : recursion!");
457 // I think this should never assert, now that we're using the base class' mbCreatingPeer in addition to
458 // our own m_nPeerCreationLevel
459 // But I'm not sure as I don't _fully_ understand the underlying toolkit implementations...
460 // (if this asserts, we still need m_nPeerCreationLevel. If not, we could omit it...)
461 // 14.05.2001 - 86836 - frank.schoenheit@germany.sun.com
463 // TODO: why the hell this whole class does not use any mutex?
468 mbCreatingPeer
= true;
469 // mbCreatingPeer is virtually the same as m_nPeerCreationLevel, but it's the base class' method
470 // to prevent recursion.
472 vcl::Window
* pParentWin
= nullptr;
473 if (rParentPeer
.is())
475 VCLXWindow
* pParent
= dynamic_cast<VCLXWindow
*>(rParentPeer
.get());
477 pParentWin
= pParent
->GetWindow();
480 rtl::Reference
<FmXGridPeer
> pPeer
= imp_CreatePeer(pParentWin
);
481 DBG_ASSERT(pPeer
!= nullptr, "FmXGridControl::createPeer : imp_CreatePeer didn't return a peer !");
484 // reading the properties from the model
485 // ++m_nPeerCreationLevel;
488 // consider the following ugly scenario: updateFromModel leads to a propertiesChanges on the Control,
489 // which determines, dat a "critical" property has changed (e.g. "Border") and therefore starts a new
490 // Peer, which lands again here in createPeer we also start a second FmXGridPeer and initialise it.
491 // Then we exit from the first incarnation's updateFromModel and continue working with the pPeer,
492 // that is in fact now already obsolete (as another peer is being started in the second incarnation).
493 // Therefore the effort with the PeerCreationLevel, which ensures that we really use the Peer
494 // created at the deepest level, but first initialise it in the top-level.
495 // if (--m_nPeerCreationLevel == 0)
497 DBG_ASSERT(getPeer().is(), "FmXGridControl::createPeer : something went wrong ... no top level peer !");
498 pPeer
= dynamic_cast<FmXGridPeer
*>(getPeer().get());
500 setPosSize( maComponentInfos
.nX
, maComponentInfos
.nY
, maComponentInfos
.nWidth
, maComponentInfos
.nHeight
, css::awt::PosSize::POSSIZE
);
502 Reference
< XIndexContainer
> xColumns(getModel(), UNO_QUERY
);
504 pPeer
->setColumns(xColumns
);
506 if (maComponentInfos
.bVisible
)
507 pPeer
->setVisible(true);
509 if (!maComponentInfos
.bEnable
)
510 pPeer
->setEnable(false);
512 if (maWindowListeners
.getLength())
513 pPeer
->addWindowListener( &maWindowListeners
);
515 if (maFocusListeners
.getLength())
516 pPeer
->addFocusListener( &maFocusListeners
);
518 if (maKeyListeners
.getLength())
519 pPeer
->addKeyListener( &maKeyListeners
);
521 if (maMouseListeners
.getLength())
522 pPeer
->addMouseListener( &maMouseListeners
);
524 if (maMouseMotionListeners
.getLength())
525 pPeer
->addMouseMotionListener( &maMouseMotionListeners
);
527 if (maPaintListeners
.getLength())
528 pPeer
->addPaintListener( &maPaintListeners
);
530 if (m_aModifyListeners
.getLength())
531 pPeer
->addModifyListener( &m_aModifyListeners
);
533 if (m_aUpdateListeners
.getLength())
534 pPeer
->addUpdateListener( &m_aUpdateListeners
);
536 if (m_aContainerListeners
.getLength())
537 pPeer
->addContainerListener( &m_aContainerListeners
);
539 // forward the design mode
540 bool bForceAlivePeer
= m_bInDraw
&& !maComponentInfos
.bVisible
;
541 // (we force an alive-mode peer if we're in "draw", cause in this case the peer will be used for drawing in
542 // foreign devices. We ensure this with the visibility check as a living peer is assumed to be noncritical
543 // only if invisible)
544 Any aOldCursorBookmark
;
545 if (!mbDesignMode
|| bForceAlivePeer
)
547 Reference
< XFormComponent
> xComp(getModel(), UNO_QUERY
);
550 Reference
< XRowSet
> xForm(xComp
->getParent(), UNO_QUERY
);
551 // is the form alive?
552 // we can see that if the form contains columns
553 Reference
< css::sdbcx::XColumnsSupplier
> xColumnsSupplier(xForm
, UNO_QUERY
);
554 if (xColumnsSupplier
.is())
556 if (Reference
< XIndexAccess
> (xColumnsSupplier
->getColumns(),UNO_QUERY_THROW
)->getCount())
558 // we get only a new bookmark if the resultset is not forwardonly
559 if (::comphelper::getINT32(Reference
< XPropertySet
> (xForm
, UNO_QUERY_THROW
)->getPropertyValue(FM_PROP_RESULTSET_TYPE
)) != ResultSetType::FORWARD_ONLY
)
561 // as the FmGridControl touches the data source it is connected to we have to remember the current
562 // cursor position (and restore afterwards)
563 // OJ: but only when we stand on a valid row
564 if ( !xForm
->isBeforeFirst() && !xForm
->isAfterLast() )
568 aOldCursorBookmark
= Reference
< css::sdbcx::XRowLocate
> (xForm
, UNO_QUERY_THROW
)->getBookmark();
570 catch( const Exception
& )
572 DBG_UNHANDLED_EXCEPTION("svx");
578 pPeer
->setRowSet(xForm
);
581 pPeer
->setDesignMode(mbDesignMode
&& !bForceAlivePeer
);
585 if (aOldCursorBookmark
.hasValue())
586 { // we have a valid bookmark, so we have to restore the cursor's position
587 Reference
< XFormComponent
> xComp(getModel(), UNO_QUERY
);
588 Reference
< css::sdbcx::XRowLocate
> xLocate(xComp
->getParent(), UNO_QUERY
);
589 xLocate
->moveToBookmark(aOldCursorBookmark
);
592 catch( const Exception
& )
594 DBG_UNHANDLED_EXCEPTION("svx");
597 Reference
< css::awt::XView
> xPeerView(getPeer(), UNO_QUERY
);
598 xPeerView
->setZoom( maComponentInfos
.nZoomX
, maComponentInfos
.nZoomY
);
599 xPeerView
->setGraphics( mxGraphics
);
601 mbCreatingPeer
= false;
605 void FmXGridControl::addModifyListener(const Reference
< css::util::XModifyListener
>& l
)
607 m_aModifyListeners
.addInterface( l
);
608 if( getPeer().is() && m_aModifyListeners
.getLength() == 1 )
610 Reference
< css::util::XModifyBroadcaster
> xGrid(getPeer(), UNO_QUERY
);
611 xGrid
->addModifyListener( &m_aModifyListeners
);
616 sal_Bool SAL_CALL
FmXGridControl::select( const Any
& _rSelection
)
618 SolarMutexGuard aGuard
;
619 Reference
< XSelectionSupplier
> xPeer(getPeer(), UNO_QUERY
);
620 return xPeer
->select(_rSelection
);
624 Any SAL_CALL
FmXGridControl::getSelection( )
626 SolarMutexGuard aGuard
;
627 Reference
< XSelectionSupplier
> xPeer(getPeer(), UNO_QUERY
);
628 return xPeer
->getSelection();
632 void SAL_CALL
FmXGridControl::addSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
)
634 m_aSelectionListeners
.addInterface( _rxListener
);
635 if( getPeer().is() && 1 == m_aSelectionListeners
.getLength() )
637 Reference
< XSelectionSupplier
> xGrid(getPeer(), UNO_QUERY
);
638 xGrid
->addSelectionChangeListener( &m_aSelectionListeners
);
643 void SAL_CALL
FmXGridControl::removeSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
)
645 if( getPeer().is() && 1 == m_aSelectionListeners
.getLength() )
647 Reference
< XSelectionSupplier
> xGrid(getPeer(), UNO_QUERY
);
648 xGrid
->removeSelectionChangeListener( &m_aSelectionListeners
);
650 m_aSelectionListeners
.removeInterface( _rxListener
);
654 Sequence
< sal_Bool
> SAL_CALL
FmXGridControl::queryFieldDataType( const Type
& xType
)
658 Reference
< XGridFieldDataSupplier
> xPeerSupplier(getPeer(), UNO_QUERY
);
659 if (xPeerSupplier
.is())
660 return xPeerSupplier
->queryFieldDataType(xType
);
663 return Sequence
<sal_Bool
>();
667 Sequence
< Any
> SAL_CALL
FmXGridControl::queryFieldData( sal_Int32 nRow
, const Type
& xType
)
671 Reference
< XGridFieldDataSupplier
> xPeerSupplier(getPeer(), UNO_QUERY
);
672 if (xPeerSupplier
.is())
673 return xPeerSupplier
->queryFieldData(nRow
, xType
);
676 return Sequence
< Any
>();
680 void SAL_CALL
FmXGridControl::removeModifyListener(const Reference
< css::util::XModifyListener
>& l
)
682 if( getPeer().is() && m_aModifyListeners
.getLength() == 1 )
684 Reference
< css::util::XModifyBroadcaster
> xGrid(getPeer(), UNO_QUERY
);
685 xGrid
->removeModifyListener( &m_aModifyListeners
);
687 m_aModifyListeners
.removeInterface( l
);
691 void SAL_CALL
FmXGridControl::draw( sal_Int32 x
, sal_Int32 y
)
693 SolarMutexGuard aGuard
;
695 UnoControl::draw(x
, y
);
700 void SAL_CALL
FmXGridControl::setDesignMode(sal_Bool bOn
)
702 css::util::ModeChangeEvent aModeChangeEvent
;
704 // --- <mutex_lock> ---
706 SolarMutexGuard aGuard
;
708 Reference
< XRowSetSupplier
> xGrid(getPeer(), UNO_QUERY
);
710 if (xGrid
.is() && (bool(bOn
) != mbDesignMode
|| (!bOn
&& !xGrid
->getRowSet().is())))
714 xGrid
->setRowSet(Reference
< XRowSet
> ());
718 Reference
< XFormComponent
> xComp(getModel(), UNO_QUERY
);
721 Reference
< XRowSet
> xForm(xComp
->getParent(), UNO_QUERY
);
722 xGrid
->setRowSet(xForm
);
726 // Avoid infinite recursion when calling XVclWindowPeer::setDesignMode below
729 Reference
< XVclWindowPeer
> xVclWindowPeer( getPeer(), UNO_QUERY
);
730 if (xVclWindowPeer
.is())
731 xVclWindowPeer
->setDesignMode(bOn
);
738 // dispose our current AccessibleContext, if we have one
739 // (changing the design mode implies having a new implementation for this context,
740 // so the old one must be declared DEFUNC)
741 DisposeAccessibleContext(
742 Reference
<XComponent
>(maAccessibleContext
, UNO_QUERY
));
743 maAccessibleContext
.clear();
745 // prepare firing an event
746 aModeChangeEvent
.Source
= *this;
747 aModeChangeEvent
.NewMode
= mbDesignMode
? std::u16string_view( u
"design" ) : std::u16string_view( u
"alive" );
750 // --- </mutex_lock> ---
751 maModeChangeListeners
.notifyEach( &XModeChangeListener::modeChanged
, aModeChangeEvent
);
756 void SAL_CALL
FmXGridControl::addUpdateListener(const Reference
< XUpdateListener
>& l
)
758 m_aUpdateListeners
.addInterface( l
);
759 if( getPeer().is() && m_aUpdateListeners
.getLength() == 1 )
761 Reference
< XBoundComponent
> xBound(getPeer(), UNO_QUERY
);
762 xBound
->addUpdateListener( &m_aUpdateListeners
);
767 void SAL_CALL
FmXGridControl::removeUpdateListener(const Reference
< XUpdateListener
>& l
)
769 if( getPeer().is() && m_aUpdateListeners
.getLength() == 1 )
771 Reference
< XBoundComponent
> xBound(getPeer(), UNO_QUERY
);
772 xBound
->removeUpdateListener( &m_aUpdateListeners
);
774 m_aUpdateListeners
.removeInterface( l
);
778 sal_Bool SAL_CALL
FmXGridControl::commit()
780 Reference
< XBoundComponent
> xBound(getPeer(), UNO_QUERY
);
782 return xBound
->commit();
789 void SAL_CALL
FmXGridControl::addContainerListener(const Reference
< XContainerListener
>& l
)
791 m_aContainerListeners
.addInterface( l
);
792 if( getPeer().is() && m_aContainerListeners
.getLength() == 1 )
794 Reference
< XContainer
> xContainer(getPeer(), UNO_QUERY
);
795 xContainer
->addContainerListener( &m_aContainerListeners
);
800 void SAL_CALL
FmXGridControl::removeContainerListener(const Reference
< XContainerListener
>& l
)
802 if( getPeer().is() && m_aContainerListeners
.getLength() == 1 )
804 Reference
< XContainer
> xContainer(getPeer(), UNO_QUERY
);
805 xContainer
->removeContainerListener( &m_aContainerListeners
);
807 m_aContainerListeners
.removeInterface( l
);
811 Reference
< css::frame::XDispatch
> SAL_CALL
FmXGridControl::queryDispatch(const css::util::URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
813 Reference
< css::frame::XDispatchProvider
> xPeerProvider(getPeer(), UNO_QUERY
);
814 if (xPeerProvider
.is())
815 return xPeerProvider
->queryDispatch(aURL
, aTargetFrameName
, nSearchFlags
);
817 return Reference
< css::frame::XDispatch
> ();
821 Sequence
< Reference
< css::frame::XDispatch
> > SAL_CALL
FmXGridControl::queryDispatches(const Sequence
< css::frame::DispatchDescriptor
>& aDescripts
)
823 Reference
< css::frame::XDispatchProvider
> xPeerProvider(getPeer(), UNO_QUERY
);
824 if (xPeerProvider
.is())
825 return xPeerProvider
->queryDispatches(aDescripts
);
827 return Sequence
< Reference
< css::frame::XDispatch
> >();
831 void SAL_CALL
FmXGridControl::registerDispatchProviderInterceptor(const Reference
< css::frame::XDispatchProviderInterceptor
>& _xInterceptor
)
833 Reference
< css::frame::XDispatchProviderInterception
> xPeerInterception(getPeer(), UNO_QUERY
);
834 if (xPeerInterception
.is())
835 xPeerInterception
->registerDispatchProviderInterceptor(_xInterceptor
);
839 void SAL_CALL
FmXGridControl::releaseDispatchProviderInterceptor(const Reference
< css::frame::XDispatchProviderInterceptor
>& _xInterceptor
)
841 Reference
< css::frame::XDispatchProviderInterception
> xPeerInterception(getPeer(), UNO_QUERY
);
842 if (xPeerInterception
.is())
843 xPeerInterception
->releaseDispatchProviderInterceptor(_xInterceptor
);
847 void SAL_CALL
FmXGridControl::addGridControlListener( const Reference
< XGridControlListener
>& _listener
)
849 ::osl::MutexGuard
aGuard( GetMutex() );
851 m_aGridControlListeners
.addInterface( _listener
);
852 if ( getPeer().is() && 1 == m_aGridControlListeners
.getLength() )
854 Reference
< XGridControl
> xPeerGrid( getPeer(), UNO_QUERY
);
855 if ( xPeerGrid
.is() )
856 xPeerGrid
->addGridControlListener( &m_aGridControlListeners
);
861 void SAL_CALL
FmXGridControl::removeGridControlListener( const Reference
< XGridControlListener
>& _listener
)
863 ::osl::MutexGuard
aGuard( GetMutex() );
865 if( getPeer().is() && 1 == m_aGridControlListeners
.getLength() )
867 Reference
< XGridControl
> xPeerGrid( getPeer(), UNO_QUERY
);
868 if ( xPeerGrid
.is() )
869 xPeerGrid
->removeGridControlListener( &m_aGridControlListeners
);
872 m_aGridControlListeners
.removeInterface( _listener
);
876 sal_Int16 SAL_CALL
FmXGridControl::getCurrentColumnPosition()
878 Reference
< XGridControl
> xGrid( getPeer(), UNO_QUERY
);
879 return xGrid
.is() ? xGrid
->getCurrentColumnPosition() : -1;
883 void SAL_CALL
FmXGridControl::setCurrentColumnPosition(sal_Int16 nPos
)
885 Reference
< XGridControl
> xGrid( getPeer(), UNO_QUERY
);
888 SolarMutexGuard aGuard
;
889 xGrid
->setCurrentColumnPosition( nPos
);
895 sal_Bool SAL_CALL
FmXGridControl::hasElements()
897 Reference
< XElementAccess
> xPeer(getPeer(), UNO_QUERY
);
898 return xPeer
.is() && xPeer
->hasElements();
902 Type SAL_CALL
FmXGridControl::getElementType( )
904 return cppu::UnoType
<css::awt::XTextComponent
>::get();
907 // XEnumerationAccess
909 Reference
< XEnumeration
> SAL_CALL
FmXGridControl::createEnumeration()
911 Reference
< XEnumerationAccess
> xPeer(getPeer(), UNO_QUERY
);
913 return xPeer
->createEnumeration();
915 return new ::comphelper::OEnumerationByIndex(this);
920 sal_Int32 SAL_CALL
FmXGridControl::getCount()
922 Reference
< XIndexAccess
> xPeer(getPeer(), UNO_QUERY
);
923 return xPeer
.is() ? xPeer
->getCount() : 0;
927 Any SAL_CALL
FmXGridControl::getByIndex(sal_Int32 _nIndex
)
929 Reference
< XIndexAccess
> xPeer(getPeer(), UNO_QUERY
);
931 throw IndexOutOfBoundsException();
933 return xPeer
->getByIndex(_nIndex
);
936 // css::util::XModeSelector
938 void SAL_CALL
FmXGridControl::setMode(const OUString
& Mode
)
940 Reference
< css::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
942 throw NoSupportException();
944 xPeer
->setMode(Mode
);
948 OUString SAL_CALL
FmXGridControl::getMode()
950 Reference
< css::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
951 return xPeer
.is() ? xPeer
->getMode() : OUString();
955 css::uno::Sequence
<OUString
> SAL_CALL
FmXGridControl::getSupportedModes()
957 Reference
< css::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
958 return xPeer
.is() ? xPeer
->getSupportedModes() : css::uno::Sequence
<OUString
>();
962 sal_Bool SAL_CALL
FmXGridControl::supportsMode(const OUString
& Mode
)
964 Reference
< css::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
965 return xPeer
.is() && xPeer
->supportsMode(Mode
);
968 void SAL_CALL
FmXGridControl::setFocus()
970 rtl::Reference
<FmXGridPeer
> pPeer
= dynamic_cast<FmXGridPeer
*>(getPeer().get());
973 VclPtr
<FmGridControl
> xGrid
= pPeer
->GetAs
<FmGridControl
>();
974 bool bAlreadyHasFocus
= xGrid
->HasChildPathFocus() || xGrid
->ControlHasFocus();
975 // if the focus is already in the control don't grab focus again which
976 // would grab focus away from any native widgets hosted in the control
977 if (bAlreadyHasFocus
)
980 UnoControl::setFocus();
983 // helper class which prevents that in the peer's header the FmGridListener must be known
984 class FmXGridPeer::GridListenerDelegator
: public FmGridListener
987 FmXGridPeer
* m_pPeer
;
990 explicit GridListenerDelegator( FmXGridPeer
* _pPeer
);
991 virtual ~GridListenerDelegator();
994 virtual void selectionChanged() override
;
995 virtual void columnChanged() override
;
999 FmXGridPeer::GridListenerDelegator::GridListenerDelegator(FmXGridPeer
* _pPeer
)
1002 DBG_ASSERT(m_pPeer
, "GridListenerDelegator::GridListenerDelegator");
1005 FmXGridPeer::GridListenerDelegator::~GridListenerDelegator()
1010 void FmXGridPeer::GridListenerDelegator::selectionChanged()
1012 m_pPeer
->selectionChanged();
1016 void FmXGridPeer::GridListenerDelegator::columnChanged()
1018 m_pPeer
->columnChanged();
1021 void FmXGridPeer::selectionChanged()
1023 std::unique_lock
g(m_aMutex
);
1024 EventObject aSource
;
1025 aSource
.Source
= getXWeak();
1026 m_aSelectionListeners
.notifyEach( g
, &XSelectionChangeListener::selectionChanged
, aSource
);
1030 void FmXGridPeer::columnChanged()
1032 std::unique_lock
g(m_aMutex
);
1033 EventObject
aEvent( *this );
1034 m_aGridControlListeners
.notifyEach( g
, &XGridControlListener::columnChanged
, aEvent
);
1038 FmXGridPeer::FmXGridPeer(const Reference
< XComponentContext
>& _rxContext
)
1039 :m_xContext(_rxContext
)
1040 ,m_aMode(u
"DataMode"_ustr
)
1041 ,m_nCursorListening(0)
1042 ,m_bInterceptingDispatch(false)
1044 // Create must be called after this constructor
1045 m_pGridListener
.reset( new GridListenerDelegator( this ) );
1049 VclPtr
<FmGridControl
> FmXGridPeer::imp_CreateControl(vcl::Window
* pParent
, WinBits nStyle
)
1051 return VclPtr
<FmGridControl
>::Create(m_xContext
, pParent
, this, nStyle
);
1055 void FmXGridPeer::Create(vcl::Window
* pParent
, WinBits nStyle
)
1057 VclPtr
<FmGridControl
> pWin
= imp_CreateControl(pParent
, nStyle
);
1058 DBG_ASSERT(pWin
!= nullptr, "FmXGridPeer::Create : imp_CreateControl didn't return a control !");
1060 pWin
->SetStateProvider(LINK(this, FmXGridPeer
, OnQueryGridSlotState
));
1061 pWin
->SetSlotExecutor(LINK(this, FmXGridPeer
, OnExecuteGridSlot
));
1063 // want to hear about row selections
1064 pWin
->setGridListener( m_pGridListener
.get() );
1066 // Init must always be called
1068 pWin
->SetComponentInterface(this);
1073 FmXGridPeer::~FmXGridPeer()
1075 setRowSet(Reference
< XRowSet
> ());
1076 setColumns(Reference
< XIndexContainer
> ());
1081 void FmXGridPeer::disposing(const EventObject
& e
)
1083 bool bKnownSender
= false;
1085 Reference
< XIndexContainer
> xCols( e
.Source
, UNO_QUERY
);
1088 setColumns(Reference
< XIndexContainer
> ());
1089 bKnownSender
= true;
1092 Reference
< XRowSet
> xCursor(e
.Source
, UNO_QUERY
);
1095 setRowSet( m_xCursor
);
1096 m_xCursor
= nullptr;
1097 bKnownSender
= true;
1101 if ( !bKnownSender
&& m_pDispatchers
)
1103 const Sequence
< URL
>& aSupportedURLs
= getSupportedURLs();
1104 const URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
1105 for ( sal_Int32 i
=0; i
< ( aSupportedURLs
.getLength() ) && !bKnownSender
; ++i
, ++pSupportedURLs
)
1107 if ( m_pDispatchers
[i
] == e
.Source
)
1109 m_pDispatchers
[i
]->removeStatusListener( static_cast< css::frame::XStatusListener
* >( this ), *pSupportedURLs
);
1110 m_pDispatchers
[i
] = nullptr;
1111 m_pStateCache
[i
] = false;
1112 bKnownSender
= true;
1117 if ( !bKnownSender
)
1118 VCLXWindow::disposing(e
);
1122 void FmXGridPeer::addModifyListener(const Reference
< css::util::XModifyListener
>& l
)
1124 std::unique_lock
g(m_aMutex
);
1125 m_aModifyListeners
.addInterface( g
, l
);
1129 void FmXGridPeer::removeModifyListener(const Reference
< css::util::XModifyListener
>& l
)
1131 std::unique_lock
g(m_aMutex
);
1132 m_aModifyListeners
.removeInterface( g
, l
);
1136 #define LAST_KNOWN_TYPE FormComponentType::PATTERNFIELD
1137 Sequence
< sal_Bool
> SAL_CALL
FmXGridPeer::queryFieldDataType( const Type
& xType
)
1139 // a 'conversion table'
1140 static const bool bCanConvert
[LAST_KNOWN_TYPE
][4] =
1142 { false, false, false, false }, // FormComponentType::CONTROL
1143 { false, false, false, false }, // FormComponentType::COMMANDBUTTON
1144 { false, false, false, false }, // FormComponentType::RADIOBUTTON
1145 { false, false, false, false }, // FormComponentType::IMAGEBUTTON
1146 { false, false, false, true }, // FormComponentType::CHECKBOX
1147 { false, false, false, false }, // FormComponentType::LISTBOX
1148 { false, false, false, false }, // FormComponentType::COMBOBOX
1149 { false, false, false, false }, // FormComponentType::GROUPBOX
1150 { true , false, false, false }, // FormComponentType::TEXTFIELD
1151 { false, false, false, false }, // FormComponentType::FIXEDTEXT
1152 { false, false, false, false }, // FormComponentType::GRIDCONTROL
1153 { false, false, false, false }, // FormComponentType::FILECONTROL
1154 { false, false, false, false }, // FormComponentType::HIDDENCONTROL
1155 { false, false, false, false }, // FormComponentType::IMAGECONTROL
1156 { true , true , true , false }, // FormComponentType::DATEFIELD
1157 { true , true , false, false }, // FormComponentType::TIMEFIELD
1158 { true , true , false, false }, // FormComponentType::NUMERICFIELD
1159 { true , true , false, false }, // FormComponentType::CURRENCYFIELD
1160 { true , false, false, false } // FormComponentType::PATTERNFIELD
1164 sal_Int16 nMapColumn
= -1;
1165 switch (xType
.getTypeClass())
1167 case TypeClass_STRING
: nMapColumn
= 0; break;
1168 case TypeClass_FLOAT
:
1169 case TypeClass_DOUBLE
: nMapColumn
= 1; break;
1170 case TypeClass_SHORT
:
1171 case TypeClass_LONG
:
1172 case TypeClass_UNSIGNED_LONG
:
1173 case TypeClass_UNSIGNED_SHORT
: nMapColumn
= 2; break;
1174 case TypeClass_BOOLEAN
: nMapColumn
= 3; break;
1179 Reference
< XIndexContainer
> xColumns
= getColumns();
1181 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1182 sal_Int32 nColumns
= pGrid
->GetViewColCount();
1184 std::vector
< std::unique_ptr
<DbGridColumn
> > const & aColumns
= pGrid
->GetColumns();
1186 Sequence
<sal_Bool
> aReturnSequence(nColumns
);
1187 sal_Bool
* pReturnArray
= aReturnSequence
.getArray();
1189 bool bRequestedAsAny
= (xType
.getTypeClass() == TypeClass_ANY
);
1192 for (sal_Int32 i
=0; i
<nColumns
; ++i
)
1194 if (bRequestedAsAny
)
1196 pReturnArray
[i
] = true;
1200 pReturnArray
[i
] = false;
1202 sal_uInt16 nModelPos
= pGrid
->GetModelColumnPos(pGrid
->GetColumnIdFromViewPos(static_cast<sal_uInt16
>(i
)));
1203 DBG_ASSERT(nModelPos
!= sal_uInt16(-1), "FmXGridPeer::queryFieldDataType : no model pos !");
1205 pCol
= aColumns
[ nModelPos
].get();
1206 const DbGridRowRef xRow
= pGrid
->GetSeekRow();
1207 Reference
<css::sdb::XColumn
> xFieldContent
=
1208 (xRow
.is() && xRow
->HasField(pCol
->GetFieldPos())) ? xRow
->GetField(pCol
->GetFieldPos()).getColumn() : Reference
< css::sdb::XColumn
> ();
1209 if (!xFieldContent
.is())
1210 // can't supply anything without a field content
1211 // FS - 07.12.99 - 54391
1214 Reference
<XPropertySet
> xCurrentColumn
;
1215 xColumns
->getByIndex(nModelPos
) >>= xCurrentColumn
;
1216 if (!::comphelper::hasProperty(FM_PROP_CLASSID
, xCurrentColumn
))
1219 sal_Int16 nClassId
= sal_Int16();
1220 xCurrentColumn
->getPropertyValue(FM_PROP_CLASSID
) >>= nClassId
;
1221 if (nClassId
>LAST_KNOWN_TYPE
)
1223 DBG_ASSERT(nClassId
>0, "FmXGridPeer::queryFieldDataType : somebody changed the definition of the FormComponentType enum !");
1225 if (nMapColumn
!= -1)
1226 pReturnArray
[i
] = bCanConvert
[nClassId
-1][nMapColumn
];
1229 return aReturnSequence
;
1233 Sequence
< Any
> SAL_CALL
FmXGridPeer::queryFieldData( sal_Int32 nRow
, const Type
& xType
)
1235 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1236 DBG_ASSERT(pGrid
&& pGrid
->IsOpen(), "FmXGridPeer::queryFieldData : have no valid grid window !");
1237 if (!pGrid
|| !pGrid
->IsOpen())
1238 return Sequence
< Any
>();
1240 // move the control to the specified row
1241 if (!pGrid
->SeekRow(nRow
))
1243 throw IllegalArgumentException();
1246 // don't use GetCurrentRow as this isn't affected by the above SeekRow
1247 // FS - 30.09.99 - 68644
1248 DbGridRowRef xPaintRow
= pGrid
->GetPaintRow();
1249 ENSURE_OR_THROW( xPaintRow
.is(), "invalid paint row" );
1251 // I need the columns of the control for GetFieldText
1252 std::vector
< std::unique_ptr
<DbGridColumn
> > const & aColumns
= pGrid
->GetColumns();
1254 // and through all the columns
1255 sal_Int32 nColumnCount
= pGrid
->GetViewColCount();
1257 Sequence
< Any
> aReturnSequence(nColumnCount
);
1258 Any
* pReturnArray
= aReturnSequence
.getArray();
1260 bool bRequestedAsAny
= (xType
.getTypeClass() == TypeClass_ANY
);
1261 for (sal_Int32 i
=0; i
< nColumnCount
; ++i
)
1263 sal_uInt16 nModelPos
= pGrid
->GetModelColumnPos(pGrid
->GetColumnIdFromViewPos(static_cast<sal_uInt16
>(i
)));
1264 DBG_ASSERT(nModelPos
!= sal_uInt16(-1), "FmXGridPeer::queryFieldData : invalid model pos !");
1266 // don't use GetCurrentFieldValue to determine the field content as this isn't affected by the above SeekRow
1267 // FS - 30.09.99 - 68644
1268 DbGridColumn
* pCol
= aColumns
[ nModelPos
].get();
1269 Reference
<css::sdb::XColumn
> xFieldContent
= xPaintRow
->HasField(pCol
->GetFieldPos())
1270 ? xPaintRow
->GetField( pCol
->GetFieldPos() ).getColumn()
1271 : Reference
< XColumn
> ();
1273 if ( !xFieldContent
.is() )
1276 if (bRequestedAsAny
)
1278 Reference
< XPropertySet
> xFieldSet(xFieldContent
, UNO_QUERY
);
1279 pReturnArray
[i
] = xFieldSet
->getPropertyValue(FM_PROP_VALUE
);
1283 switch (xType
.getTypeClass())
1285 // Strings are dealt with directly by the GetFieldText
1286 case TypeClass_STRING
:
1288 OUString sText
= aColumns
[ nModelPos
]->GetCellText( xPaintRow
.get(), pGrid
->getNumberFormatter() );
1289 pReturnArray
[i
] <<= sText
;
1292 // everything else is requested in the DatabaseVariant
1293 case TypeClass_FLOAT
: pReturnArray
[i
] <<= xFieldContent
->getFloat(); break;
1294 case TypeClass_DOUBLE
: pReturnArray
[i
] <<= xFieldContent
->getDouble(); break;
1295 case TypeClass_SHORT
: pReturnArray
[i
] <<= xFieldContent
->getShort(); break;
1296 case TypeClass_LONG
: pReturnArray
[i
] <<= static_cast<sal_Int32
>(xFieldContent
->getLong()); break;
1297 case TypeClass_UNSIGNED_SHORT
: pReturnArray
[i
] <<= static_cast<sal_uInt16
>(xFieldContent
->getShort()); break;
1298 case TypeClass_UNSIGNED_LONG
: pReturnArray
[i
] <<= static_cast<sal_uInt32
>(xFieldContent
->getLong()); break;
1299 case TypeClass_BOOLEAN
: pReturnArray
[i
] <<= xFieldContent
->getBoolean(); break;
1302 throw IllegalArgumentException();
1307 return aReturnSequence
;
1311 void FmXGridPeer::CellModified()
1313 std::unique_lock
g(m_aMutex
);
1315 aEvt
.Source
= getXWeak();
1316 m_aModifyListeners
.notifyEach( g
, &XModifyListener::modified
, aEvt
);
1319 // XPropertyChangeListener
1321 void FmXGridPeer::propertyChange(const PropertyChangeEvent
& evt
)
1323 SolarMutexGuard aGuard
;
1324 // want to do a lot of VCL stuff here ...
1325 // this should not be (deadlock) critical, as by definition, every component should release
1326 // any own mutexes before notifying
1328 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1333 if (evt
.PropertyName
== FM_PROP_VALUE
|| m_xCursor
== evt
.Source
)
1334 pGrid
->propertyChange(evt
);
1335 else if (pGrid
&& m_xColumns
.is() && m_xColumns
->hasElements())
1337 // next find which column has changed
1338 css::uno::Reference
<css::uno::XInterface
> xCurrent
;
1341 for ( i
= 0; i
< m_xColumns
->getCount(); i
++)
1343 xCurrent
.set(m_xColumns
->getByIndex(i
), css::uno::UNO_QUERY
);
1344 if (evt
.Source
== xCurrent
)
1348 if (i
>= m_xColumns
->getCount())
1349 // this is valid because we are listening at the cursor, too (RecordCount, -status, edit mode)
1352 sal_uInt16 nId
= pGrid
->GetColumnIdFromModelPos(static_cast<sal_uInt16
>(i
));
1353 bool bInvalidateColumn
= false;
1355 if (evt
.PropertyName
== FM_PROP_LABEL
)
1357 OUString aName
= ::comphelper::getString(evt
.NewValue
);
1358 if (aName
!= pGrid
->GetColumnTitle(nId
))
1359 pGrid
->SetColumnTitle(nId
, aName
);
1361 else if (evt
.PropertyName
== FM_PROP_WIDTH
)
1363 sal_Int32 nWidth
= 0;
1364 if (evt
.NewValue
.getValueTypeClass() == TypeClass_VOID
)
1365 nWidth
= pGrid
->GetDefaultColumnWidth(pGrid
->GetColumnTitle(nId
));
1366 // GetDefaultColumnWidth already considered the zoom factor
1369 sal_Int32 nTest
= 0;
1370 if (evt
.NewValue
>>= nTest
)
1372 nWidth
= pGrid
->LogicToPixel(Point(nTest
, 0), MapMode(MapUnit::Map10thMM
)).X();
1373 // take the zoom factor into account
1374 nWidth
= pGrid
->CalcZoom(nWidth
);
1377 if (nWidth
!= (sal_Int32(pGrid
->GetColumnWidth(nId
))))
1379 if (pGrid
->IsEditing())
1381 pGrid
->DeactivateCell();
1382 pGrid
->ActivateCell();
1384 pGrid
->SetColumnWidth(nId
, nWidth
);
1387 else if (evt
.PropertyName
== FM_PROP_HIDDEN
)
1389 DBG_ASSERT(evt
.NewValue
.getValueTypeClass() == TypeClass_BOOLEAN
,
1390 "FmXGridPeer::propertyChange : the property 'hidden' should be of type boolean !");
1391 if (::comphelper::getBOOL(evt
.NewValue
))
1392 pGrid
->HideColumn(nId
);
1394 pGrid
->ShowColumn(nId
);
1396 else if (evt
.PropertyName
== FM_PROP_ALIGN
)
1398 // in design mode it doesn't matter
1399 if (!isDesignMode())
1401 DbGridColumn
* pCol
= pGrid
->GetColumns()[i
].get();
1403 pCol
->SetAlignmentFromModel(-1);
1404 bInvalidateColumn
= true;
1407 else if (evt
.PropertyName
== FM_PROP_FORMATKEY
)
1409 if (!isDesignMode())
1410 bInvalidateColumn
= true;
1413 // need to invalidate the affected column ?
1414 if (bInvalidateColumn
)
1416 bool bWasEditing
= pGrid
->IsEditing();
1418 pGrid
->DeactivateCell();
1420 ::tools::Rectangle aColRect
= pGrid
->GetFieldRect(nId
);
1421 aColRect
.SetTop( 0 );
1422 aColRect
.SetBottom( pGrid
->GetSizePixel().Height() );
1423 pGrid
->Invalidate(aColRect
);
1426 pGrid
->ActivateCell();
1433 void FmXGridPeer::addUpdateListener(const Reference
< XUpdateListener
>& l
)
1435 std::unique_lock
g(m_aMutex
);
1436 m_aUpdateListeners
.addInterface(g
, l
);
1440 void FmXGridPeer::removeUpdateListener(const Reference
< XUpdateListener
>& l
)
1442 std::unique_lock
g(m_aMutex
);
1443 m_aUpdateListeners
.removeInterface(g
, l
);
1447 sal_Bool
FmXGridPeer::commit()
1449 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1450 if (!m_xCursor
.is() || !pGrid
)
1453 std::unique_lock
g(m_aMutex
);
1454 EventObject
aEvt(getXWeak());
1455 ::comphelper::OInterfaceIteratorHelper4
aIter(g
, m_aUpdateListeners
);
1456 bool bCancel
= false;
1457 while (aIter
.hasMoreElements() && !bCancel
)
1458 if ( !aIter
.next()->approveUpdate( aEvt
) )
1462 bCancel
= !pGrid
->commit();
1465 m_aUpdateListeners
.notifyEach( g
, &XUpdateListener::updated
, aEvt
);
1470 void FmXGridPeer::cursorMoved(const EventObject
& _rEvent
)
1472 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1473 // we are not interested in moving to insert row only in the reset event
1474 // which is fired after positioning and the insert row
1475 if (pGrid
&& pGrid
->IsOpen() && !::comphelper::getBOOL(Reference
< XPropertySet
> (_rEvent
.Source
, UNO_QUERY_THROW
)->getPropertyValue(FM_PROP_ISNEW
)))
1476 pGrid
->positioned();
1480 void FmXGridPeer::rowChanged(const EventObject
& /*_rEvent*/)
1482 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1483 if (pGrid
&& pGrid
->IsOpen())
1485 if (m_xCursor
->rowUpdated() && !pGrid
->IsCurrentAppending())
1486 pGrid
->RowModified(pGrid
->GetCurrentPos());
1487 else if (m_xCursor
->rowInserted())
1493 void FmXGridPeer::rowSetChanged(const EventObject
& /*event*/)
1495 // not interested in ...
1496 // (our parent is a form which means we get a loaded or reloaded after this rowSetChanged)
1501 void FmXGridPeer::loaded(const EventObject
& /*rEvent*/)
1503 updateGrid(m_xCursor
);
1507 void FmXGridPeer::unloaded(const EventObject
& /*rEvent*/)
1509 updateGrid( Reference
< XRowSet
> (nullptr) );
1513 void FmXGridPeer::reloading(const EventObject
& /*aEvent*/)
1516 updateGrid( Reference
< XRowSet
> (nullptr) );
1520 void FmXGridPeer::unloading(const EventObject
& /*aEvent*/)
1523 updateGrid( Reference
< XRowSet
> (nullptr) );
1527 void FmXGridPeer::reloaded(const EventObject
& aEvent
)
1530 const sal_Int32 cnt
= m_xColumns
->getCount();
1531 for(sal_Int32 i
=0; i
<cnt
; ++i
)
1533 Reference
< XLoadListener
> xll(m_xColumns
->getByIndex(i
), UNO_QUERY
);
1536 xll
->reloaded(aEvent
);
1540 updateGrid(m_xCursor
);
1545 Reference
< XIndexContainer
> FmXGridPeer::getColumns()
1551 void FmXGridPeer::addColumnListeners(const Reference
< XPropertySet
>& xCol
)
1553 static constexpr OUString aPropsListenedTo
[] =
1555 FM_PROP_LABEL
, FM_PROP_WIDTH
, FM_PROP_HIDDEN
, FM_PROP_ALIGN
,
1559 // as not all properties have to be supported by all columns we have to check this
1560 // before adding a listener
1561 Reference
< XPropertySetInfo
> xInfo
= xCol
->getPropertySetInfo();
1562 for (size_t i
=0; i
<SAL_N_ELEMENTS(aPropsListenedTo
); ++i
)
1564 if ( xInfo
->hasPropertyByName( aPropsListenedTo
[i
] ) )
1566 Property aPropDesc
= xInfo
->getPropertyByName( aPropsListenedTo
[i
] );
1567 if ( 0 != ( aPropDesc
.Attributes
& PropertyAttribute::BOUND
) )
1568 xCol
->addPropertyChangeListener( aPropsListenedTo
[i
], this );
1574 void FmXGridPeer::removeColumnListeners(const Reference
< XPropertySet
>& xCol
)
1576 // the same props as in addColumnListeners... linux has problems with global static UStrings, so
1577 // we have to do it this way...
1578 static constexpr OUString aPropsListenedTo
[] =
1580 FM_PROP_LABEL
, FM_PROP_WIDTH
, FM_PROP_HIDDEN
, FM_PROP_ALIGN
,
1584 Reference
< XPropertySetInfo
> xInfo
= xCol
->getPropertySetInfo();
1585 for (const auto & i
: aPropsListenedTo
)
1586 if (xInfo
->hasPropertyByName(i
))
1587 xCol
->removePropertyChangeListener(i
, this);
1591 void FmXGridPeer::setColumns(const Reference
< XIndexContainer
>& Columns
)
1593 SolarMutexGuard aGuard
;
1595 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1597 if (m_xColumns
.is())
1599 Reference
< XPropertySet
> xCol
;
1600 for (sal_Int32 i
= 0; i
< m_xColumns
->getCount(); i
++)
1602 xCol
.set(m_xColumns
->getByIndex(i
), css::uno::UNO_QUERY
);
1603 removeColumnListeners(xCol
);
1605 Reference
< XContainer
> xContainer(m_xColumns
, UNO_QUERY
);
1606 xContainer
->removeContainerListener(this);
1608 Reference
< XSelectionSupplier
> xSelSupplier(m_xColumns
, UNO_QUERY
);
1609 xSelSupplier
->removeSelectionChangeListener(this);
1611 Reference
< XReset
> xColumnReset(m_xColumns
, UNO_QUERY
);
1612 if (xColumnReset
.is())
1613 xColumnReset
->removeResetListener(static_cast<XResetListener
*>(this));
1617 Reference
< XContainer
> xContainer(Columns
, UNO_QUERY
);
1618 xContainer
->addContainerListener(this);
1620 Reference
< XSelectionSupplier
> xSelSupplier(Columns
, UNO_QUERY
);
1621 xSelSupplier
->addSelectionChangeListener(this);
1623 Reference
< XPropertySet
> xCol
;
1624 for (sal_Int32 i
= 0; i
< Columns
->getCount(); i
++)
1626 xCol
.set(Columns
->getByIndex(i
), css::uno::UNO_QUERY
);
1627 addColumnListeners(xCol
);
1630 Reference
< XReset
> xColumnReset(Columns
, UNO_QUERY
);
1631 if (xColumnReset
.is())
1632 xColumnReset
->addResetListener(static_cast<XResetListener
*>(this));
1634 m_xColumns
= Columns
;
1637 pGrid
->InitColumnsByModels(m_xColumns
);
1639 if (m_xColumns
.is())
1641 EventObject
aEvt(m_xColumns
);
1642 selectionChanged(aEvt
);
1648 void FmXGridPeer::setDesignMode(sal_Bool bOn
)
1650 if (bOn
!= isDesignMode())
1652 VclPtr
<vcl::Window
> pWin
= GetWindow();
1654 static_cast<FmGridControl
*>(pWin
.get())->SetDesignMode(bOn
);
1658 DisConnectFromDispatcher();
1660 UpdateDispatches(); // will connect if not already connected and just update else
1664 sal_Bool
FmXGridPeer::isDesignMode()
1666 VclPtr
<vcl::Window
> pWin
= GetWindow();
1668 return static_cast<FmGridControl
*>(pWin
.get())->IsDesignMode();
1674 void FmXGridPeer::elementInserted(const ContainerEvent
& evt
)
1676 SolarMutexGuard aGuard
;
1678 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1679 // take handle column into account
1680 if (!pGrid
|| !m_xColumns
.is() || pGrid
->IsInColumnMove() || m_xColumns
->getCount() == static_cast<sal_Int32
>(pGrid
->GetModelColCount()))
1683 Reference
< XPropertySet
> xNewColumn(evt
.Element
, css::uno::UNO_QUERY
);
1684 addColumnListeners(xNewColumn
);
1686 OUString aName
= ::comphelper::getString(xNewColumn
->getPropertyValue(FM_PROP_LABEL
));
1687 Any aWidth
= xNewColumn
->getPropertyValue(FM_PROP_WIDTH
);
1688 sal_Int32 nWidth
= 0;
1689 if (aWidth
>>= nWidth
)
1690 nWidth
= pGrid
->LogicToPixel(Point(nWidth
, 0), MapMode(MapUnit::Map10thMM
)).X();
1692 pGrid
->AppendColumn(aName
, static_cast<sal_uInt16
>(nWidth
), static_cast<sal_Int16
>(::comphelper::getINT32(evt
.Accessor
)));
1694 // now set the column
1695 DbGridColumn
* pCol
= pGrid
->GetColumns()[ ::comphelper::getINT32(evt
.Accessor
) ].get();
1696 pCol
->setModel(xNewColumn
);
1698 Any aHidden
= xNewColumn
->getPropertyValue(FM_PROP_HIDDEN
);
1699 if (::comphelper::getBOOL(aHidden
))
1700 pGrid
->HideColumn(pCol
->GetId());
1702 FormControlFactory( m_xContext
).initializeTextFieldLineEnds( xNewColumn
);
1706 void FmXGridPeer::elementReplaced(const ContainerEvent
& evt
)
1708 SolarMutexGuard aGuard
;
1710 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1712 // take handle column into account
1713 if (!pGrid
|| !m_xColumns
.is() || pGrid
->IsInColumnMove())
1716 Reference
< XPropertySet
> xNewColumn(evt
.Element
, css::uno::UNO_QUERY
);
1717 Reference
< XPropertySet
> xOldColumn(
1718 evt
.ReplacedElement
, css::uno::UNO_QUERY
);
1720 bool bWasEditing
= pGrid
->IsEditing();
1722 pGrid
->DeactivateCell();
1724 pGrid
->RemoveColumn(pGrid
->GetColumnIdFromModelPos(static_cast<sal_uInt16
>(::comphelper::getINT32(evt
.Accessor
))));
1726 removeColumnListeners(xOldColumn
);
1727 addColumnListeners(xNewColumn
);
1729 OUString aName
= ::comphelper::getString(xNewColumn
->getPropertyValue(FM_PROP_LABEL
));
1730 Any aWidth
= xNewColumn
->getPropertyValue(FM_PROP_WIDTH
);
1731 sal_Int32 nWidth
= 0;
1732 if (aWidth
>>= nWidth
)
1733 nWidth
= pGrid
->LogicToPixel(Point(nWidth
, 0), MapMode(MapUnit::Map10thMM
)).X();
1734 sal_uInt16 nNewId
= pGrid
->AppendColumn(aName
, static_cast<sal_uInt16
>(nWidth
), static_cast<sal_Int16
>(::comphelper::getINT32(evt
.Accessor
)));
1735 sal_uInt16 nNewPos
= pGrid
->GetModelColumnPos(nNewId
);
1737 // set the model of the new column
1738 DbGridColumn
* pCol
= pGrid
->GetColumns()[ nNewPos
].get();
1740 // for initializing this grid column, we need the fields of the grid's data source
1741 Reference
< XColumnsSupplier
> xSuppColumns
;
1742 CursorWrapper
* pGridDataSource
= pGrid
->getDataSource();
1743 if ( pGridDataSource
)
1744 xSuppColumns
.set(Reference
< XInterface
>( *pGridDataSource
), css::uno::UNO_QUERY
);
1745 Reference
< XNameAccess
> xColumnsByName
;
1746 if ( xSuppColumns
.is() )
1747 xColumnsByName
= xSuppColumns
->getColumns();
1748 Reference
< XIndexAccess
> xColumnsByIndex( xColumnsByName
, UNO_QUERY
);
1750 if ( xColumnsByIndex
.is() )
1751 FmGridControl::InitColumnByField( pCol
, xNewColumn
, xColumnsByName
, xColumnsByIndex
);
1753 // the simple version, applies when the grid is not yet connected to a data source
1754 pCol
->setModel(xNewColumn
);
1757 pGrid
->ActivateCell();
1761 void FmXGridPeer::elementRemoved(const ContainerEvent
& evt
)
1763 SolarMutexGuard aGuard
;
1765 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1767 // take handle column into account
1768 if (!pGrid
|| !m_xColumns
.is() || pGrid
->IsInColumnMove() || m_xColumns
->getCount() == static_cast<sal_Int32
>(pGrid
->GetModelColCount()))
1771 pGrid
->RemoveColumn(pGrid
->GetColumnIdFromModelPos(static_cast<sal_uInt16
>(::comphelper::getINT32(evt
.Accessor
))));
1773 Reference
< XPropertySet
> xOldColumn(evt
.Element
, css::uno::UNO_QUERY
);
1774 removeColumnListeners(xOldColumn
);
1778 void FmXGridPeer::setProperty( const OUString
& PropertyName
, const Any
& Value
)
1780 SolarMutexGuard aGuard
;
1782 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1784 bool bVoid
= !Value
.hasValue();
1786 if ( PropertyName
== FM_PROP_TEXTLINECOLOR
)
1788 ::Color
aTextLineColor( bVoid
? COL_TRANSPARENT
: ::Color(ColorTransparency
, ::comphelper::getINT32( Value
)) );
1791 pGrid
->SetTextLineColor();
1792 pGrid
->GetDataWindow().SetTextLineColor();
1796 pGrid
->SetTextLineColor(aTextLineColor
);
1797 pGrid
->GetDataWindow().SetTextLineColor(aTextLineColor
);
1800 // need to forward this to the columns
1801 std::vector
< std::unique_ptr
<DbGridColumn
> > const & rColumns
= pGrid
->GetColumns();
1802 for (auto const & pLoop
: rColumns
)
1804 FmXGridCell
* pXCell
= pLoop
->GetCell();
1808 pXCell
->SetTextLineColor();
1810 pXCell
->SetTextLineColor(aTextLineColor
);
1815 pGrid
->Invalidate();
1817 else if ( PropertyName
== FM_PROP_FONTEMPHASISMARK
)
1819 vcl::Font aGridFont
= pGrid
->GetControlFont();
1820 sal_Int16 nValue
= ::comphelper::getINT16(Value
);
1821 aGridFont
.SetEmphasisMark( static_cast<FontEmphasisMark
>(nValue
) );
1822 pGrid
->SetControlFont( aGridFont
);
1824 else if ( PropertyName
== FM_PROP_FONTRELIEF
)
1826 vcl::Font aGridFont
= pGrid
->GetControlFont();
1827 sal_Int16 nValue
= ::comphelper::getINT16(Value
);
1828 aGridFont
.SetRelief( static_cast<FontRelief
>(nValue
) );
1829 pGrid
->SetControlFont( aGridFont
);
1831 else if ( PropertyName
== FM_PROP_HELPURL
)
1834 OSL_VERIFY( Value
>>= sHelpURL
);
1835 INetURLObject
aHID( sHelpURL
);
1836 if ( aHID
.GetProtocol() == INetProtocol::Hid
)
1837 sHelpURL
= aHID
.GetURLPath();
1838 pGrid
->SetHelpId( sHelpURL
);
1840 else if ( PropertyName
== FM_PROP_DISPLAYSYNCHRON
)
1842 pGrid
->setDisplaySynchron(::comphelper::getBOOL(Value
));
1844 else if ( PropertyName
== FM_PROP_CURSORCOLOR
)
1847 pGrid
->SetCursorColor(COL_TRANSPARENT
);
1849 pGrid
->SetCursorColor( ::Color(ColorTransparency
, ::comphelper::getINT32(Value
)));
1851 pGrid
->Invalidate();
1853 else if ( PropertyName
== FM_PROP_ALWAYSSHOWCURSOR
)
1855 pGrid
->EnablePermanentCursor(::comphelper::getBOOL(Value
));
1857 pGrid
->Invalidate();
1859 else if ( PropertyName
== FM_PROP_FONT
)
1862 pGrid
->SetControlFont( vcl::Font() );
1865 css::awt::FontDescriptor aFont
;
1866 if (Value
>>= aFont
)
1868 vcl::Font aNewVclFont
;
1869 if (aFont
!= ::comphelper::getDefaultFont()) // is this the default
1870 aNewVclFont
= ImplCreateFont( aFont
);
1872 // need to add relief and emphasis (they're stored in a VCL-Font, but not in a FontDescriptor
1873 vcl::Font aOldVclFont
= pGrid
->GetControlFont();
1874 aNewVclFont
.SetRelief( aOldVclFont
.GetRelief() );
1875 aNewVclFont
.SetEmphasisMark( aOldVclFont
.GetEmphasisMark() );
1878 pGrid
->SetControlFont( aNewVclFont
);
1880 // if our row-height property is void (which means "calculate it font-dependent") we have
1881 // to adjust the control's row height
1882 Reference
< XPropertySet
> xModelSet(getColumns(), UNO_QUERY
);
1883 if (xModelSet
.is() && ::comphelper::hasProperty(FM_PROP_ROWHEIGHT
, xModelSet
))
1885 Any aHeight
= xModelSet
->getPropertyValue(FM_PROP_ROWHEIGHT
);
1886 if (!aHeight
.hasValue())
1887 pGrid
->SetDataRowHeight(0);
1893 else if ( PropertyName
== FM_PROP_BACKGROUNDCOLOR
)
1897 pGrid
->SetControlBackground();
1901 ::Color
aColor( ColorTransparency
, ::comphelper::getINT32(Value
) );
1902 pGrid
->SetBackground( aColor
);
1903 pGrid
->SetControlBackground( aColor
);
1906 else if ( PropertyName
== FM_PROP_TEXTCOLOR
)
1910 pGrid
->SetControlForeground();
1914 ::Color
aColor( ColorTransparency
, ::comphelper::getINT32(Value
) );
1915 pGrid
->SetTextColor( aColor
);
1916 pGrid
->SetControlForeground( aColor
);
1919 else if ( PropertyName
== FM_PROP_ROWHEIGHT
)
1921 sal_Int32
nLogHeight(0);
1922 if (Value
>>= nLogHeight
)
1924 sal_Int32 nHeight
= pGrid
->LogicToPixel(Point(0, nLogHeight
), MapMode(MapUnit::Map10thMM
)).Y();
1925 // take the zoom factor into account
1926 nHeight
= pGrid
->CalcZoom(nHeight
);
1927 pGrid
->SetDataRowHeight(nHeight
);
1930 pGrid
->SetDataRowHeight(0);
1932 else if ( PropertyName
== FM_PROP_HASNAVIGATION
)
1934 bool bValue( true );
1935 OSL_VERIFY( Value
>>= bValue
);
1936 pGrid
->EnableNavigationBar( bValue
);
1938 else if ( PropertyName
== FM_PROP_RECORDMARKER
)
1940 bool bValue( true );
1941 OSL_VERIFY( Value
>>= bValue
);
1942 pGrid
->EnableHandle( bValue
);
1944 else if ( PropertyName
== FM_PROP_ENABLED
)
1946 bool bValue( true );
1947 OSL_VERIFY( Value
>>= bValue
);
1949 // In design mode, disable only the data window.
1950 // Else the control cannot be configured anymore.
1952 pGrid
->GetDataWindow().Enable( bValue
);
1954 pGrid
->Enable( bValue
);
1957 VCLXWindow::setProperty( PropertyName
, Value
);
1961 Reference
< XAccessibleContext
> FmXGridPeer::CreateAccessibleContext()
1963 Reference
< XAccessibleContext
> xContext
;
1965 // use the AccessibleContext provided by the VCL window
1966 VclPtr
<vcl::Window
> pGrid
= GetWindow();
1969 Reference
< XAccessible
> xAcc( pGrid
->GetAccessible() );
1971 xContext
= xAcc
->getAccessibleContext();
1972 // TODO: this has a slight conceptual problem:
1974 // We know that the XAccessible and XAccessibleContext implementation of the browse
1975 // box is the same (the class implements both interfaces), which, speaking strictly,
1976 // is bad here (means when a browse box acts as UnoControl): We (the FmXGridPeer) are
1977 // the XAccessible here, and the browse box should be able to provide us an XAccessibleContext,
1978 // but it should _not_ be the XAccessible itself.
1979 // However, as long as no client implementation uses dirty hacks such as querying an
1980 // XAccessibleContext for XAccessible, this should not be a problem.
1983 if ( !xContext
.is() )
1984 xContext
= VCLXWindow::CreateAccessibleContext( );
1990 Any
FmXGridPeer::getProperty( const OUString
& _rPropertyName
)
1995 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1996 vcl::Window
* pDataWindow
= &pGrid
->GetDataWindow();
1998 if ( _rPropertyName
== FM_PROP_NAME
)
2000 vcl::Font aFont
= pDataWindow
->GetControlFont();
2001 aProp
<<= ImplCreateFontDescriptor( aFont
);
2003 else if ( _rPropertyName
== FM_PROP_TEXTCOLOR
)
2005 aProp
<<= pDataWindow
->GetControlForeground();
2007 else if ( _rPropertyName
== FM_PROP_BACKGROUNDCOLOR
)
2009 aProp
<<= pDataWindow
->GetControlBackground();
2011 else if ( _rPropertyName
== FM_PROP_ROWHEIGHT
)
2013 sal_Int32 nPixelHeight
= pGrid
->GetDataRowHeight();
2014 // take the zoom factor into account
2015 nPixelHeight
= pGrid
->CalcReverseZoom(nPixelHeight
);
2016 aProp
<<= static_cast<sal_Int32
>(pGrid
->PixelToLogic(Point(0, nPixelHeight
), MapMode(MapUnit::Map10thMM
)).Y());
2018 else if ( _rPropertyName
== FM_PROP_HASNAVIGATION
)
2020 bool bHasNavBar
= pGrid
->HasNavigationBar();
2021 aProp
<<= bHasNavBar
;
2023 else if ( _rPropertyName
== FM_PROP_RECORDMARKER
)
2025 bool bHasHandle
= pGrid
->HasHandle();
2026 aProp
<<= bHasHandle
;
2028 else if ( _rPropertyName
== FM_PROP_ENABLED
)
2030 aProp
<<= pDataWindow
->IsEnabled();
2033 aProp
= VCLXWindow::getProperty( _rPropertyName
);
2039 void FmXGridPeer::dispose()
2042 std::unique_lock
g(m_aMutex
);
2044 aEvt
.Source
= getXWeak();
2045 m_aModifyListeners
.disposeAndClear(g
, aEvt
);
2046 m_aUpdateListeners
.disposeAndClear(g
, aEvt
);
2047 m_aContainerListeners
.disposeAndClear(g
, aEvt
);
2049 // release all interceptors
2050 Reference
< XDispatchProviderInterceptor
> xInterceptor( m_xFirstDispatchInterceptor
);
2051 m_xFirstDispatchInterceptor
.clear();
2052 while ( xInterceptor
.is() )
2054 // tell the interceptor it has a new (means no) predecessor
2055 xInterceptor
->setMasterDispatchProvider( nullptr );
2057 // ask for its successor
2058 Reference
< XDispatchProvider
> xSlave
= xInterceptor
->getSlaveDispatchProvider();
2059 // and give it the new (means no) successoert
2060 xInterceptor
->setSlaveDispatchProvider( nullptr );
2062 // start over with the next chain element
2063 xInterceptor
.set(xSlave
, css::uno::UNO_QUERY
);
2066 DisConnectFromDispatcher();
2068 // unregister all listeners
2071 m_xCursor
->removeRowSetListener(this);
2073 Reference
< XReset
> xReset(m_xCursor
, UNO_QUERY
);
2075 xReset
->removeResetListener(this);
2076 Reference
< XLoadable
> xLoadable(m_xCursor
, UNO_QUERY
);
2078 xLoadable
->removeLoadListener(this);
2079 Reference
< XPropertySet
> xSet(m_xCursor
, UNO_QUERY
);
2082 xSet
->removePropertyChangeListener(FM_PROP_ISMODIFIED
, this);
2083 xSet
->removePropertyChangeListener(FM_PROP_ROWCOUNT
, this);
2088 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2091 pGrid
->setDataSource(Reference
< XRowSet
> ());
2092 pGrid
->DisposeAccessible();
2095 VCLXWindow::dispose();
2100 void FmXGridPeer::addContainerListener(const Reference
< XContainerListener
>& l
)
2102 std::unique_lock
g(m_aMutex
);
2103 m_aContainerListeners
.addInterface( g
, l
);
2106 void FmXGridPeer::removeContainerListener(const Reference
< XContainerListener
>& l
)
2108 std::unique_lock
g(m_aMutex
);
2109 m_aContainerListeners
.removeInterface( g
, l
);
2112 // css::data::XDatabaseCursorSupplier
2114 void FmXGridPeer::startCursorListening()
2116 if (!m_nCursorListening
)
2119 m_xCursor
->addRowSetListener(this);
2121 Reference
< XReset
> xReset(m_xCursor
, UNO_QUERY
);
2123 xReset
->addResetListener(this);
2125 // register all listeners
2126 Reference
< XPropertySet
> xSet(m_xCursor
, UNO_QUERY
);
2129 xSet
->addPropertyChangeListener(FM_PROP_ISMODIFIED
, this);
2130 xSet
->addPropertyChangeListener(FM_PROP_ROWCOUNT
, this);
2133 m_nCursorListening
++;
2137 void FmXGridPeer::stopCursorListening()
2139 if (--m_nCursorListening
)
2143 m_xCursor
->removeRowSetListener(this);
2145 Reference
< XReset
> xReset(m_xCursor
, UNO_QUERY
);
2147 xReset
->removeResetListener(this);
2149 Reference
< XPropertySet
> xSet(m_xCursor
, UNO_QUERY
);
2152 xSet
->removePropertyChangeListener(FM_PROP_ISMODIFIED
, this);
2153 xSet
->removePropertyChangeListener(FM_PROP_ROWCOUNT
, this);
2158 void FmXGridPeer::updateGrid(const Reference
< XRowSet
>& _rxCursor
)
2160 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2162 pGrid
->setDataSource(_rxCursor
);
2166 Reference
< XRowSet
> FmXGridPeer::getRowSet()
2172 void FmXGridPeer::setRowSet(const Reference
< XRowSet
>& _rDatabaseCursor
)
2174 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2175 if (!pGrid
|| !m_xColumns
.is() || !m_xColumns
->getCount())
2177 // unregister all listeners
2180 Reference
< XLoadable
> xLoadable(m_xCursor
, UNO_QUERY
);
2181 // only if the form is loaded we set the rowset
2184 stopCursorListening();
2185 xLoadable
->removeLoadListener(this);
2189 m_xCursor
= _rDatabaseCursor
;
2194 Reference
< XLoadable
> xLoadable(m_xCursor
, UNO_QUERY
);
2195 // only if the form is loaded we set the rowset
2196 if (xLoadable
.is() && xLoadable
->isLoaded())
2197 pGrid
->setDataSource(m_xCursor
);
2199 pGrid
->setDataSource(Reference
< XRowSet
> ());
2203 startCursorListening();
2204 xLoadable
->addLoadListener(this);
2209 void SAL_CALL
FmXGridPeer::addGridControlListener( const Reference
< XGridControlListener
>& _listener
)
2211 std::unique_lock
g(m_aMutex
);
2212 m_aGridControlListeners
.addInterface( g
, _listener
);
2216 void SAL_CALL
FmXGridPeer::removeGridControlListener( const Reference
< XGridControlListener
>& _listener
)
2218 std::unique_lock
g(m_aMutex
);
2219 m_aGridControlListeners
.removeInterface( g
, _listener
);
2223 sal_Int16
FmXGridPeer::getCurrentColumnPosition()
2225 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2226 return pGrid
? pGrid
->GetViewColumnPos(pGrid
->GetCurColumnId()) : -1;
2230 void FmXGridPeer::setCurrentColumnPosition(sal_Int16 nPos
)
2232 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2234 pGrid
->GoToColumnId(pGrid
->GetColumnIdFromViewPos(nPos
));
2238 void FmXGridPeer::selectionChanged(const EventObject
& evt
)
2240 SolarMutexGuard aGuard
;
2242 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2246 Reference
< css::view::XSelectionSupplier
> xSelSupplier(evt
.Source
, UNO_QUERY
);
2247 Any aSelection
= xSelSupplier
->getSelection();
2248 DBG_ASSERT(aSelection
.getValueTypeClass() == TypeClass_INTERFACE
, "FmXGridPeer::selectionChanged : invalid selection !");
2249 Reference
< XPropertySet
> xSelection
;
2250 aSelection
>>= xSelection
;
2251 if (xSelection
.is())
2253 Reference
< XPropertySet
> xCol
;
2255 sal_Int32 nColCount
= m_xColumns
->getCount();
2257 for (; i
< nColCount
; ++i
)
2259 m_xColumns
->getByIndex(i
) >>= xCol
;
2260 if ( xCol
== xSelection
)
2262 pGrid
->markColumn(pGrid
->GetColumnIdFromModelPos(static_cast<sal_uInt16
>(i
)));
2266 // The columns have to be 1-based for the VCL control.
2267 // If necessary, pass on the selection to the VCL control
2268 if ( i
!= pGrid
->GetSelectedColumn() )
2269 { // (if this does not take effect, the selectionChanged was implicitly triggered by the control itself)
2270 if ( i
< nColCount
)
2272 pGrid
->SelectColumnPos(pGrid
->GetViewColumnPos(pGrid
->GetColumnIdFromModelPos( static_cast<sal_uInt16
>(i
) )) + 1);
2273 // SelectColumnPos has led to an implicit ActivateCell again
2274 if (pGrid
->IsEditing())
2275 pGrid
->DeactivateCell();
2278 pGrid
->SetNoSelection();
2282 pGrid
->markColumn(USHRT_MAX
);
2287 sal_Bool
FmXGridPeer::hasElements()
2289 return getCount() != 0;
2293 Type SAL_CALL
FmXGridPeer::getElementType( )
2295 return cppu::UnoType
<css::awt::XControl
>::get();
2298 // XEnumerationAccess
2300 Reference
< XEnumeration
> FmXGridPeer::createEnumeration()
2302 return new ::comphelper::OEnumerationByIndex(this);
2307 sal_Int32
FmXGridPeer::getCount()
2309 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2311 return pGrid
->GetViewColCount();
2317 Any
FmXGridPeer::getByIndex(sal_Int32 _nIndex
)
2319 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2321 _nIndex
>= getCount() || !pGrid
)
2322 throw IndexOutOfBoundsException();
2326 sal_uInt16 nId
= pGrid
->GetColumnIdFromViewPos(static_cast<sal_uInt16
>(_nIndex
));
2327 // get the list position
2328 sal_uInt16 nPos
= pGrid
->GetModelColumnPos(nId
);
2330 if ( nPos
== GRID_COLUMN_NOT_FOUND
)
2333 DbGridColumn
* pCol
= pGrid
->GetColumns()[ nPos
].get();
2334 Reference
< css::awt::XControl
> xControl(pCol
->GetCell());
2335 aElement
<<= xControl
;
2340 // css::util::XModeSelector
2342 void FmXGridPeer::setMode(const OUString
& Mode
)
2344 if (!supportsMode(Mode
))
2345 throw NoSupportException();
2347 if (Mode
== m_aMode
)
2352 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2353 if ( Mode
== "FilterMode" )
2354 pGrid
->SetFilterMode(true);
2357 pGrid
->SetFilterMode(false);
2358 pGrid
->setDataSource(m_xCursor
);
2363 OUString
FmXGridPeer::getMode()
2369 css::uno::Sequence
<OUString
> FmXGridPeer::getSupportedModes()
2371 static css::uno::Sequence
<OUString
> const aModes
2380 sal_Bool
FmXGridPeer::supportsMode(const OUString
& Mode
)
2382 css::uno::Sequence
<OUString
> aModes(getSupportedModes());
2383 return comphelper::findValue(aModes
, Mode
) != -1;
2387 void FmXGridPeer::columnVisible(DbGridColumn
const * pColumn
)
2389 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2391 sal_Int32 _nIndex
= pGrid
->GetModelColumnPos(pColumn
->GetId());
2392 Reference
< css::awt::XControl
> xControl(pColumn
->GetCell());
2393 ContainerEvent aEvt
;
2394 aEvt
.Source
= static_cast<XContainer
*>(this);
2395 aEvt
.Accessor
<<= _nIndex
;
2396 aEvt
.Element
<<= xControl
;
2398 std::unique_lock
g(m_aMutex
);
2399 m_aContainerListeners
.notifyEach( g
, &XContainerListener::elementInserted
, aEvt
);
2403 void FmXGridPeer::columnHidden(DbGridColumn
const * pColumn
)
2405 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2407 sal_Int32 _nIndex
= pGrid
->GetModelColumnPos(pColumn
->GetId());
2408 Reference
< css::awt::XControl
> xControl(pColumn
->GetCell());
2409 ContainerEvent aEvt
;
2410 aEvt
.Source
= static_cast<XContainer
*>(this);
2411 aEvt
.Accessor
<<= _nIndex
;
2412 aEvt
.Element
<<= xControl
;
2414 std::unique_lock
g(m_aMutex
);
2415 m_aContainerListeners
.notifyEach( g
, &XContainerListener::elementRemoved
, aEvt
);
2419 void FmXGridPeer::draw( sal_Int32 x
, sal_Int32 y
)
2421 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2422 EditBrowseBoxFlags nOldFlags
= pGrid
->GetBrowserFlags();
2423 pGrid
->SetBrowserFlags(nOldFlags
| EditBrowseBoxFlags::NO_HANDLE_COLUMN_CONTENT
);
2425 VCLXWindow::draw(x
, y
);
2427 pGrid
->SetBrowserFlags(nOldFlags
);
2431 Reference
< css::frame::XDispatch
> FmXGridPeer::queryDispatch(const css::util::URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
2433 Reference
< css::frame::XDispatch
> xResult
;
2435 // first ask our interceptor chain
2436 if (m_xFirstDispatchInterceptor
.is() && !m_bInterceptingDispatch
)
2438 m_bInterceptingDispatch
= true;
2439 // safety against recursion : as we are master of the first chain element and slave of the last one we would
2440 // have an infinite loop without this if no dispatcher can fulfill the request
2441 xResult
= m_xFirstDispatchInterceptor
->queryDispatch(aURL
, aTargetFrameName
, nSearchFlags
);
2442 m_bInterceptingDispatch
= false;
2445 // then ask ourself : we don't have any dispatches
2450 Sequence
< Reference
< css::frame::XDispatch
> > FmXGridPeer::queryDispatches(const Sequence
< css::frame::DispatchDescriptor
>& aDescripts
)
2452 if (m_xFirstDispatchInterceptor
.is())
2453 return m_xFirstDispatchInterceptor
->queryDispatches(aDescripts
);
2455 // then ask ourself : we don't have any dispatches
2456 return Sequence
< Reference
< css::frame::XDispatch
> >();
2460 void FmXGridPeer::registerDispatchProviderInterceptor(const Reference
< css::frame::XDispatchProviderInterceptor
>& _xInterceptor
)
2462 if (!_xInterceptor
.is())
2465 if (m_xFirstDispatchInterceptor
.is())
2467 // there is already an interceptor; the new one will become its master
2468 _xInterceptor
->setSlaveDispatchProvider(m_xFirstDispatchInterceptor
);
2469 m_xFirstDispatchInterceptor
->setMasterDispatchProvider(m_xFirstDispatchInterceptor
);
2473 // it is the first interceptor; set ourself as slave
2474 _xInterceptor
->setSlaveDispatchProvider(static_cast<css::frame::XDispatchProvider
*>(this));
2477 // we are the master of the chain's first interceptor
2478 m_xFirstDispatchInterceptor
= _xInterceptor
;
2479 m_xFirstDispatchInterceptor
->setMasterDispatchProvider(static_cast<css::frame::XDispatchProvider
*>(this));
2481 // we have a new interceptor and we're alive ?
2482 if (!isDesignMode())
2483 // -> check for new dispatchers
2488 void FmXGridPeer::releaseDispatchProviderInterceptor(const Reference
< css::frame::XDispatchProviderInterceptor
>& _xInterceptor
)
2490 if (!_xInterceptor
.is())
2493 Reference
< css::frame::XDispatchProviderInterceptor
> xChainWalk(m_xFirstDispatchInterceptor
);
2495 if (m_xFirstDispatchInterceptor
== _xInterceptor
)
2496 { // our chain will have a new first element
2497 m_xFirstDispatchInterceptor
.set(m_xFirstDispatchInterceptor
->getSlaveDispatchProvider(), UNO_QUERY
);
2499 // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
2501 while (xChainWalk
.is())
2503 // walk along the chain of interceptors and look for the interceptor that has to be removed
2504 Reference
< css::frame::XDispatchProviderInterceptor
> xSlave(xChainWalk
->getSlaveDispatchProvider(), UNO_QUERY
);
2506 if (xChainWalk
== _xInterceptor
)
2508 // old master may be an interceptor too
2509 Reference
< css::frame::XDispatchProviderInterceptor
> xMaster(xChainWalk
->getMasterDispatchProvider(), UNO_QUERY
);
2511 // unchain the interceptor that has to be removed
2512 xChainWalk
->setSlaveDispatchProvider(Reference
< css::frame::XDispatchProvider
> ());
2513 xChainWalk
->setMasterDispatchProvider(Reference
< css::frame::XDispatchProvider
> ());
2515 // reconnect the chain
2519 xMaster
->setSlaveDispatchProvider(xSlave
);
2521 // it's the first interceptor of the chain, set ourself as slave
2522 xMaster
->setSlaveDispatchProvider(static_cast<css::frame::XDispatchProvider
*>(this));
2526 // the chain's first element was removed, set ourself as new master of the second one
2528 xSlave
->setMasterDispatchProvider(static_cast<css::frame::XDispatchProvider
*>(this));
2532 xChainWalk
= std::move(xSlave
);
2534 // our interceptor chain has changed and we're alive ?
2535 if (!isDesignMode())
2536 // -> check the dispatchers
2541 void FmXGridPeer::statusChanged(const css::frame::FeatureStateEvent
& Event
)
2543 DBG_ASSERT(m_pStateCache
, "FmXGridPeer::statusChanged : invalid call !");
2544 DBG_ASSERT(m_pDispatchers
, "FmXGridPeer::statusChanged : invalid call !");
2546 const Sequence
< css::util::URL
>& aUrls
= getSupportedURLs();
2548 const std::vector
<DbGridControlNavigationBarState
>& aSlots
= getSupportedGridSlots();
2550 auto pUrl
= std::find_if(aUrls
.begin(), aUrls
.end(),
2551 [&Event
](const css::util::URL
& rUrl
) { return rUrl
.Main
== Event
.FeatureURL
.Main
; });
2552 if (pUrl
!= aUrls
.end())
2554 auto i
= static_cast<sal_uInt32
>(std::distance(aUrls
.begin(), pUrl
));
2555 DBG_ASSERT(m_pDispatchers
[i
] == Event
.Source
, "FmXGridPeer::statusChanged : the event source is a little bit suspect !");
2556 m_pStateCache
[i
] = Event
.IsEnabled
;
2557 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2558 if (aSlots
[i
] != DbGridControlNavigationBarState::Undo
)
2559 pGrid
->GetNavigationBar().InvalidateState(aSlots
[i
]);
2561 DBG_ASSERT(pUrl
!= aUrls
.end(), "FmXGridPeer::statusChanged : got a call for an unknown url !");
2565 sal_Bool
FmXGridPeer::approveReset(const EventObject
& /*rEvent*/)
2571 sal_Bool SAL_CALL
FmXGridPeer::select( const Any
& _rSelection
)
2573 Sequence
< Any
> aBookmarks
;
2574 if ( !( _rSelection
>>= aBookmarks
) )
2575 throw IllegalArgumentException();
2577 return GetAs
< FmGridControl
>()->selectBookmarks(aBookmarks
);
2580 // speaking strictly, we would have to adjust our model, as our ColumnSelection may have changed.
2581 // Our model is a XSelectionSupplier, too, it handles the selection of single columns.
2582 // This is somewhat strange, as selection should be a view (not a model) aspect.
2583 // So for a clean solution, we should handle column selection ourself, and the model shouldn't
2584 // deal with selection at all.
2588 Any SAL_CALL
FmXGridPeer::getSelection( )
2590 VclPtr
< FmGridControl
> pVclControl
= GetAs
< FmGridControl
>();
2591 Sequence
< Any
> aSelectionBookmarks
= pVclControl
->getSelectionBookmarks();
2592 return Any(aSelectionBookmarks
);
2596 void SAL_CALL
FmXGridPeer::addSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
)
2598 std::unique_lock
g(m_aMutex
);
2599 m_aSelectionListeners
.addInterface( g
, _rxListener
);
2603 void SAL_CALL
FmXGridPeer::removeSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
)
2605 std::unique_lock
g(m_aMutex
);
2606 m_aSelectionListeners
.removeInterface( g
, _rxListener
);
2610 void FmXGridPeer::resetted(const EventObject
& rEvent
)
2612 if (m_xColumns
== rEvent
.Source
)
2613 { // my model was reset -> refresh the grid content
2614 SolarMutexGuard aGuard
;
2615 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2618 pGrid
->resetCurrentRow();
2620 // if the cursor fired a reset event we seem to be on the insert row
2621 else if (m_xCursor
== rEvent
.Source
)
2623 SolarMutexGuard aGuard
;
2624 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2625 if (pGrid
&& pGrid
->IsOpen())
2626 pGrid
->positioned();
2631 const std::vector
<DbGridControlNavigationBarState
>& FmXGridPeer::getSupportedGridSlots()
2633 static const std::vector
<DbGridControlNavigationBarState
> aSupported
{
2634 DbGridControlNavigationBarState::First
,
2635 DbGridControlNavigationBarState::Prev
,
2636 DbGridControlNavigationBarState::Next
,
2637 DbGridControlNavigationBarState::Last
,
2638 DbGridControlNavigationBarState::New
,
2639 DbGridControlNavigationBarState::Undo
2645 Sequence
< css::util::URL
>& FmXGridPeer::getSupportedURLs()
2647 static Sequence
< css::util::URL
> aSupported
= []()
2649 static constexpr OUString sSupported
[] = {
2650 FMURL_RECORD_MOVEFIRST
,
2651 FMURL_RECORD_MOVEPREV
,
2652 FMURL_RECORD_MOVENEXT
,
2653 FMURL_RECORD_MOVELAST
,
2654 FMURL_RECORD_MOVETONEW
,
2657 Sequence
< css::util::URL
> tmp(SAL_N_ELEMENTS(sSupported
));
2658 css::util::URL
* pSupported
= tmp
.getArray();
2660 for ( sal_Int32 i
= 0; i
< tmp
.getLength(); ++i
, ++pSupported
)
2661 pSupported
->Complete
= sSupported
[i
];
2663 // let a css::util::URL-transformer normalize the URLs
2664 Reference
< css::util::XURLTransformer
> xTransformer(
2665 util::URLTransformer::create(::comphelper::getProcessComponentContext()) );
2666 for (css::util::URL
& rURL
: asNonConstRange(tmp
))
2667 xTransformer
->parseStrict(rURL
);
2675 void FmXGridPeer::UpdateDispatches()
2678 { // we don't have any dispatchers yet -> do the initial connect
2679 ConnectToDispatcher();
2683 sal_uInt16 nDispatchersGot
= 0;
2684 const Sequence
< css::util::URL
>& aSupportedURLs
= getSupportedURLs();
2685 const css::util::URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
2686 Reference
< css::frame::XDispatch
> xNewDispatch
;
2687 for (sal_Int32 i
=0; i
<aSupportedURLs
.getLength(); ++i
, ++pSupportedURLs
)
2689 xNewDispatch
= queryDispatch(*pSupportedURLs
, OUString(), 0);
2690 if (xNewDispatch
!= m_pDispatchers
[i
])
2692 if (m_pDispatchers
[i
].is())
2693 m_pDispatchers
[i
]->removeStatusListener(static_cast<css::frame::XStatusListener
*>(this), *pSupportedURLs
);
2694 m_pDispatchers
[i
] = xNewDispatch
;
2695 if (m_pDispatchers
[i
].is())
2696 m_pDispatchers
[i
]->addStatusListener(static_cast<css::frame::XStatusListener
*>(this), *pSupportedURLs
);
2698 if (m_pDispatchers
[i
].is())
2702 if (!nDispatchersGot
)
2704 m_pStateCache
.reset();
2705 m_pDispatchers
.reset();
2710 void FmXGridPeer::ConnectToDispatcher()
2712 DBG_ASSERT((m_pStateCache
!= nullptr) == (m_pDispatchers
!= nullptr), "FmXGridPeer::ConnectToDispatcher : inconsistent !");
2714 { // already connected -> just do an update
2719 const Sequence
< css::util::URL
>& aSupportedURLs
= getSupportedURLs();
2721 // _before_ adding the status listeners (as the add should result in a statusChanged-call) !
2722 m_pStateCache
.reset(new bool[aSupportedURLs
.getLength()]);
2723 m_pDispatchers
.reset(new Reference
< css::frame::XDispatch
> [aSupportedURLs
.getLength()]);
2725 sal_uInt16 nDispatchersGot
= 0;
2726 const css::util::URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
2727 for (sal_Int32 i
=0; i
<aSupportedURLs
.getLength(); ++i
, ++pSupportedURLs
)
2729 m_pStateCache
[i
] = false;
2730 m_pDispatchers
[i
] = queryDispatch(*pSupportedURLs
, OUString(), 0);
2731 if (m_pDispatchers
[i
].is())
2733 m_pDispatchers
[i
]->addStatusListener(static_cast<css::frame::XStatusListener
*>(this), *pSupportedURLs
);
2738 if (!nDispatchersGot
)
2740 m_pStateCache
.reset();
2741 m_pDispatchers
.reset();
2746 void FmXGridPeer::DisConnectFromDispatcher()
2748 if (!m_pStateCache
|| !m_pDispatchers
)
2750 // we're not connected
2752 const Sequence
< css::util::URL
>& aSupportedURLs
= getSupportedURLs();
2753 const css::util::URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
2754 for (sal_Int32 i
=0; i
<aSupportedURLs
.getLength(); ++i
, ++pSupportedURLs
)
2756 if (m_pDispatchers
[i
].is())
2757 m_pDispatchers
[i
]->removeStatusListener(static_cast<css::frame::XStatusListener
*>(this), *pSupportedURLs
);
2760 m_pStateCache
.reset();
2761 m_pDispatchers
.reset();
2765 IMPL_LINK(FmXGridPeer
, OnQueryGridSlotState
, DbGridControlNavigationBarState
, nSlot
, int)
2768 return -1; // unspecified
2770 // search the given slot with our supported sequence
2771 const std::vector
<DbGridControlNavigationBarState
>& aSupported
= getSupportedGridSlots();
2772 for (size_t i
=0; i
<aSupported
.size(); ++i
)
2774 if (aSupported
[i
] == nSlot
)
2776 if (!m_pDispatchers
[i
].is())
2777 return -1; // nothing known about this slot
2779 return m_pStateCache
[i
] ? 1 : 0;
2787 IMPL_LINK(FmXGridPeer
, OnExecuteGridSlot
, DbGridControlNavigationBarState
, nSlot
, bool)
2789 if (!m_pDispatchers
)
2790 return false; // not handled
2792 Sequence
< css::util::URL
>& aUrls
= getSupportedURLs();
2793 const css::util::URL
* pUrls
= aUrls
.getConstArray();
2795 const std::vector
<DbGridControlNavigationBarState
>& aSlots
= getSupportedGridSlots();
2797 DBG_ASSERT(aSlots
.size() == o3tl::make_unsigned(aUrls
.getLength()), "FmXGridPeer::OnExecuteGridSlot : inconsistent data returned by getSupportedURLs/getSupportedGridSlots!");
2799 for (size_t i
=0; i
<aSlots
.size(); ++i
, ++pUrls
)
2801 if (aSlots
[i
] == nSlot
)
2803 if (m_pDispatchers
[i
].is())
2805 // commit any changes done so far, if it's not the undoRecord URL
2806 if ( pUrls
->Complete
== FMURL_RECORD_UNDO
|| commit() )
2807 m_pDispatchers
[i
]->dispatch(*pUrls
, Sequence
< PropertyValue
>());
2809 return true; // handled
2814 return false; // not handled
2817 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */