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 .
21 #include "svx/fmgridif.hxx"
23 #include "fmservs.hxx"
24 #include "svx/fmtools.hxx"
26 #include "formcontrolfactory.hxx"
27 #include "gridcell.hxx"
28 #include "sdbdatacolumn.hxx"
29 #include "svx/fmgridcl.hxx"
30 #include "svx/svxids.hrc"
31 #include <tools/urlobj.hxx>
33 #include <com/sun/star/awt/PosSize.hpp>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/form/FormComponentType.hpp>
36 #include <com/sun/star/form/XFormComponent.hpp>
37 #include <com/sun/star/form/XLoadable.hpp>
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <com/sun/star/sdbc/ResultSetType.hpp>
40 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
41 #include <com/sun/star/util/URLTransformer.hpp>
42 #include <com/sun/star/util/XURLTransformer.hpp>
43 #include <com/sun/star/view/XSelectionSupplier.hpp>
44 #include <com/sun/star/sdbcx/XRowLocate.hpp>
46 #include <comphelper/container.hxx>
47 #include <comphelper/enumhelper.hxx>
48 #include <comphelper/processfactory.hxx>
49 #include <comphelper/property.hxx>
50 #include <comphelper/sequence.hxx>
51 #include <comphelper/servicehelper.hxx>
52 #include <comphelper/types.hxx>
53 #include <cppuhelper/supportsservice.hxx>
54 #include <cppuhelper/typeprovider.hxx>
55 #include <cppuhelper/queryinterface.hxx>
56 #include <toolkit/helper/vclunohelper.hxx>
57 #include <tools/diagnose_ex.h>
58 #include <sal/macros.h>
60 using namespace ::svxform
;
61 using namespace ::com::sun::star::container
;
62 using namespace ::com::sun::star::sdb
;
63 using namespace ::com::sun::star::sdbc
;
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::view
;
66 using namespace ::com::sun::star::beans
;
67 using namespace ::com::sun::star::lang
;
68 using namespace ::com::sun::star::form
;
69 using namespace ::com::sun::star::util
;
70 using namespace ::com::sun::star
;
72 using ::com::sun::star::sdbcx::XColumnsSupplier
;
73 using ::com::sun::star::frame::XDispatchProviderInterceptor
;
74 using ::com::sun::star::frame::XDispatchProvider
;
75 using ::com::sun::star::accessibility::XAccessible
;
76 using ::com::sun::star::accessibility::XAccessibleContext
;
77 using ::com::sun::star::sdb::XRowSetSupplier
;
78 using ::com::sun::star::awt::XVclWindowPeer
;
82 ::com::sun::star::awt::FontDescriptor
ImplCreateFontDescriptor( const vcl::Font
& rFont
)
84 ::com::sun::star::awt::FontDescriptor aFD
;
85 aFD
.Name
= rFont
.GetName();
86 aFD
.StyleName
= rFont
.GetStyleName();
87 aFD
.Height
= (sal_Int16
)rFont
.GetSize().Height();
88 aFD
.Width
= (sal_Int16
)rFont
.GetSize().Width();
89 aFD
.Family
= (sal_Int16
)rFont
.GetFamily();
90 aFD
.CharSet
= rFont
.GetCharSet();
91 aFD
.Pitch
= (sal_Int16
)rFont
.GetPitch();
92 aFD
.CharacterWidth
= VCLUnoHelper::ConvertFontWidth( rFont
.GetWidthType() );
93 aFD
.Weight
= VCLUnoHelper::ConvertFontWeight( rFont
.GetWeight() );
94 aFD
.Slant
= VCLUnoHelper::ConvertFontSlant( rFont
.GetItalic() );
95 aFD
.Underline
= (sal_Int16
)rFont
.GetUnderline();
96 aFD
.Strikeout
= (sal_Int16
)rFont
.GetStrikeout();
97 aFD
.Orientation
= rFont
.GetOrientation();
98 aFD
.Kerning
= rFont
.IsKerning();
99 aFD
.WordLineMode
= rFont
.IsWordLineMode();
100 aFD
.Type
= 0; // ??? => Nur an Metric...
105 vcl::Font
ImplCreateFont( const ::com::sun::star::awt::FontDescriptor
& rDescr
)
108 aFont
.SetName( rDescr
.Name
);
109 aFont
.SetStyleName( rDescr
.StyleName
);
110 aFont
.SetSize( ::Size( rDescr
.Width
, rDescr
.Height
) );
111 aFont
.SetFamily( (FontFamily
)rDescr
.Family
);
112 aFont
.SetCharSet( (rtl_TextEncoding
)rDescr
.CharSet
);
113 aFont
.SetPitch( (FontPitch
)rDescr
.Pitch
);
114 aFont
.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr
.CharacterWidth
) );
115 aFont
.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr
.Weight
) );
116 aFont
.SetItalic( (FontItalic
)rDescr
.Slant
);
117 aFont
.SetUnderline( (::FontUnderline
)rDescr
.Underline
);
118 aFont
.SetStrikeout( (::FontStrikeout
)rDescr
.Strikeout
);
119 aFont
.SetOrientation( (sal_Int16
)rDescr
.Orientation
);
120 aFont
.SetKerning( static_cast<FontKerning
>(rDescr
.Kerning
) );
121 aFont
.SetWordLineMode( rDescr
.WordLineMode
);
125 FmXModifyMultiplexer::FmXModifyMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
126 :OWeakSubObject( rSource
)
127 ,OInterfaceContainerHelper( _rMutex
)
132 Any SAL_CALL
FmXModifyMultiplexer::queryInterface(const Type
& _rType
) throw (RuntimeException
, std::exception
)
135 aReturn
= ::cppu::queryInterface(_rType
,
136 static_cast< ::com::sun::star::util::XModifyListener
*>(this),
137 static_cast< XEventListener
*>(this)
140 if (!aReturn
.hasValue())
141 aReturn
= OWeakSubObject::queryInterface( _rType
);
147 void FmXModifyMultiplexer::disposing(const EventObject
& ) throw( RuntimeException
, std::exception
)
152 void FmXModifyMultiplexer::modified(const EventObject
& e
) throw( RuntimeException
, std::exception
)
154 EventObject
aMulti( e
);
155 aMulti
.Source
= &m_rParent
;
156 notifyEach( &XModifyListener::modified
, aMulti
);
159 FmXUpdateMultiplexer::FmXUpdateMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
160 :OWeakSubObject( rSource
)
161 ,OInterfaceContainerHelper( _rMutex
)
166 Any SAL_CALL
FmXUpdateMultiplexer::queryInterface(const Type
& _rType
) throw (RuntimeException
, std::exception
)
169 aReturn
= ::cppu::queryInterface(_rType
,
170 static_cast< XUpdateListener
*>(this),
171 static_cast< XEventListener
*>(this)
174 if (!aReturn
.hasValue())
175 aReturn
= OWeakSubObject::queryInterface( _rType
);
181 void FmXUpdateMultiplexer::disposing(const EventObject
& ) throw( RuntimeException
, std::exception
)
186 sal_Bool
FmXUpdateMultiplexer::approveUpdate(const EventObject
&e
) throw( RuntimeException
, std::exception
)
188 EventObject
aMulti( e
);
189 aMulti
.Source
= &m_rParent
;
194 ::cppu::OInterfaceIteratorHelper
aIter(*this);
195 while ( bResult
&& aIter
.hasMoreElements() )
196 bResult
= static_cast< XUpdateListener
* >( aIter
.next() )->approveUpdate( aMulti
);
203 void FmXUpdateMultiplexer::updated(const EventObject
&e
) throw( RuntimeException
, std::exception
)
205 EventObject
aMulti( e
);
206 aMulti
.Source
= &m_rParent
;
207 notifyEach( &XUpdateListener::updated
, aMulti
);
210 FmXSelectionMultiplexer::FmXSelectionMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
211 :OWeakSubObject( rSource
)
212 ,OInterfaceContainerHelper( _rMutex
)
217 Any SAL_CALL
FmXSelectionMultiplexer::queryInterface(const Type
& _rType
) throw (RuntimeException
, std::exception
)
220 aReturn
= ::cppu::queryInterface(_rType
,
221 static_cast< XSelectionChangeListener
*>(this),
222 static_cast< XEventListener
*>(this)
225 if (!aReturn
.hasValue())
226 aReturn
= OWeakSubObject::queryInterface( _rType
);
232 void FmXSelectionMultiplexer::disposing(const EventObject
& ) throw( RuntimeException
, std::exception
)
237 void SAL_CALL
FmXSelectionMultiplexer::selectionChanged( const EventObject
& _rEvent
) throw (RuntimeException
, std::exception
)
239 EventObject
aMulti(_rEvent
);
240 aMulti
.Source
= &m_rParent
;
241 notifyEach( &XSelectionChangeListener::selectionChanged
, aMulti
);
244 FmXContainerMultiplexer::FmXContainerMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
245 :OWeakSubObject( rSource
)
246 ,OInterfaceContainerHelper( _rMutex
)
251 Any SAL_CALL
FmXContainerMultiplexer::queryInterface(const Type
& _rType
) throw (RuntimeException
, std::exception
)
254 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
& ) throw( RuntimeException
, std::exception
)
270 void FmXContainerMultiplexer::elementInserted(const ContainerEvent
& e
) throw( RuntimeException
, std::exception
)
272 ContainerEvent
aMulti( e
);
273 aMulti
.Source
= &m_rParent
;
274 notifyEach( &XContainerListener::elementInserted
, aMulti
);
278 void FmXContainerMultiplexer::elementRemoved(const ContainerEvent
& e
) throw( RuntimeException
, std::exception
)
280 ContainerEvent
aMulti( e
);
281 aMulti
.Source
= &m_rParent
;
282 notifyEach( &XContainerListener::elementRemoved
, aMulti
);
287 void FmXContainerMultiplexer::elementReplaced(const ContainerEvent
& e
) throw( RuntimeException
, std::exception
)
289 ContainerEvent
aMulti( e
);
290 aMulti
.Source
= &m_rParent
;
291 notifyEach( &XContainerListener::elementReplaced
, aMulti
);
294 FmXGridControlMultiplexer::FmXGridControlMultiplexer( ::cppu::OWeakObject
& rSource
, ::osl::Mutex
& _rMutex
)
295 :OWeakSubObject( rSource
)
296 ,OInterfaceContainerHelper( _rMutex
)
301 Any SAL_CALL
FmXGridControlMultiplexer::queryInterface(const Type
& _rType
) throw (RuntimeException
, std::exception
)
304 aReturn
= ::cppu::queryInterface( _rType
,
305 static_cast< XGridControlListener
*>(this)
308 if (!aReturn
.hasValue())
309 aReturn
= OWeakSubObject::queryInterface( _rType
);
315 void FmXGridControlMultiplexer::disposing( const EventObject
& ) throw( RuntimeException
, std::exception
)
320 void SAL_CALL
FmXGridControlMultiplexer::columnChanged( const EventObject
& _event
) throw (RuntimeException
, std::exception
)
322 EventObject
aForwardedEvent( _event
);
323 aForwardedEvent
.Source
= &m_rParent
;
324 notifyEach( &XGridControlListener::columnChanged
, aForwardedEvent
);
332 Reference
< XInterface
> SAL_CALL
FmXGridControl_NewInstance_Impl(const Reference
< XMultiServiceFactory
>& _rxFactory
)
333 throw (css::uno::Exception
)
335 return *(new FmXGridControl( comphelper::getComponentContext(_rxFactory
) ));
338 FmXGridControl::FmXGridControl(const Reference
< XComponentContext
>& _rxContext
)
340 ,m_aModifyListeners(*this, GetMutex())
341 ,m_aUpdateListeners(*this, GetMutex())
342 ,m_aContainerListeners(*this, GetMutex())
343 ,m_aSelectionListeners(*this, GetMutex())
344 ,m_aGridControlListeners(*this, GetMutex())
345 ,m_nPeerCreationLevel(0)
347 ,m_xContext(_rxContext
)
352 FmXGridControl::~FmXGridControl()
357 Any SAL_CALL
FmXGridControl::queryAggregation(const Type
& _rType
) throw (RuntimeException
, std::exception
)
359 Any aReturn
= FmXGridControl_BASE::queryInterface(_rType
);
361 if (!aReturn
.hasValue())
362 aReturn
= UnoControl::queryAggregation( _rType
);
367 Sequence
< Type
> SAL_CALL
FmXGridControl::getTypes( ) throw(RuntimeException
, std::exception
)
369 return comphelper::concatSequences(UnoControl::getTypes(),FmXGridControl_BASE::getTypes());
373 Sequence
<sal_Int8
> SAL_CALL
FmXGridControl::getImplementationId( ) throw(RuntimeException
, std::exception
)
375 return css::uno::Sequence
<sal_Int8
>();
379 sal_Bool SAL_CALL
FmXGridControl::supportsService(const OUString
& ServiceName
) throw(std::exception
)
381 return cppu::supportsService(this, ServiceName
);
384 OUString SAL_CALL
FmXGridControl::getImplementationName() throw(std::exception
)
386 return OUString("com.sun.star.form.FmXGridControl");
389 ::comphelper::StringSequence SAL_CALL
FmXGridControl::getSupportedServiceNames() throw(std::exception
)
391 Sequence
< OUString
> aServiceNames(2);
392 aServiceNames
[0] = FM_SUN_CONTROL_GRIDCONTROL
;
393 aServiceNames
[1] = "com.sun.star.awt.UnoControl";
394 return aServiceNames
;
398 void SAL_CALL
FmXGridControl::dispose() throw( RuntimeException
, std::exception
)
400 SolarMutexGuard aGuard
;
403 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >(this);
404 m_aModifyListeners
.disposeAndClear(aEvt
);
405 m_aUpdateListeners
.disposeAndClear(aEvt
);
406 m_aContainerListeners
.disposeAndClear(aEvt
);
408 UnoControl::dispose();
412 OUString
FmXGridControl::GetComponentServiceName()
414 OUString
aName("DBGrid");
419 sal_Bool SAL_CALL
FmXGridControl::setModel(const Reference
< ::com::sun::star::awt::XControlModel
>& rModel
) throw( RuntimeException
, std::exception
)
421 SolarMutexGuard aGuard
;
423 if (!UnoControl::setModel(rModel
))
426 Reference
< XGridPeer
> xGridPeer(getPeer(), UNO_QUERY
);
429 Reference
< XIndexContainer
> xCols(mxModel
, UNO_QUERY
);
430 xGridPeer
->setColumns(xCols
);
436 FmXGridPeer
* FmXGridControl::imp_CreatePeer(vcl::Window
* pParent
)
438 FmXGridPeer
* pReturn
= new FmXGridPeer(m_xContext
);
440 // translate properties into WinBits
441 WinBits nStyle
= WB_TABSTOP
;
442 Reference
< XPropertySet
> xModelSet(getModel(), UNO_QUERY
);
447 if (::comphelper::getINT16(xModelSet
->getPropertyValue(FM_PROP_BORDER
)))
450 catch(const Exception
&)
452 OSL_FAIL("Can not get style");
456 pReturn
->Create(pParent
, nStyle
);
461 void SAL_CALL
FmXGridControl::createPeer(const Reference
< ::com::sun::star::awt::XToolkit
>& /*rToolkit*/, const Reference
< ::com::sun::star::awt::XWindowPeer
>& rParentPeer
) throw( RuntimeException
, std::exception
)
464 throw DisposedException( OUString(), *this );
466 DBG_ASSERT(/*(0 == m_nPeerCreationLevel) && */!mbCreatingPeer
, "FmXGridControl::createPeer : recursion!");
467 // I think this should never assert, now that we're using the base class' mbCreatingPeer in addition to
468 // our own m_nPeerCreationLevel
469 // But I'm not sure as I don't _fully_ understand the underlying toolkit implementations ....
470 // (if this asserts, we still need m_nPeerCreationLevel. If not, we could omit it ....)
471 // 14.05.2001 - 86836 - frank.schoenheit@germany.sun.com
473 // TODO: why the hell this whole class does not use any mutex?
477 mbCreatingPeer
= true;
478 // mbCreatingPeer is virtually the same as m_nPeerCreationLevel, but it's the base class' method
479 // to prevent recursion.
481 vcl::Window
* pParentWin
= NULL
;
482 if (rParentPeer
.is())
484 VCLXWindow
* pParent
= VCLXWindow::GetImplementation(rParentPeer
);
486 pParentWin
= pParent
->GetWindow();
489 FmXGridPeer
* pPeer
= imp_CreatePeer(pParentWin
);
490 DBG_ASSERT(pPeer
!= NULL
, "FmXGridControl::createPeer : imp_CreatePeer didn't return a peer !");
493 // reading the properties from the model
494 // ++m_nPeerCreationLevel;
497 // consider the following ugly scenario: updateFromModel leads to a propertiesChanges on the Control,
498 // which determines, dat a "critical" property has changed (e.g. "Border") and therefore starts a new
499 // Peer, which lands again here in createPeerm we also start a second FmXGridPeer and initialise it.
500 // Then we exit from the first incarnation's updateFromModel and continue working with the pPeer,
501 // that is in fact now already obsolete (as another peer is being started in the second incarnation).
502 // Therefore the effort with the PeerCreationLevel, which ensures that we really use the Peer
503 // created at the deepest level, but first initialise it in the top-level.
504 // if (--m_nPeerCreationLevel == 0)
506 DBG_ASSERT(getPeer().is(), "FmXGridControl::createPeer : something went wrong ... no top level peer !");
507 pPeer
= FmXGridPeer::getImplementation(getPeer());
509 setPosSize( maComponentInfos
.nX
, maComponentInfos
.nY
, maComponentInfos
.nWidth
, maComponentInfos
.nHeight
, ::com::sun::star::awt::PosSize::POSSIZE
);
511 Reference
< XIndexContainer
> xColumns(getModel(), UNO_QUERY
);
513 pPeer
->setColumns(xColumns
);
515 if (maComponentInfos
.bVisible
)
516 pPeer
->setVisible(sal_True
);
518 if (!maComponentInfos
.bEnable
)
519 pPeer
->setEnable(sal_False
);
521 if (maWindowListeners
.getLength())
522 pPeer
->addWindowListener( &maWindowListeners
);
524 if (maFocusListeners
.getLength())
525 pPeer
->addFocusListener( &maFocusListeners
);
527 if (maKeyListeners
.getLength())
528 pPeer
->addKeyListener( &maKeyListeners
);
530 if (maMouseListeners
.getLength())
531 pPeer
->addMouseListener( &maMouseListeners
);
533 if (maMouseMotionListeners
.getLength())
534 pPeer
->addMouseMotionListener( &maMouseMotionListeners
);
536 if (maPaintListeners
.getLength())
537 pPeer
->addPaintListener( &maPaintListeners
);
539 if (m_aModifyListeners
.getLength())
540 pPeer
->addModifyListener( &m_aModifyListeners
);
542 if (m_aUpdateListeners
.getLength())
543 pPeer
->addUpdateListener( &m_aUpdateListeners
);
545 if (m_aContainerListeners
.getLength())
546 pPeer
->addContainerListener( &m_aContainerListeners
);
548 // forward the design mode
549 bool bForceAlivePeer
= m_bInDraw
&& !maComponentInfos
.bVisible
;
550 // (we force an alive-mode peer if we're in "draw", cause in this case the peer will be used for drawing in
551 // foreign devices. We ensure this with the visibility check as an living peer is assumed to be noncritical
552 // only if invisible)
553 Any aOldCursorBookmark
;
554 if (!mbDesignMode
|| bForceAlivePeer
)
556 Reference
< XFormComponent
> xComp(getModel(), UNO_QUERY
);
559 Reference
< XRowSet
> xForm(xComp
->getParent(), UNO_QUERY
);
560 // is the form alive?
561 // we can see that if the form contains columns
562 Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> xColumnsSupplier(xForm
, UNO_QUERY
);
563 if (xColumnsSupplier
.is())
565 if (Reference
< XIndexAccess
> (xColumnsSupplier
->getColumns(),UNO_QUERY
)->getCount())
567 // we get only a new bookmark if the resultset is not forwardonly
568 if (::comphelper::getINT32(Reference
< XPropertySet
> (xForm
, UNO_QUERY
)->getPropertyValue(FM_PROP_RESULTSET_TYPE
)) != ResultSetType::FORWARD_ONLY
)
570 // as the FmGridControl touches the data source it is connected to we have to remember the current
571 // cursor position (and restore afterwards)
572 // OJ: but only when we stand on a valid row
573 Reference
< XResultSet
> xResultSet(xForm
, UNO_QUERY
);
574 if ( !xResultSet
->isBeforeFirst() && !xResultSet
->isAfterLast() )
578 aOldCursorBookmark
= Reference
< ::com::sun::star::sdbcx::XRowLocate
> (xForm
, UNO_QUERY
)->getBookmark();
580 catch( const Exception
& e
)
582 DBG_UNHANDLED_EXCEPTION();
589 pPeer
->setRowSet(xForm
);
592 pPeer
->setDesignMode(mbDesignMode
&& !bForceAlivePeer
);
596 if (aOldCursorBookmark
.hasValue())
597 { // we have a valid bookmark, so we have to restore the cursor's position
598 Reference
< XFormComponent
> xComp(getModel(), UNO_QUERY
);
599 Reference
< ::com::sun::star::sdbcx::XRowLocate
> xLocate(xComp
->getParent(), UNO_QUERY
);
600 xLocate
->moveToBookmark(aOldCursorBookmark
);
603 catch( const Exception
& e
)
605 DBG_UNHANDLED_EXCEPTION();
609 Reference
< ::com::sun::star::awt::XView
> xPeerView(getPeer(), UNO_QUERY
);
610 xPeerView
->setZoom( maComponentInfos
.nZoomX
, maComponentInfos
.nZoomY
);
611 xPeerView
->setGraphics( mxGraphics
);
613 mbCreatingPeer
= false;
618 void FmXGridControl::addModifyListener(const Reference
< ::com::sun::star::util::XModifyListener
>& l
) throw( RuntimeException
, std::exception
)
620 m_aModifyListeners
.addInterface( l
);
621 if( getPeer().is() && m_aModifyListeners
.getLength() == 1 )
623 Reference
< ::com::sun::star::util::XModifyBroadcaster
> xGrid(getPeer(), UNO_QUERY
);
624 xGrid
->addModifyListener( &m_aModifyListeners
);
629 sal_Bool SAL_CALL
FmXGridControl::select( const Any
& _rSelection
) throw (IllegalArgumentException
, RuntimeException
, std::exception
)
631 SolarMutexGuard aGuard
;
632 Reference
< XSelectionSupplier
> xPeer(getPeer(), UNO_QUERY
);
633 return xPeer
->select(_rSelection
);
637 Any SAL_CALL
FmXGridControl::getSelection( ) throw (RuntimeException
, std::exception
)
639 SolarMutexGuard aGuard
;
640 Reference
< XSelectionSupplier
> xPeer(getPeer(), UNO_QUERY
);
641 return xPeer
->getSelection();
645 void SAL_CALL
FmXGridControl::addSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
) throw (RuntimeException
, std::exception
)
647 m_aSelectionListeners
.addInterface( _rxListener
);
648 if( getPeer().is() && 1 == m_aSelectionListeners
.getLength() )
650 Reference
< XSelectionSupplier
> xGrid(getPeer(), UNO_QUERY
);
651 xGrid
->addSelectionChangeListener( &m_aSelectionListeners
);
656 void SAL_CALL
FmXGridControl::removeSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
) throw (RuntimeException
, std::exception
)
658 if( getPeer().is() && 1 == m_aSelectionListeners
.getLength() )
660 Reference
< XSelectionSupplier
> xGrid(getPeer(), UNO_QUERY
);
661 xGrid
->removeSelectionChangeListener( &m_aSelectionListeners
);
663 m_aSelectionListeners
.removeInterface( _rxListener
);
667 Sequence
< sal_Bool
> SAL_CALL
FmXGridControl::queryFieldDataType( const Type
& xType
) throw(RuntimeException
, std::exception
)
671 Reference
< XGridFieldDataSupplier
> xPeerSupplier(getPeer(), UNO_QUERY
);
672 if (xPeerSupplier
.is())
673 return xPeerSupplier
->queryFieldDataType(xType
);
676 return Sequence
<sal_Bool
>();
680 Sequence
< Any
> SAL_CALL
FmXGridControl::queryFieldData( sal_Int32 nRow
, const Type
& xType
) throw(RuntimeException
, std::exception
)
684 Reference
< XGridFieldDataSupplier
> xPeerSupplier(getPeer(), UNO_QUERY
);
685 if (xPeerSupplier
.is())
686 return xPeerSupplier
->queryFieldData(nRow
, xType
);
689 return Sequence
< Any
>();
693 void SAL_CALL
FmXGridControl::removeModifyListener(const Reference
< ::com::sun::star::util::XModifyListener
>& l
) throw( RuntimeException
, std::exception
)
695 if( getPeer().is() && m_aModifyListeners
.getLength() == 1 )
697 Reference
< ::com::sun::star::util::XModifyBroadcaster
> xGrid(getPeer(), UNO_QUERY
);
698 xGrid
->removeModifyListener( &m_aModifyListeners
);
700 m_aModifyListeners
.removeInterface( l
);
704 void SAL_CALL
FmXGridControl::draw( sal_Int32 x
, sal_Int32 y
) throw( RuntimeException
, std::exception
)
706 SolarMutexGuard aGuard
;
708 UnoControl::draw(x
, y
);
713 void SAL_CALL
FmXGridControl::setDesignMode(sal_Bool bOn
) throw( RuntimeException
, std::exception
)
715 ::com::sun::star::util::ModeChangeEvent aModeChangeEvent
;
717 // --- <mutex_lock> ---
719 SolarMutexGuard aGuard
;
721 Reference
< XRowSetSupplier
> xGrid(getPeer(), UNO_QUERY
);
723 if (xGrid
.is() && (bool(bOn
) != mbDesignMode
|| (!bOn
&& !xGrid
->getRowSet().is())))
727 xGrid
->setRowSet(Reference
< XRowSet
> ());
731 Reference
< XFormComponent
> xComp(getModel(), UNO_QUERY
);
734 Reference
< XRowSet
> xForm(xComp
->getParent(), UNO_QUERY
);
735 xGrid
->setRowSet(xForm
);
741 Reference
< XVclWindowPeer
> xVclWindowPeer( getPeer(), UNO_QUERY
);
742 if (xVclWindowPeer
.is())
743 xVclWindowPeer
->setDesignMode(bOn
);
747 // dispose our current AccessibleContext, if we have one
748 // (changing the design mode implies having a new implementation for this context,
749 // so the old one must be declared DEFUNC)
750 DisposeAccessibleContext(
751 Reference
<XComponent
>(maAccessibleContext
, UNO_QUERY
));
752 maAccessibleContext
.clear();
754 // prepare firing an event
755 aModeChangeEvent
.Source
= *this;
756 aModeChangeEvent
.NewMode
= mbDesignMode
? OUString( "design" ) : OUString( "alive" );
759 // --- </mutex_lock> ---
760 maModeChangeListeners
.notifyEach( &XModeChangeListener::modeChanged
, aModeChangeEvent
);
765 void SAL_CALL
FmXGridControl::addUpdateListener(const Reference
< XUpdateListener
>& l
) throw( RuntimeException
, std::exception
)
767 m_aUpdateListeners
.addInterface( l
);
768 if( getPeer().is() && m_aUpdateListeners
.getLength() == 1 )
770 Reference
< XBoundComponent
> xBound(getPeer(), UNO_QUERY
);
771 xBound
->addUpdateListener( &m_aUpdateListeners
);
776 void SAL_CALL
FmXGridControl::removeUpdateListener(const Reference
< XUpdateListener
>& l
) throw( RuntimeException
, std::exception
)
778 if( getPeer().is() && m_aUpdateListeners
.getLength() == 1 )
780 Reference
< XBoundComponent
> xBound(getPeer(), UNO_QUERY
);
781 xBound
->removeUpdateListener( &m_aUpdateListeners
);
783 m_aUpdateListeners
.removeInterface( l
);
787 sal_Bool SAL_CALL
FmXGridControl::commit() throw( RuntimeException
, std::exception
)
789 Reference
< XBoundComponent
> xBound(getPeer(), UNO_QUERY
);
791 return xBound
->commit();
798 void SAL_CALL
FmXGridControl::addContainerListener(const Reference
< XContainerListener
>& l
) throw( RuntimeException
, std::exception
)
800 m_aContainerListeners
.addInterface( l
);
801 if( getPeer().is() && m_aContainerListeners
.getLength() == 1 )
803 Reference
< XContainer
> xContainer(getPeer(), UNO_QUERY
);
804 xContainer
->addContainerListener( &m_aContainerListeners
);
809 void SAL_CALL
FmXGridControl::removeContainerListener(const Reference
< XContainerListener
>& l
) throw( RuntimeException
, std::exception
)
811 if( getPeer().is() && m_aContainerListeners
.getLength() == 1 )
813 Reference
< XContainer
> xContainer(getPeer(), UNO_QUERY
);
814 xContainer
->removeContainerListener( &m_aContainerListeners
);
816 m_aContainerListeners
.removeInterface( l
);
820 Reference
< ::com::sun::star::frame::XDispatch
> SAL_CALL
FmXGridControl::queryDispatch(const ::com::sun::star::util::URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) throw( RuntimeException
, std::exception
)
822 Reference
< ::com::sun::star::frame::XDispatchProvider
> xPeerProvider(getPeer(), UNO_QUERY
);
823 if (xPeerProvider
.is())
824 return xPeerProvider
->queryDispatch(aURL
, aTargetFrameName
, nSearchFlags
);
826 return Reference
< ::com::sun::star::frame::XDispatch
> ();
830 Sequence
< Reference
< ::com::sun::star::frame::XDispatch
> > SAL_CALL
FmXGridControl::queryDispatches(const Sequence
< ::com::sun::star::frame::DispatchDescriptor
>& aDescripts
) throw( RuntimeException
, std::exception
)
832 Reference
< ::com::sun::star::frame::XDispatchProvider
> xPeerProvider(getPeer(), UNO_QUERY
);
833 if (xPeerProvider
.is())
834 return xPeerProvider
->queryDispatches(aDescripts
);
836 return Sequence
< Reference
< ::com::sun::star::frame::XDispatch
> >();
840 void SAL_CALL
FmXGridControl::registerDispatchProviderInterceptor(const Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
>& _xInterceptor
) throw( RuntimeException
, std::exception
)
842 Reference
< ::com::sun::star::frame::XDispatchProviderInterception
> xPeerInterception(getPeer(), UNO_QUERY
);
843 if (xPeerInterception
.is())
844 xPeerInterception
->registerDispatchProviderInterceptor(_xInterceptor
);
848 void SAL_CALL
FmXGridControl::releaseDispatchProviderInterceptor(const Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
>& _xInterceptor
) throw( RuntimeException
, std::exception
)
850 Reference
< ::com::sun::star::frame::XDispatchProviderInterception
> xPeerInterception(getPeer(), UNO_QUERY
);
851 if (xPeerInterception
.is())
852 xPeerInterception
->releaseDispatchProviderInterceptor(_xInterceptor
);
856 void SAL_CALL
FmXGridControl::addGridControlListener( const Reference
< XGridControlListener
>& _listener
) throw( RuntimeException
, std::exception
)
858 ::osl::MutexGuard
aGuard( GetMutex() );
860 m_aGridControlListeners
.addInterface( _listener
);
861 if ( getPeer().is() && 1 == m_aGridControlListeners
.getLength() )
863 Reference
< XGridControl
> xPeerGrid( getPeer(), UNO_QUERY
);
864 if ( xPeerGrid
.is() )
865 xPeerGrid
->addGridControlListener( &m_aGridControlListeners
);
870 void SAL_CALL
FmXGridControl::removeGridControlListener( const Reference
< XGridControlListener
>& _listener
) throw( RuntimeException
, std::exception
)
872 ::osl::MutexGuard
aGuard( GetMutex() );
874 if( getPeer().is() && 1 == m_aGridControlListeners
.getLength() )
876 Reference
< XGridControl
> xPeerGrid( getPeer(), UNO_QUERY
);
877 if ( xPeerGrid
.is() )
878 xPeerGrid
->removeGridControlListener( &m_aGridControlListeners
);
881 m_aGridControlListeners
.removeInterface( _listener
);
885 sal_Int16 SAL_CALL
FmXGridControl::getCurrentColumnPosition() throw( RuntimeException
, std::exception
)
887 Reference
< XGridControl
> xGrid( getPeer(), UNO_QUERY
);
888 return xGrid
.is() ? xGrid
->getCurrentColumnPosition() : -1;
892 void SAL_CALL
FmXGridControl::setCurrentColumnPosition(sal_Int16 nPos
) throw( RuntimeException
, std::exception
)
894 Reference
< XGridControl
> xGrid( getPeer(), UNO_QUERY
);
897 SolarMutexGuard aGuard
;
898 xGrid
->setCurrentColumnPosition( nPos
);
904 sal_Bool SAL_CALL
FmXGridControl::hasElements() throw( RuntimeException
, std::exception
)
906 Reference
< XElementAccess
> xPeer(getPeer(), UNO_QUERY
);
907 return xPeer
.is() && xPeer
->hasElements();
911 Type SAL_CALL
FmXGridControl::getElementType( ) throw(RuntimeException
, std::exception
)
913 return cppu::UnoType
<com::sun::star::awt::XTextComponent
>::get();
916 // XEnumerationAccess
918 Reference
< XEnumeration
> SAL_CALL
FmXGridControl::createEnumeration() throw( RuntimeException
, std::exception
)
920 Reference
< XEnumerationAccess
> xPeer(getPeer(), UNO_QUERY
);
922 return xPeer
->createEnumeration();
924 return new ::comphelper::OEnumerationByIndex(this);
929 sal_Int32 SAL_CALL
FmXGridControl::getCount() throw( RuntimeException
, std::exception
)
931 Reference
< XIndexAccess
> xPeer(getPeer(), UNO_QUERY
);
932 return xPeer
.is() ? xPeer
->getCount() : 0;
936 Any SAL_CALL
FmXGridControl::getByIndex(sal_Int32 _nIndex
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
938 Reference
< XIndexAccess
> xPeer(getPeer(), UNO_QUERY
);
940 throw IndexOutOfBoundsException();
942 return xPeer
->getByIndex(_nIndex
);
945 // ::com::sun::star::util::XModeSelector
947 void SAL_CALL
FmXGridControl::setMode(const OUString
& Mode
) throw( NoSupportException
, RuntimeException
, std::exception
)
949 Reference
< ::com::sun::star::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
951 throw NoSupportException();
953 xPeer
->setMode(Mode
);
957 OUString SAL_CALL
FmXGridControl::getMode() throw( RuntimeException
, std::exception
)
959 Reference
< ::com::sun::star::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
960 return xPeer
.is() ? xPeer
->getMode() : OUString();
964 ::comphelper::StringSequence SAL_CALL
FmXGridControl::getSupportedModes() throw( RuntimeException
, std::exception
)
966 Reference
< ::com::sun::star::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
967 return xPeer
.is() ? xPeer
->getSupportedModes() : ::comphelper::StringSequence();
971 sal_Bool SAL_CALL
FmXGridControl::supportsMode(const OUString
& Mode
) throw( RuntimeException
, std::exception
)
973 Reference
< ::com::sun::star::util::XModeSelector
> xPeer(getPeer(), UNO_QUERY
);
974 return xPeer
.is() ? xPeer
->supportsMode(Mode
) : sal_False
;
977 // helper class which prevents that in the peer's header the FmGridListener must be known
978 class FmXGridPeer::GridListenerDelegator
: public FmGridListener
981 FmXGridPeer
* m_pPeer
;
984 GridListenerDelegator( FmXGridPeer
* _pPeer
);
985 virtual ~GridListenerDelegator();
988 virtual void selectionChanged() SAL_OVERRIDE
;
989 virtual void columnChanged() SAL_OVERRIDE
;
993 FmXGridPeer::GridListenerDelegator::GridListenerDelegator(FmXGridPeer
* _pPeer
)
996 DBG_ASSERT(m_pPeer
, "GridListenerDelegator::GridListenerDelegator");
999 FmXGridPeer::GridListenerDelegator::~GridListenerDelegator()
1004 void FmXGridPeer::GridListenerDelegator::selectionChanged()
1006 m_pPeer
->selectionChanged();
1010 void FmXGridPeer::GridListenerDelegator::columnChanged()
1012 m_pPeer
->columnChanged();
1015 void FmXGridPeer::selectionChanged()
1017 EventObject aSource
;
1018 aSource
.Source
= static_cast< ::cppu::OWeakObject
* >(this);
1019 m_aSelectionListeners
.notifyEach( &XSelectionChangeListener::selectionChanged
, aSource
);
1023 void FmXGridPeer::columnChanged()
1025 EventObject
aEvent( *this );
1026 m_aGridControlListeners
.notifyEach( &XGridControlListener::columnChanged
, aEvent
);
1032 const OUString
getDataModeIdentifier()
1034 return OUString("DataMode");
1037 using namespace fmgridif
;
1040 FmXGridPeer::FmXGridPeer(const Reference
< XComponentContext
>& _rxContext
)
1041 :m_aModifyListeners(m_aMutex
)
1042 ,m_aUpdateListeners(m_aMutex
)
1043 ,m_aContainerListeners(m_aMutex
)
1044 ,m_aSelectionListeners(m_aMutex
)
1045 ,m_aGridControlListeners(m_aMutex
)
1046 ,m_aMode( getDataModeIdentifier() )
1047 ,m_nCursorListening(0)
1048 ,m_bInterceptingDispatch(false)
1049 ,m_pStateCache(NULL
)
1050 ,m_pDispatchers(NULL
)
1051 ,m_pGridListener(NULL
)
1052 ,m_xContext(_rxContext
)
1054 // Create must be called after this constructure
1055 m_pGridListener
= new GridListenerDelegator( this );
1059 VclPtr
<FmGridControl
> FmXGridPeer::imp_CreateControl(vcl::Window
* pParent
, WinBits nStyle
)
1061 return VclPtr
<FmGridControl
>::Create(m_xContext
, pParent
, this, nStyle
);
1065 void FmXGridPeer::Create(vcl::Window
* pParent
, WinBits nStyle
)
1067 FmGridControl
* pWin
= imp_CreateControl(pParent
, nStyle
);
1068 DBG_ASSERT(pWin
!= NULL
, "FmXGridPeer::Create : imp_CreateControl didn't return a control !");
1070 pWin
->SetStateProvider(LINK(this, FmXGridPeer
, OnQueryGridSlotState
));
1071 pWin
->SetSlotExecutor(LINK(this, FmXGridPeer
, OnExecuteGridSlot
));
1073 // want to hear about row selections
1074 pWin
->setGridListener( m_pGridListener
);
1076 // Init must always be called
1078 pWin
->SetComponentInterface(this);
1084 FmXGridPeer::~FmXGridPeer()
1086 setRowSet(Reference
< XRowSet
> ());
1087 setColumns(Reference
< XIndexContainer
> ());
1089 delete m_pGridListener
;
1094 class theFmXGridPeerImplementationId
: public rtl::Static
< UnoTunnelIdInit
, theFmXGridPeerImplementationId
> {};
1097 const Sequence
< sal_Int8
>& FmXGridPeer::getUnoTunnelImplementationId() throw()
1099 return theFmXGridPeerImplementationId::get().getSeq();
1103 FmXGridPeer
* FmXGridPeer::getImplementation( const Reference
< XInterface
>& _rxIFace
) throw()
1105 FmXGridPeer
* pReturn
= NULL
;
1106 Reference
< XUnoTunnel
> xTunnel(_rxIFace
, UNO_QUERY
);
1108 pReturn
= reinterpret_cast<FmXGridPeer
*>(xTunnel
->getSomething(getUnoTunnelImplementationId()));
1114 sal_Int64 SAL_CALL
FmXGridPeer::getSomething( const Sequence
< sal_Int8
>& _rIdentifier
) throw(RuntimeException
, std::exception
)
1116 sal_Int64
nReturn(0);
1118 if ( (_rIdentifier
.getLength() == 16)
1119 && (0 == memcmp( getUnoTunnelImplementationId().getConstArray(), _rIdentifier
.getConstArray(), 16 ))
1122 nReturn
= reinterpret_cast<sal_Int64
>(this);
1125 nReturn
= VCLXWindow::getSomething(_rIdentifier
);
1132 void FmXGridPeer::disposing(const EventObject
& e
) throw( RuntimeException
, std::exception
)
1134 using namespace ::com::sun::star::util
;
1135 bool bKnownSender
= false;
1137 Reference
< XIndexContainer
> xCols( e
.Source
, UNO_QUERY
);
1140 setColumns(Reference
< XIndexContainer
> ());
1141 bKnownSender
= true;
1144 Reference
< XRowSet
> xCursor(e
.Source
, UNO_QUERY
);
1147 setRowSet( m_xCursor
);
1149 bKnownSender
= true;
1153 if ( !bKnownSender
&& m_pDispatchers
)
1155 const Sequence
< URL
>& aSupportedURLs
= getSupportedURLs();
1156 const URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
1157 for ( sal_uInt16 i
=0; i
< ( aSupportedURLs
.getLength() ) && !bKnownSender
; ++i
, ++pSupportedURLs
)
1159 if ( m_pDispatchers
[i
] == e
.Source
)
1161 m_pDispatchers
[i
]->removeStatusListener( static_cast< ::com::sun::star::frame::XStatusListener
* >( this ), *pSupportedURLs
);
1162 m_pDispatchers
[i
] = NULL
;
1163 m_pStateCache
[i
] = false;
1164 bKnownSender
= true;
1169 if ( !bKnownSender
)
1170 VCLXWindow::disposing(e
);
1174 void FmXGridPeer::addModifyListener(const Reference
< ::com::sun::star::util::XModifyListener
>& l
) throw( RuntimeException
, std::exception
)
1176 m_aModifyListeners
.addInterface( l
);
1180 void FmXGridPeer::removeModifyListener(const Reference
< ::com::sun::star::util::XModifyListener
>& l
) throw( RuntimeException
, std::exception
)
1182 m_aModifyListeners
.removeInterface( l
);
1186 #define LAST_KNOWN_TYPE FormComponentType::PATTERNFIELD
1187 Sequence
< sal_Bool
> SAL_CALL
FmXGridPeer::queryFieldDataType( const Type
& xType
) throw(RuntimeException
, std::exception
)
1189 // eine 'Konvertierungstabelle'
1190 static const sal_Bool bCanConvert
[LAST_KNOWN_TYPE
][4] =
1192 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::CONTROL
1193 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::COMMANDBUTTON
1194 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::RADIOBUTTON
1195 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::IMAGEBUTTON
1196 { sal_False
, sal_False
, sal_False
, sal_True
}, // FormComponentType::CHECKBOX
1197 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::LISTBOX
1198 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::COMBOBOX
1199 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::GROUPBOX
1200 { sal_True
, sal_False
, sal_False
, sal_False
}, // FormComponentType::TEXTFIELD
1201 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::FIXEDTEXT
1202 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::GRIDCONTROL
1203 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::FILECONTROL
1204 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::HIDDENCONTROL
1205 { sal_False
, sal_False
, sal_False
, sal_False
}, // FormComponentType::IMAGECONTROL
1206 { sal_True
, sal_True
, sal_True
, sal_False
}, // FormComponentType::DATEFIELD
1207 { sal_True
, sal_True
, sal_False
, sal_False
}, // FormComponentType::TIMEFIELD
1208 { sal_True
, sal_True
, sal_False
, sal_False
}, // FormComponentType::NUMERICFIELD
1209 { sal_True
, sal_True
, sal_False
, sal_False
}, // FormComponentType::CURRENCYFIELD
1210 { sal_True
, sal_False
, sal_False
, sal_False
} // FormComponentType::PATTERNFIELD
1214 sal_Int16 nMapColumn
= -1;
1215 switch (xType
.getTypeClass())
1217 case TypeClass_STRING
: nMapColumn
= 0; break;
1218 case TypeClass_FLOAT
:
1219 case TypeClass_DOUBLE
: nMapColumn
= 1; break;
1220 case TypeClass_SHORT
:
1221 case TypeClass_LONG
:
1222 case TypeClass_UNSIGNED_LONG
:
1223 case TypeClass_UNSIGNED_SHORT
: nMapColumn
= 2; break;
1224 case TypeClass_BOOLEAN
: nMapColumn
= 3; break;
1229 Reference
< XIndexContainer
> xColumns
= getColumns();
1231 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1232 sal_Int32 nColumns
= pGrid
->GetViewColCount();
1234 DbGridColumns aColumns
= pGrid
->GetColumns();
1236 Sequence
<sal_Bool
> aReturnSequence(nColumns
);
1237 sal_Bool
* pReturnArray
= aReturnSequence
.getArray();
1239 bool bRequestedAsAny
= (xType
.getTypeClass() == TypeClass_ANY
);
1242 Reference
< ::com::sun::star::sdb::XColumn
> xFieldContent
;
1243 Reference
< XPropertySet
> xCurrentColumn
;
1244 for (sal_Int32 i
=0; i
<nColumns
; ++i
)
1246 if (bRequestedAsAny
)
1248 pReturnArray
[i
] = sal_True
;
1252 pReturnArray
[i
] = sal_False
;
1254 sal_uInt16 nModelPos
= pGrid
->GetModelColumnPos(pGrid
->GetColumnIdFromViewPos((sal_uInt16
)i
));
1255 DBG_ASSERT(nModelPos
!= (sal_uInt16
)-1, "FmXGridPeer::queryFieldDataType : no model pos !");
1257 pCol
= aColumns
[ nModelPos
];
1258 const DbGridRowRef xRow
= pGrid
->GetSeekRow();
1259 xFieldContent
= (xRow
.Is() && xRow
->HasField(pCol
->GetFieldPos())) ? xRow
->GetField(pCol
->GetFieldPos()).getColumn() : Reference
< ::com::sun::star::sdb::XColumn
> ();
1260 if (!xFieldContent
.is())
1261 // can't supply anything without a field content
1262 // FS - 07.12.99 - 54391
1265 xColumns
->getByIndex(nModelPos
) >>= xCurrentColumn
;
1266 if (!::comphelper::hasProperty(FM_PROP_CLASSID
, xCurrentColumn
))
1269 sal_Int16 nClassId
= sal_Int16();
1270 xCurrentColumn
->getPropertyValue(FM_PROP_CLASSID
) >>= nClassId
;
1271 if (nClassId
>LAST_KNOWN_TYPE
)
1273 DBG_ASSERT(nClassId
>0, "FmXGridPeer::queryFieldDataType : somebody changed the definition of the FormComponentType enum !");
1275 if (nMapColumn
!= -1)
1276 pReturnArray
[i
] = bCanConvert
[nClassId
-1][nMapColumn
];
1279 return aReturnSequence
;
1283 Sequence
< Any
> SAL_CALL
FmXGridPeer::queryFieldData( sal_Int32 nRow
, const Type
& xType
) throw(RuntimeException
, std::exception
)
1285 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1286 DBG_ASSERT(pGrid
&& pGrid
->IsOpen(), "FmXGridPeer::queryFieldData : have no valid grid window !");
1287 if (!pGrid
|| !pGrid
->IsOpen())
1288 return Sequence
< Any
>();
1290 // das Control zur angegebenen Row fahren
1291 if (!pGrid
->SeekRow(nRow
))
1293 throw IllegalArgumentException();
1296 // don't use GetCurrentRow as this isn't affected by the above SeekRow
1297 // FS - 30.09.99 - 68644
1298 DbGridRowRef xPaintRow
= pGrid
->GetPaintRow();
1299 ENSURE_OR_THROW( xPaintRow
.Is(), "invalid paint row" );
1301 // I need the columns of the control for GetFieldText
1302 DbGridColumns aColumns
= pGrid
->GetColumns();
1304 // und durch alle Spalten durch
1305 sal_Int32 nColumnCount
= pGrid
->GetViewColCount();
1307 Sequence
< Any
> aReturnSequence(nColumnCount
);
1308 Any
* pReturnArray
= aReturnSequence
.getArray();
1310 bool bRequestedAsAny
= (xType
.getTypeClass() == TypeClass_ANY
);
1311 Reference
< ::com::sun::star::sdb::XColumn
> xFieldContent
;
1312 for (sal_Int32 i
=0; i
< nColumnCount
; ++i
)
1314 sal_uInt16 nModelPos
= pGrid
->GetModelColumnPos(pGrid
->GetColumnIdFromViewPos((sal_uInt16
)i
));
1315 DBG_ASSERT(nModelPos
!= (sal_uInt16
)-1, "FmXGridPeer::queryFieldData : invalid model pos !");
1317 // don't use GetCurrentFieldValue to determine the field content as this isn't affected by the above SeekRow
1318 // FS - 30.09.99 - 68644
1319 DbGridColumn
* pCol
= aColumns
[ nModelPos
];
1320 xFieldContent
= xPaintRow
->HasField( pCol
->GetFieldPos() )
1321 ? xPaintRow
->GetField( pCol
->GetFieldPos() ).getColumn()
1322 : Reference
< XColumn
> ();
1324 if ( !xFieldContent
.is() )
1327 if (bRequestedAsAny
)
1329 Reference
< XPropertySet
> xFieldSet(xFieldContent
, UNO_QUERY
);
1330 pReturnArray
[i
] = xFieldSet
->getPropertyValue(FM_PROP_VALUE
);
1334 switch (xType
.getTypeClass())
1336 // Strings are dealt with directly by the GetFieldText
1337 case TypeClass_STRING
:
1339 OUString sText
= aColumns
[ nModelPos
]->GetCellText( xPaintRow
, pGrid
->getNumberFormatter() );
1340 pReturnArray
[i
] <<= sText
;
1343 // everything else is requested in the DatabaseVariant
1344 case TypeClass_FLOAT
: pReturnArray
[i
] <<= xFieldContent
->getFloat(); break;
1345 case TypeClass_DOUBLE
: pReturnArray
[i
] <<= xFieldContent
->getDouble(); break;
1346 case TypeClass_SHORT
: pReturnArray
[i
] <<= (sal_Int16
)xFieldContent
->getShort(); break;
1347 case TypeClass_LONG
: pReturnArray
[i
] <<= (sal_Int32
)xFieldContent
->getLong(); break;
1348 case TypeClass_UNSIGNED_SHORT
: pReturnArray
[i
] <<= (sal_uInt16
)xFieldContent
->getShort(); break;
1349 case TypeClass_UNSIGNED_LONG
: pReturnArray
[i
] <<= (sal_uInt32
)xFieldContent
->getLong(); break;
1350 case TypeClass_BOOLEAN
: ::comphelper::setBOOL(pReturnArray
[i
],xFieldContent
->getBoolean()); break;
1353 throw IllegalArgumentException();
1358 return aReturnSequence
;
1362 void FmXGridPeer::CellModified()
1365 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >(this);
1366 m_aModifyListeners
.notifyEach( &XModifyListener::modified
, aEvt
);
1369 // XPropertyChangeListener
1371 void FmXGridPeer::propertyChange(const PropertyChangeEvent
& evt
) throw( RuntimeException
, std::exception
)
1373 SolarMutexGuard aGuard
;
1374 // want to do a lot of VCL stuff here ...
1375 // this should not be (deadlock) critical, as by definition, every component should release
1376 // any own mutexes before notifying
1378 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1383 Reference
< XRowSet
> xCursor(evt
.Source
, UNO_QUERY
);
1384 if (evt
.PropertyName
== FM_PROP_VALUE
|| m_xCursor
== evt
.Source
)
1385 pGrid
->propertyChange(evt
);
1386 else if (pGrid
&& m_xColumns
.is() && m_xColumns
->hasElements())
1388 // next find which column has changed
1389 ::comphelper::InterfaceRef xCurrent
;
1392 for ( i
= 0; i
< m_xColumns
->getCount(); i
++)
1394 xCurrent
.set(m_xColumns
->getByIndex(i
), css::uno::UNO_QUERY
);
1395 if (evt
.Source
== xCurrent
)
1399 if (i
>= m_xColumns
->getCount())
1400 // this is valid because we are listening at the cursor, too (RecordCount, -status, edit mode)
1403 sal_uInt16 nId
= pGrid
->GetColumnIdFromModelPos((sal_uInt16
)i
);
1404 bool bInvalidateColumn
= false;
1406 if (evt
.PropertyName
== FM_PROP_LABEL
)
1408 OUString aName
= ::comphelper::getString(evt
.NewValue
);
1409 if (aName
!= pGrid
->GetColumnTitle(nId
))
1410 pGrid
->SetColumnTitle(nId
, aName
);
1412 else if (evt
.PropertyName
== FM_PROP_WIDTH
)
1414 sal_Int32 nWidth
= 0;
1415 if (evt
.NewValue
.getValueType().getTypeClass() == TypeClass_VOID
)
1416 nWidth
= pGrid
->GetDefaultColumnWidth(pGrid
->GetColumnTitle(nId
));
1417 // GetDefaultColumnWidth already considered the zoom factor
1420 sal_Int32 nTest
= 0;
1421 if (evt
.NewValue
>>= nTest
)
1423 nWidth
= pGrid
->LogicToPixel(Point(nTest
,0),MAP_10TH_MM
).X();
1424 // take the zoom factor into account
1425 nWidth
= pGrid
->CalcZoom(nWidth
);
1428 if (nWidth
!= (sal_Int32(pGrid
->GetColumnWidth(nId
))))
1430 if (pGrid
->IsEditing())
1432 pGrid
->DeactivateCell();
1433 pGrid
->ActivateCell();
1435 pGrid
->SetColumnWidth(nId
, nWidth
);
1438 else if (evt
.PropertyName
== FM_PROP_HIDDEN
)
1440 DBG_ASSERT(evt
.NewValue
.getValueType().getTypeClass() == TypeClass_BOOLEAN
,
1441 "FmXGridPeer::propertyChange : the property 'hidden' should be of type boolean !");
1442 if (::comphelper::getBOOL(evt
.NewValue
))
1443 pGrid
->HideColumn(nId
);
1445 pGrid
->ShowColumn(nId
);
1447 else if (evt
.PropertyName
== FM_PROP_ALIGN
)
1449 // in design mode it doesn't matter
1450 if (!isDesignMode())
1452 DbGridColumn
* pCol
= pGrid
->GetColumns().at( i
);
1454 pCol
->SetAlignmentFromModel(-1);
1455 bInvalidateColumn
= true;
1458 else if (evt
.PropertyName
== FM_PROP_FORMATKEY
)
1460 if (!isDesignMode())
1461 bInvalidateColumn
= true;
1464 // need to invalidate the affected column ?
1465 if (bInvalidateColumn
)
1467 bool bWasEditing
= pGrid
->IsEditing();
1469 pGrid
->DeactivateCell();
1471 ::Rectangle aColRect
= pGrid
->GetFieldRect(nId
);
1473 aColRect
.Bottom() = pGrid
->GetSizePixel().Height();
1474 pGrid
->Invalidate(aColRect
);
1477 pGrid
->ActivateCell();
1484 void FmXGridPeer::addUpdateListener(const Reference
< XUpdateListener
>& l
) throw( RuntimeException
, std::exception
)
1486 m_aUpdateListeners
.addInterface(l
);
1490 void FmXGridPeer::removeUpdateListener(const Reference
< XUpdateListener
>& l
) throw( RuntimeException
, std::exception
)
1492 m_aUpdateListeners
.removeInterface(l
);
1496 sal_Bool
FmXGridPeer::commit() throw( RuntimeException
, std::exception
)
1498 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1499 if (!m_xCursor
.is() || !pGrid
)
1502 EventObject
aEvt(static_cast< ::cppu::OWeakObject
* >(this));
1503 ::cppu::OInterfaceIteratorHelper
aIter(m_aUpdateListeners
);
1504 bool bCancel
= false;
1505 while (aIter
.hasMoreElements() && !bCancel
)
1506 if ( !static_cast< XUpdateListener
* >( aIter
.next() )->approveUpdate( aEvt
) )
1510 bCancel
= !pGrid
->commit();
1513 m_aUpdateListeners
.notifyEach( &XUpdateListener::updated
, aEvt
);
1519 void FmXGridPeer::cursorMoved(const EventObject
& _rEvent
) throw( RuntimeException
, std::exception
)
1521 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1522 // we are not interested in move to insert row only in the resetted event
1523 // which is fired after positioning an the insert row
1524 if (pGrid
&& pGrid
->IsOpen() && !::comphelper::getBOOL(Reference
< XPropertySet
> (_rEvent
.Source
, UNO_QUERY
)->getPropertyValue(FM_PROP_ISNEW
)))
1525 pGrid
->positioned(_rEvent
);
1529 void FmXGridPeer::rowChanged(const EventObject
& _rEvent
) throw( RuntimeException
, std::exception
)
1531 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1532 if (pGrid
&& pGrid
->IsOpen())
1534 if (m_xCursor
->rowUpdated() && !pGrid
->IsCurrentAppending())
1535 pGrid
->RowModified(pGrid
->GetCurrentPos());
1536 else if (m_xCursor
->rowInserted())
1537 pGrid
->inserted(_rEvent
);
1542 void FmXGridPeer::rowSetChanged(const EventObject
& /*event*/) throw( RuntimeException
, std::exception
)
1544 // not interested in ...
1545 // (our parent is a form which means we get a loaded or reloaded after this rowSetChanged)
1550 void FmXGridPeer::loaded(const EventObject
& /*rEvent*/) throw( RuntimeException
, std::exception
)
1552 updateGrid(m_xCursor
);
1556 void FmXGridPeer::unloaded(const EventObject
& /*rEvent*/) throw( RuntimeException
, std::exception
)
1558 updateGrid( Reference
< XRowSet
> (NULL
) );
1562 void FmXGridPeer::reloading(const EventObject
& /*aEvent*/) throw( RuntimeException
, std::exception
)
1565 updateGrid( Reference
< XRowSet
> (NULL
) );
1569 void FmXGridPeer::unloading(const EventObject
& /*aEvent*/) throw( RuntimeException
, std::exception
)
1572 updateGrid( Reference
< XRowSet
> (NULL
) );
1576 void FmXGridPeer::reloaded(const EventObject
& /*aEvent*/) throw( RuntimeException
, std::exception
)
1578 updateGrid(m_xCursor
);
1583 Reference
< XIndexContainer
> FmXGridPeer::getColumns() throw( RuntimeException
, std::exception
)
1589 void FmXGridPeer::addColumnListeners(const Reference
< XPropertySet
>& xCol
)
1591 static const OUString aPropsListenedTo
[] =
1593 OUString(FM_PROP_LABEL
), OUString(FM_PROP_WIDTH
), OUString(FM_PROP_HIDDEN
), OUString(FM_PROP_ALIGN
), OUString(FM_PROP_FORMATKEY
)
1596 // as not all properties have to be supported by all columns we have to check this
1597 // before adding a listener
1598 Reference
< XPropertySetInfo
> xInfo
= xCol
->getPropertySetInfo();
1600 const OUString
* pProps
= aPropsListenedTo
;
1601 const OUString
* pPropsEnd
= pProps
+ sizeof( aPropsListenedTo
) / sizeof( aPropsListenedTo
[ 0 ] );
1602 for (; pProps
!= pPropsEnd
; ++pProps
)
1604 if ( xInfo
->hasPropertyByName( *pProps
) )
1606 aPropDesc
= xInfo
->getPropertyByName( *pProps
);
1607 if ( 0 != ( aPropDesc
.Attributes
& PropertyAttribute::BOUND
) )
1608 xCol
->addPropertyChangeListener( *pProps
, this );
1614 void FmXGridPeer::removeColumnListeners(const Reference
< XPropertySet
>& xCol
)
1616 // the same props as in addColumnListeners ... linux has problems with global static UStrings, so
1617 // we have to do it this way ....
1618 static OUString aPropsListenedTo
[] =
1620 OUString(FM_PROP_LABEL
), OUString(FM_PROP_WIDTH
), OUString(FM_PROP_HIDDEN
), OUString(FM_PROP_ALIGN
), OUString(FM_PROP_FORMATKEY
)
1623 Reference
< XPropertySetInfo
> xInfo
= xCol
->getPropertySetInfo();
1624 for (sal_uInt16 i
=0; i
<sizeof(aPropsListenedTo
)/sizeof(aPropsListenedTo
[0]); ++i
)
1625 if (xInfo
->hasPropertyByName(aPropsListenedTo
[i
]))
1626 xCol
->removePropertyChangeListener(aPropsListenedTo
[i
], this);
1630 void FmXGridPeer::setColumns(const Reference
< XIndexContainer
>& Columns
) throw( RuntimeException
, std::exception
)
1632 SolarMutexGuard aGuard
;
1634 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1636 if (m_xColumns
.is())
1638 Reference
< XPropertySet
> xCol
;
1639 for (sal_Int32 i
= 0; i
< m_xColumns
->getCount(); i
++)
1641 xCol
.set(m_xColumns
->getByIndex(i
), css::uno::UNO_QUERY
);
1642 removeColumnListeners(xCol
);
1644 Reference
< XContainer
> xContainer(m_xColumns
, UNO_QUERY
);
1645 xContainer
->removeContainerListener(this);
1647 Reference
< XSelectionSupplier
> xSelSupplier(m_xColumns
, UNO_QUERY
);
1648 xSelSupplier
->removeSelectionChangeListener(this);
1650 Reference
< XReset
> xColumnReset(m_xColumns
, UNO_QUERY
);
1651 if (xColumnReset
.is())
1652 xColumnReset
->removeResetListener((XResetListener
*)this);
1656 Reference
< XContainer
> xContainer(Columns
, UNO_QUERY
);
1657 xContainer
->addContainerListener(this);
1659 Reference
< XSelectionSupplier
> xSelSupplier(Columns
, UNO_QUERY
);
1660 xSelSupplier
->addSelectionChangeListener(this);
1662 Reference
< XPropertySet
> xCol
;
1663 for (sal_Int32 i
= 0; i
< Columns
->getCount(); i
++)
1665 xCol
.set(Columns
->getByIndex(i
), css::uno::UNO_QUERY
);
1666 addColumnListeners(xCol
);
1669 Reference
< XReset
> xColumnReset(Columns
, UNO_QUERY
);
1670 if (xColumnReset
.is())
1671 xColumnReset
->addResetListener((XResetListener
*)this);
1673 m_xColumns
= Columns
;
1676 pGrid
->InitColumnsByModels(m_xColumns
);
1678 if (m_xColumns
.is())
1680 EventObject
aEvt(m_xColumns
);
1681 selectionChanged(aEvt
);
1687 void FmXGridPeer::setDesignMode(sal_Bool bOn
) throw( RuntimeException
, std::exception
)
1689 if (bOn
!= isDesignMode())
1691 vcl::Window
* pWin
= GetWindow();
1693 static_cast<FmGridControl
*>(pWin
)->SetDesignMode(bOn
);
1699 DisConnectFromDispatcher();
1701 UpdateDispatches(); // will connect if not already connected and just update else
1705 sal_Bool
FmXGridPeer::isDesignMode() throw( RuntimeException
, std::exception
)
1707 vcl::Window
* pWin
= GetWindow();
1709 return static_cast<FmGridControl
*>(pWin
)->IsDesignMode();
1715 void FmXGridPeer::elementInserted(const ContainerEvent
& evt
) throw( RuntimeException
, std::exception
)
1717 SolarMutexGuard aGuard
;
1719 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1720 // Handle Column beruecksichtigen
1721 if (!pGrid
|| !m_xColumns
.is() || pGrid
->IsInColumnMove() || m_xColumns
->getCount() == ((sal_Int32
)pGrid
->GetModelColCount()))
1724 Reference
< XPropertySet
> xSet(evt
.Element
, css::uno::UNO_QUERY
);
1725 addColumnListeners(xSet
);
1727 Reference
< XPropertySet
> xNewColumn(xSet
);
1728 OUString aName
= ::comphelper::getString(xNewColumn
->getPropertyValue(FM_PROP_LABEL
));
1729 Any aWidth
= xNewColumn
->getPropertyValue(FM_PROP_WIDTH
);
1730 sal_Int32 nWidth
= 0;
1731 if (aWidth
>>= nWidth
)
1732 nWidth
= pGrid
->LogicToPixel(Point(nWidth
,0),MAP_10TH_MM
).X();
1734 pGrid
->AppendColumn(aName
, (sal_uInt16
)nWidth
, (sal_Int16
)::comphelper::getINT32(evt
.Accessor
));
1736 // jetzt die Spalte setzen
1737 DbGridColumn
* pCol
= pGrid
->GetColumns().at( ::comphelper::getINT32(evt
.Accessor
) );
1738 pCol
->setModel(xNewColumn
);
1740 Any aHidden
= xNewColumn
->getPropertyValue(FM_PROP_HIDDEN
);
1741 if (::comphelper::getBOOL(aHidden
))
1742 pGrid
->HideColumn(pCol
->GetId());
1744 FormControlFactory( m_xContext
).initializeTextFieldLineEnds( xNewColumn
);
1748 void FmXGridPeer::elementReplaced(const ContainerEvent
& evt
) throw( RuntimeException
, std::exception
)
1750 SolarMutexGuard aGuard
;
1752 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1754 // Handle Column beruecksichtigen
1755 if (!pGrid
|| !m_xColumns
.is() || pGrid
->IsInColumnMove())
1758 Reference
< XPropertySet
> xNewColumn(evt
.Element
, css::uno::UNO_QUERY
);
1759 Reference
< XPropertySet
> xOldColumn(
1760 evt
.ReplacedElement
, css::uno::UNO_QUERY
);
1762 bool bWasEditing
= pGrid
->IsEditing();
1764 pGrid
->DeactivateCell();
1766 pGrid
->RemoveColumn(pGrid
->GetColumnIdFromModelPos((sal_uInt16
)::comphelper::getINT32(evt
.Accessor
)));
1768 removeColumnListeners(xOldColumn
);
1769 addColumnListeners(xNewColumn
);
1771 OUString aName
= ::comphelper::getString(xNewColumn
->getPropertyValue(FM_PROP_LABEL
));
1772 Any aWidth
= xNewColumn
->getPropertyValue(FM_PROP_WIDTH
);
1773 sal_Int32 nWidth
= 0;
1774 if (aWidth
>>= nWidth
)
1775 nWidth
= pGrid
->LogicToPixel(Point(nWidth
,0),MAP_10TH_MM
).X();
1776 sal_uInt16 nNewId
= pGrid
->AppendColumn(aName
, (sal_uInt16
)nWidth
, (sal_Int16
)::comphelper::getINT32(evt
.Accessor
));
1777 sal_uInt16 nNewPos
= pGrid
->GetModelColumnPos(nNewId
);
1779 // set the model of the new column
1780 DbGridColumn
* pCol
= pGrid
->GetColumns().at( nNewPos
);
1782 // for initializong this grid column, we need the fields of the grid's data source
1783 Reference
< XColumnsSupplier
> xSuppColumns
;
1784 CursorWrapper
* pGridDataSource
= pGrid
->getDataSource();
1785 if ( pGridDataSource
)
1786 xSuppColumns
.set(Reference
< XInterface
>( *pGridDataSource
), css::uno::UNO_QUERY
);
1787 Reference
< XNameAccess
> xColumnsByName
;
1788 if ( xSuppColumns
.is() )
1789 xColumnsByName
= xSuppColumns
->getColumns();
1790 Reference
< XIndexAccess
> xColumnsByIndex( xColumnsByName
, UNO_QUERY
);
1792 if ( xColumnsByIndex
.is() )
1793 FmGridControl::InitColumnByField( pCol
, xNewColumn
, xColumnsByName
, xColumnsByIndex
);
1795 // the simple version, applies when the grid is not yet connected to a data source
1796 pCol
->setModel(xNewColumn
);
1799 pGrid
->ActivateCell();
1803 void FmXGridPeer::elementRemoved(const ContainerEvent
& evt
) throw( RuntimeException
, std::exception
)
1805 SolarMutexGuard aGuard
;
1807 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1809 // Handle Column beruecksichtigen
1810 if (!pGrid
|| !m_xColumns
.is() || pGrid
->IsInColumnMove() || m_xColumns
->getCount() == ((sal_Int32
)pGrid
->GetModelColCount()))
1813 pGrid
->RemoveColumn(pGrid
->GetColumnIdFromModelPos((sal_uInt16
)::comphelper::getINT32(evt
.Accessor
)));
1815 Reference
< XPropertySet
> xOldColumn(evt
.Element
, css::uno::UNO_QUERY
);
1816 removeColumnListeners(xOldColumn
);
1820 void FmXGridPeer::setProperty( const OUString
& PropertyName
, const Any
& Value
) throw( RuntimeException
, std::exception
)
1822 SolarMutexGuard aGuard
;
1824 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
1826 bool bVoid
= !Value
.hasValue();
1828 if ( PropertyName
== FM_PROP_TEXTLINECOLOR
)
1830 ::Color
aTextLineColor( bVoid
? COL_TRANSPARENT
: ::comphelper::getINT32( Value
) );
1833 pGrid
->SetTextLineColor();
1834 pGrid
->GetDataWindow().SetTextLineColor();
1838 pGrid
->SetTextLineColor(aTextLineColor
);
1839 pGrid
->GetDataWindow().SetTextLineColor(aTextLineColor
);
1842 // need to forward this to the columns
1843 DbGridColumns
& rColumns
= const_cast<DbGridColumns
&>(pGrid
->GetColumns());
1844 for ( size_t i
= 0, n
= rColumns
.size(); i
< n
; ++i
)
1846 DbGridColumn
* pLoop
= rColumns
[ i
];
1847 FmXGridCell
* pXCell
= pLoop
->GetCell();
1851 pXCell
->SetTextLineColor();
1853 pXCell
->SetTextLineColor(aTextLineColor
);
1858 pGrid
->Invalidate();
1860 else if ( PropertyName
== FM_PROP_FONTEMPHASISMARK
)
1862 vcl::Font aGridFont
= pGrid
->GetControlFont();
1863 sal_Int16 nValue
= ::comphelper::getINT16(Value
);
1864 aGridFont
.SetEmphasisMark( nValue
);
1865 pGrid
->SetControlFont( aGridFont
);
1867 else if ( PropertyName
== FM_PROP_FONTRELIEF
)
1869 vcl::Font aGridFont
= pGrid
->GetControlFont();
1870 sal_Int16 nValue
= ::comphelper::getINT16(Value
);
1871 aGridFont
.SetRelief( (FontRelief
)nValue
);
1872 pGrid
->SetControlFont( aGridFont
);
1874 else if ( PropertyName
== FM_PROP_HELPURL
)
1877 OSL_VERIFY( Value
>>= sHelpURL
);
1878 INetURLObject
aHID( sHelpURL
);
1879 if ( aHID
.GetProtocol() == INetProtocol::Hid
)
1880 sHelpURL
= aHID
.GetURLPath();
1881 pGrid
->SetHelpId( OUStringToOString( sHelpURL
, RTL_TEXTENCODING_UTF8
) );
1883 else if ( PropertyName
== FM_PROP_DISPLAYSYNCHRON
)
1885 pGrid
->setDisplaySynchron(::comphelper::getBOOL(Value
));
1887 else if ( PropertyName
== FM_PROP_CURSORCOLOR
)
1890 pGrid
->SetCursorColor(COL_TRANSPARENT
);
1892 pGrid
->SetCursorColor( ::Color(::comphelper::getINT32(Value
)));
1894 pGrid
->Invalidate();
1896 else if ( PropertyName
== FM_PROP_ALWAYSSHOWCURSOR
)
1898 pGrid
->EnablePermanentCursor(::comphelper::getBOOL(Value
));
1900 pGrid
->Invalidate();
1902 else if ( PropertyName
== FM_PROP_FONT
)
1905 pGrid
->SetControlFont( vcl::Font() );
1908 ::com::sun::star::awt::FontDescriptor aFont
;
1909 if (Value
>>= aFont
)
1911 vcl::Font aNewVclFont
;
1912 if (::comphelper::operator!=(aFont
, ::comphelper::getDefaultFont())) // ist das der Default
1913 aNewVclFont
= ImplCreateFont( aFont
);
1915 // need to add relief and emphasis (they're stored in a VCL-Font, but not in a FontDescriptor
1916 vcl::Font aOldVclFont
= pGrid
->GetControlFont();
1917 aNewVclFont
.SetRelief( aOldVclFont
.GetRelief() );
1918 aNewVclFont
.SetEmphasisMark( aOldVclFont
.GetEmphasisMark() );
1921 pGrid
->SetControlFont( aNewVclFont
);
1923 // if our row-height property is void (which means "calculate it font-dependent") we have
1924 // to adjust the control's row height
1925 Reference
< XPropertySet
> xModelSet(getColumns(), UNO_QUERY
);
1926 if (xModelSet
.is() && ::comphelper::hasProperty(FM_PROP_ROWHEIGHT
, xModelSet
))
1928 Any aHeight
= xModelSet
->getPropertyValue(FM_PROP_ROWHEIGHT
);
1929 if (!aHeight
.hasValue())
1930 pGrid
->SetDataRowHeight(0);
1936 else if ( PropertyName
== FM_PROP_BACKGROUNDCOLOR
)
1940 pGrid
->SetControlBackground();
1944 ::Color
aColor( ::comphelper::getINT32(Value
) );
1945 pGrid
->SetBackground( aColor
);
1946 pGrid
->SetControlBackground( aColor
);
1949 else if ( PropertyName
== FM_PROP_TEXTCOLOR
)
1953 pGrid
->SetControlForeground();
1957 ::Color
aColor( ::comphelper::getINT32(Value
) );
1958 pGrid
->SetTextColor( aColor
);
1959 pGrid
->SetControlForeground( aColor
);
1962 else if ( PropertyName
== FM_PROP_ROWHEIGHT
)
1964 sal_Int32
nLogHeight(0);
1965 if (Value
>>= nLogHeight
)
1967 sal_Int32 nHeight
= pGrid
->LogicToPixel(Point(0,nLogHeight
),MAP_10TH_MM
).Y();
1968 // take the zoom factor into account
1969 nHeight
= pGrid
->CalcZoom(nHeight
);
1970 pGrid
->SetDataRowHeight(nHeight
);
1973 pGrid
->SetDataRowHeight(0);
1975 else if ( PropertyName
== FM_PROP_HASNAVIGATION
)
1977 bool bValue( true );
1978 OSL_VERIFY( Value
>>= bValue
);
1979 pGrid
->EnableNavigationBar( bValue
);
1981 else if ( PropertyName
== FM_PROP_RECORDMARKER
)
1983 bool bValue( true );
1984 OSL_VERIFY( Value
>>= bValue
);
1985 pGrid
->EnableHandle( bValue
);
1987 else if ( PropertyName
== FM_PROP_ENABLED
)
1989 bool bValue( true );
1990 OSL_VERIFY( Value
>>= bValue
);
1992 // In design mode, disable only the data window.
1993 // Else the control cannot be configured anymore.
1995 pGrid
->GetDataWindow().Enable( bValue
);
1997 pGrid
->Enable( bValue
);
2000 VCLXWindow::setProperty( PropertyName
, Value
);
2004 Reference
< XAccessibleContext
> FmXGridPeer::CreateAccessibleContext()
2006 Reference
< XAccessibleContext
> xContext
;
2008 // use the AccessibleContext provided by the VCL window
2009 vcl::Window
* pGrid
= GetWindow();
2012 Reference
< XAccessible
> xAcc( pGrid
->GetAccessible( true ) );
2014 xContext
= xAcc
->getAccessibleContext();
2015 // TODO: this has a slight conceptual problem:
2017 // We know that the XAccessible and XAccessibleContext implementation of the browse
2018 // box is the same (the class implements both interfaces), which, speaking strictly,
2019 // is bad here (means when a browse box acts as UnoControl): We (the FmXGridPeer) are
2020 // the XAccessible here, and the browse box should be able to provide us an XAccessibleContext,
2021 // but it should _not_ be the XAccessible itself.
2022 // However, as long as no client implementation uses dirty hacks such as querying an
2023 // XAccessibleContext for XAccessible, this should not be a problem.
2026 if ( !xContext
.is() )
2027 xContext
= VCLXWindow::CreateAccessibleContext( );
2033 Any
FmXGridPeer::getProperty( const OUString
& _rPropertyName
) throw( RuntimeException
, std::exception
)
2038 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2039 vcl::Window
* pDataWindow
= &pGrid
->GetDataWindow();
2041 if ( _rPropertyName
== FM_PROP_NAME
)
2043 vcl::Font aFont
= pDataWindow
->GetControlFont();
2044 aProp
<<= ImplCreateFontDescriptor( aFont
);
2046 else if ( _rPropertyName
== FM_PROP_TEXTCOLOR
)
2048 aProp
<<= (sal_Int32
)pDataWindow
->GetControlForeground().GetColor();
2050 else if ( _rPropertyName
== FM_PROP_BACKGROUNDCOLOR
)
2052 aProp
<<= (sal_Int32
)pDataWindow
->GetControlBackground().GetColor();
2054 else if ( _rPropertyName
== FM_PROP_ROWHEIGHT
)
2056 sal_Int32 nPixelHeight
= pGrid
->GetDataRowHeight();
2057 // take the zoom factor into account
2058 nPixelHeight
= pGrid
->CalcReverseZoom(nPixelHeight
);
2059 aProp
<<= (sal_Int32
)pGrid
->PixelToLogic(Point(0,nPixelHeight
),MAP_10TH_MM
).Y();
2061 else if ( _rPropertyName
== FM_PROP_HASNAVIGATION
)
2063 bool bHasNavBar
= pGrid
->HasNavigationBar();
2064 aProp
<<= bHasNavBar
;
2066 else if ( _rPropertyName
== FM_PROP_RECORDMARKER
)
2068 bool bHasHandle
= pGrid
->HasHandle();
2069 aProp
<<= bHasHandle
;
2071 else if ( _rPropertyName
== FM_PROP_ENABLED
)
2073 aProp
<<= pDataWindow
->IsEnabled();
2076 aProp
= VCLXWindow::getProperty( _rPropertyName
);
2082 void FmXGridPeer::dispose() throw( RuntimeException
, std::exception
)
2085 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >(this);
2086 m_aModifyListeners
.disposeAndClear(aEvt
);
2087 m_aUpdateListeners
.disposeAndClear(aEvt
);
2088 m_aContainerListeners
.disposeAndClear(aEvt
);
2089 VCLXWindow::dispose();
2091 // release all interceptors
2092 Reference
< XDispatchProviderInterceptor
> xInterceptor( m_xFirstDispatchInterceptor
);
2093 m_xFirstDispatchInterceptor
.clear();
2094 while ( xInterceptor
.is() )
2096 // tell the interceptor it has a new (means no) predecessor
2097 xInterceptor
->setMasterDispatchProvider( NULL
);
2099 // ask for it's successor
2100 Reference
< XDispatchProvider
> xSlave
= xInterceptor
->getSlaveDispatchProvider();
2101 // and give it the new (means no) successoert
2102 xInterceptor
->setSlaveDispatchProvider( NULL
);
2104 // start over with the next chain element
2105 xInterceptor
.set(xSlave
, css::uno::UNO_QUERY
);
2108 DisConnectFromDispatcher();
2109 setRowSet(Reference
< XRowSet
> ());
2114 void FmXGridPeer::addContainerListener(const Reference
< XContainerListener
>& l
) throw( RuntimeException
, std::exception
)
2116 m_aContainerListeners
.addInterface( l
);
2119 void FmXGridPeer::removeContainerListener(const Reference
< XContainerListener
>& l
) throw( RuntimeException
, std::exception
)
2121 m_aContainerListeners
.removeInterface( l
);
2124 // ::com::sun::star::data::XDatabaseCursorSupplier
2126 void FmXGridPeer::startCursorListening()
2128 if (!m_nCursorListening
)
2130 Reference
< XRowSet
> xRowSet(m_xCursor
, UNO_QUERY
);
2132 xRowSet
->addRowSetListener(this);
2134 Reference
< XReset
> xReset(m_xCursor
, UNO_QUERY
);
2136 xReset
->addResetListener(this);
2138 // register all listeners
2139 Reference
< XPropertySet
> xSet(m_xCursor
, UNO_QUERY
);
2142 xSet
->addPropertyChangeListener(FM_PROP_ISMODIFIED
, this);
2143 xSet
->addPropertyChangeListener(FM_PROP_ROWCOUNT
, this);
2146 m_nCursorListening
++;
2150 void FmXGridPeer::stopCursorListening()
2152 if (!--m_nCursorListening
)
2154 Reference
< XRowSet
> xRowSet(m_xCursor
, UNO_QUERY
);
2156 xRowSet
->removeRowSetListener(this);
2158 Reference
< XReset
> xReset(m_xCursor
, UNO_QUERY
);
2160 xReset
->removeResetListener(this);
2162 Reference
< XPropertySet
> xSet(m_xCursor
, UNO_QUERY
);
2165 xSet
->removePropertyChangeListener(FM_PROP_ISMODIFIED
, this);
2166 xSet
->removePropertyChangeListener(FM_PROP_ROWCOUNT
, this);
2172 void FmXGridPeer::updateGrid(const Reference
< XRowSet
>& _rxCursor
)
2174 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2176 pGrid
->setDataSource(_rxCursor
);
2180 Reference
< XRowSet
> FmXGridPeer::getRowSet() throw( RuntimeException
, std::exception
)
2186 void FmXGridPeer::setRowSet(const Reference
< XRowSet
>& _rDatabaseCursor
) throw( RuntimeException
, std::exception
)
2188 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2189 if (!pGrid
|| !m_xColumns
.is() || !m_xColumns
->getCount())
2191 // unregister all listeners
2194 Reference
< XLoadable
> xLoadable(m_xCursor
, UNO_QUERY
);
2195 // only if the form is loaded we set the rowset
2198 stopCursorListening();
2199 xLoadable
->removeLoadListener(this);
2203 m_xCursor
= _rDatabaseCursor
;
2207 Reference
< XLoadable
> xLoadable(m_xCursor
, UNO_QUERY
);
2208 // only if the form is loaded we set the rowset
2209 if (xLoadable
.is() && xLoadable
->isLoaded())
2210 pGrid
->setDataSource(m_xCursor
);
2212 pGrid
->setDataSource(Reference
< XRowSet
> ());
2216 startCursorListening();
2217 xLoadable
->addLoadListener(this);
2223 void SAL_CALL
FmXGridPeer::addGridControlListener( const Reference
< XGridControlListener
>& _listener
) throw( RuntimeException
, std::exception
)
2225 m_aGridControlListeners
.addInterface( _listener
);
2229 void SAL_CALL
FmXGridPeer::removeGridControlListener( const Reference
< XGridControlListener
>& _listener
) throw( RuntimeException
, std::exception
)
2231 m_aGridControlListeners
.removeInterface( _listener
);
2235 sal_Int16
FmXGridPeer::getCurrentColumnPosition() throw( RuntimeException
, std::exception
)
2237 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2238 return pGrid
? pGrid
->GetViewColumnPos(pGrid
->GetCurColumnId()) : -1;
2242 void FmXGridPeer::setCurrentColumnPosition(sal_Int16 nPos
) throw( RuntimeException
, std::exception
)
2244 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2246 pGrid
->GoToColumnId(pGrid
->GetColumnIdFromViewPos(nPos
));
2250 void FmXGridPeer::selectionChanged(const EventObject
& evt
) throw( RuntimeException
, std::exception
)
2252 SolarMutexGuard aGuard
;
2254 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2257 Reference
< ::com::sun::star::view::XSelectionSupplier
> xSelSupplier(evt
.Source
, UNO_QUERY
);
2258 Any aSelection
= xSelSupplier
->getSelection();
2259 DBG_ASSERT(aSelection
.getValueType().getTypeClass() == TypeClass_INTERFACE
, "FmXGridPeer::selectionChanged : invalid selection !");
2260 Reference
< XPropertySet
> xSelection
;
2261 aSelection
>>= xSelection
;
2262 if (xSelection
.is())
2264 Reference
< XPropertySet
> xCol
;
2266 sal_Int32 nColCount
= m_xColumns
->getCount();
2268 for (; i
< nColCount
; ++i
)
2270 m_xColumns
->getByIndex(i
) >>= xCol
;
2271 if ( xCol
== xSelection
)
2273 pGrid
->markColumn(pGrid
->GetColumnIdFromModelPos((sal_uInt16
)i
));
2277 // The columns have to be 1-based for the VCL control.
2278 // If necessary, pass on the selection to the VCL control
2279 if ( i
!= pGrid
->GetSelectedColumn() )
2280 { // (wenn das nicht greift, wurde das selectionChanged implizit von dem Control selber ausgeloest
2281 // if this does not ?hold?catch?, the selectionChanged is cleared by the Control itself
2282 if ( i
< nColCount
)
2284 pGrid
->SelectColumnPos(pGrid
->GetViewColumnPos(pGrid
->GetColumnIdFromModelPos( (sal_uInt16
)i
)) + 1, true);
2285 // SelectColumnPos has led to an implicit ActivateCell again
2286 if (pGrid
->IsEditing())
2287 pGrid
->DeactivateCell();
2290 pGrid
->SetNoSelection();
2294 pGrid
->markColumn(USHRT_MAX
);
2300 sal_Bool
FmXGridPeer::hasElements() throw( RuntimeException
, std::exception
)
2302 return getCount() != 0;
2306 Type SAL_CALL
FmXGridPeer::getElementType( ) throw(RuntimeException
, std::exception
)
2308 return cppu::UnoType
<com::sun::star::awt::XControl
>::get();
2311 // XEnumerationAccess
2313 Reference
< XEnumeration
> FmXGridPeer::createEnumeration() throw( RuntimeException
, std::exception
)
2315 return new ::comphelper::OEnumerationByIndex(this);
2320 sal_Int32
FmXGridPeer::getCount() throw( RuntimeException
, std::exception
)
2322 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2324 return pGrid
->GetViewColCount();
2330 Any
FmXGridPeer::getByIndex(sal_Int32 _nIndex
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
2332 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2334 _nIndex
>= getCount() || !pGrid
)
2335 throw IndexOutOfBoundsException();
2339 sal_uInt16 nId
= pGrid
->GetColumnIdFromViewPos((sal_uInt16
)_nIndex
);
2340 // get the list position
2341 sal_uInt16 nPos
= pGrid
->GetModelColumnPos(nId
);
2343 if ( nPos
== GRID_COLUMN_NOT_FOUND
)
2346 DbGridColumn
* pCol
= pGrid
->GetColumns().at( nPos
);
2347 Reference
< ::com::sun::star::awt::XControl
> xControl(pCol
->GetCell());
2348 aElement
<<= xControl
;
2353 // ::com::sun::star::util::XModeSelector
2355 void FmXGridPeer::setMode(const OUString
& Mode
) throw( NoSupportException
, RuntimeException
, std::exception
)
2357 if (!supportsMode(Mode
))
2358 throw NoSupportException();
2360 if (Mode
== m_aMode
)
2365 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2366 if ( Mode
== "FilterMode" )
2367 pGrid
->SetFilterMode(true);
2370 pGrid
->SetFilterMode(false);
2371 pGrid
->setDataSource(m_xCursor
);
2376 OUString
FmXGridPeer::getMode() throw( RuntimeException
, std::exception
)
2382 ::comphelper::StringSequence
FmXGridPeer::getSupportedModes() throw( RuntimeException
, std::exception
)
2384 static ::comphelper::StringSequence aModes
;
2385 if (!aModes
.getLength())
2388 OUString
* pModes
= aModes
.getArray();
2389 pModes
[0] = "DataMode";
2390 pModes
[1] = "FilterMode";
2396 sal_Bool
FmXGridPeer::supportsMode(const OUString
& Mode
) throw( RuntimeException
, std::exception
)
2398 ::comphelper::StringSequence
aModes(getSupportedModes());
2399 const OUString
* pModes
= aModes
.getConstArray();
2400 for (sal_Int32 i
= aModes
.getLength(); i
> 0; )
2402 if (pModes
[--i
] == Mode
)
2409 void FmXGridPeer::columnVisible(DbGridColumn
* pColumn
)
2411 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2413 sal_Int32 _nIndex
= pGrid
->GetModelColumnPos(pColumn
->GetId());
2414 Reference
< ::com::sun::star::awt::XControl
> xControl(pColumn
->GetCell());
2415 ContainerEvent aEvt
;
2416 aEvt
.Source
= (XContainer
*)this;
2417 aEvt
.Accessor
<<= _nIndex
;
2418 aEvt
.Element
<<= xControl
;
2420 m_aContainerListeners
.notifyEach( &XContainerListener::elementInserted
, aEvt
);
2424 void FmXGridPeer::columnHidden(DbGridColumn
* pColumn
)
2426 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2428 sal_Int32 _nIndex
= pGrid
->GetModelColumnPos(pColumn
->GetId());
2429 Reference
< ::com::sun::star::awt::XControl
> xControl(pColumn
->GetCell());
2430 ContainerEvent aEvt
;
2431 aEvt
.Source
= (XContainer
*)this;
2432 aEvt
.Accessor
<<= _nIndex
;
2433 aEvt
.Element
<<= xControl
;
2435 m_aContainerListeners
.notifyEach( &XContainerListener::elementRemoved
, aEvt
);
2439 void FmXGridPeer::draw( sal_Int32 x
, sal_Int32 y
) throw( RuntimeException
, std::exception
)
2441 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2442 EditBrowseBoxFlags nOldFlags
= pGrid
->GetBrowserFlags();
2443 pGrid
->SetBrowserFlags(nOldFlags
| EditBrowseBoxFlags::NO_HANDLE_COLUMN_CONTENT
);
2445 VCLXWindow::draw(x
, y
);
2447 pGrid
->SetBrowserFlags(nOldFlags
);
2451 Reference
< ::com::sun::star::frame::XDispatch
> FmXGridPeer::queryDispatch(const ::com::sun::star::util::URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) throw( RuntimeException
, std::exception
)
2453 Reference
< ::com::sun::star::frame::XDispatch
> xResult
;
2455 // first ask our interceptor chain
2456 if (m_xFirstDispatchInterceptor
.is() && !m_bInterceptingDispatch
)
2458 m_bInterceptingDispatch
= true;
2459 // safety against recursion : as we are master of the first chain element and slave of the last one we would
2460 // have an infinite loop without this if no dispatcher can fulfill the request
2461 xResult
= m_xFirstDispatchInterceptor
->queryDispatch(aURL
, aTargetFrameName
, nSearchFlags
);
2462 m_bInterceptingDispatch
= false;
2465 // then ask ourself : we don't have any dispatches
2470 Sequence
< Reference
< ::com::sun::star::frame::XDispatch
> > FmXGridPeer::queryDispatches(const Sequence
< ::com::sun::star::frame::DispatchDescriptor
>& aDescripts
) throw( RuntimeException
, std::exception
)
2472 if (m_xFirstDispatchInterceptor
.is())
2473 return m_xFirstDispatchInterceptor
->queryDispatches(aDescripts
);
2475 // then ask ourself : we don't have any dispatches
2476 return Sequence
< Reference
< ::com::sun::star::frame::XDispatch
> >();
2480 void FmXGridPeer::registerDispatchProviderInterceptor(const Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
>& _xInterceptor
) throw( RuntimeException
, std::exception
)
2482 if (_xInterceptor
.is())
2484 if (m_xFirstDispatchInterceptor
.is())
2486 Reference
< ::com::sun::star::frame::XDispatchProvider
> xFirstProvider(m_xFirstDispatchInterceptor
, UNO_QUERY
);
2487 // there is already an interceptor; the new one will become its master
2488 _xInterceptor
->setSlaveDispatchProvider(xFirstProvider
);
2489 m_xFirstDispatchInterceptor
->setMasterDispatchProvider(xFirstProvider
);
2493 // it is the first interceptor; set ourself as slave
2494 _xInterceptor
->setSlaveDispatchProvider((::com::sun::star::frame::XDispatchProvider
*)this);
2497 // we are the master of the chain's first interceptor
2498 m_xFirstDispatchInterceptor
= _xInterceptor
;
2499 m_xFirstDispatchInterceptor
->setMasterDispatchProvider((::com::sun::star::frame::XDispatchProvider
*)this);
2501 // we have a new interceptor and we're alive ?
2502 if (!isDesignMode())
2503 // -> check for new dispatchers
2509 void FmXGridPeer::releaseDispatchProviderInterceptor(const Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
>& _xInterceptor
) throw( RuntimeException
, std::exception
)
2511 if (!_xInterceptor
.is())
2514 Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
> xChainWalk(m_xFirstDispatchInterceptor
);
2516 if (m_xFirstDispatchInterceptor
== _xInterceptor
)
2517 { // our chain will have a new first element
2518 Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
> xSlave(m_xFirstDispatchInterceptor
->getSlaveDispatchProvider(), UNO_QUERY
);
2519 m_xFirstDispatchInterceptor
= xSlave
;
2521 // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
2523 while (xChainWalk
.is())
2525 // walk along the chain of interceptors and look for the interceptor that has to be removed
2526 Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
> xSlave(xChainWalk
->getSlaveDispatchProvider(), UNO_QUERY
);
2528 if (xChainWalk
== _xInterceptor
)
2530 // old master may be an interceptor too
2531 Reference
< ::com::sun::star::frame::XDispatchProviderInterceptor
> xMaster(xChainWalk
->getMasterDispatchProvider(), UNO_QUERY
);
2533 // unchain the interceptor that has to be removed
2534 xChainWalk
->setSlaveDispatchProvider(Reference
< ::com::sun::star::frame::XDispatchProvider
> ());
2535 xChainWalk
->setMasterDispatchProvider(Reference
< ::com::sun::star::frame::XDispatchProvider
> ());
2537 // reconnect the chain
2541 xMaster
->setSlaveDispatchProvider(Reference
< ::com::sun::star::frame::XDispatchProvider
>::query(xSlave
));
2543 // it's the first interceptor of the chain, set ourself as slave
2544 xMaster
->setSlaveDispatchProvider((::com::sun::star::frame::XDispatchProvider
*)this);
2548 // the chain's first element was removed, set ourself as new master of the second one
2550 xSlave
->setMasterDispatchProvider((::com::sun::star::frame::XDispatchProvider
*)this);
2554 xChainWalk
= xSlave
;
2556 // our interceptor chain has changed and we're alive ?
2557 if (!isDesignMode())
2558 // -> check the dispatchers
2563 void FmXGridPeer::statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& Event
) throw( RuntimeException
, std::exception
)
2565 DBG_ASSERT(m_pStateCache
, "FmXGridPeer::statusChanged : invalid call !");
2566 DBG_ASSERT(m_pDispatchers
, "FmXGridPeer::statusChanged : invalid call !");
2568 Sequence
< ::com::sun::star::util::URL
>& aUrls
= getSupportedURLs();
2569 const ::com::sun::star::util::URL
* pUrls
= aUrls
.getConstArray();
2571 Sequence
<sal_uInt16
> aSlots
= getSupportedGridSlots();
2572 const sal_uInt16
* pSlots
= aSlots
.getConstArray();
2575 for (i
=0; i
<aUrls
.getLength(); ++i
, ++pUrls
, ++pSlots
)
2577 if (pUrls
->Main
== Event
.FeatureURL
.Main
)
2579 DBG_ASSERT(m_pDispatchers
[i
] == Event
.Source
, "FmXGridPeer::statusChanged : the event source is a little bit suspect !");
2580 m_pStateCache
[i
] = Event
.IsEnabled
;
2581 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2582 if (*pSlots
!= SID_FM_RECORD_UNDO
)
2583 pGrid
->GetNavigationBar().InvalidateState(*pSlots
);
2587 DBG_ASSERT(i
<aUrls
.getLength(), "FmXGridPeer::statusChanged : got a call for an unknown url !");
2591 sal_Bool
FmXGridPeer::approveReset(const EventObject
& /*rEvent*/) throw( RuntimeException
, std::exception
)
2597 sal_Bool SAL_CALL
FmXGridPeer::select( const Any
& _rSelection
) throw (IllegalArgumentException
, RuntimeException
, std::exception
)
2599 Sequence
< Any
> aBookmarks
;
2600 if ( !( _rSelection
>>= aBookmarks
) )
2601 throw IllegalArgumentException();
2603 return GetAs
< FmGridControl
>()->selectBookmarks(aBookmarks
);
2606 // speaking strictly, we would have to adjust our model, as our ColumnSelection may have changed.
2607 // Our model is a XSelectionSupplier, too, it handles the selection of single columns.
2608 // This is somewhat strange, as selection should be a view (not a model) aspect.
2609 // So for a clean solution, we should handle column selection ourself, and the model shouldn't
2610 // deal with selection at all.
2614 Any SAL_CALL
FmXGridPeer::getSelection( ) throw (RuntimeException
, std::exception
)
2616 VclPtr
< FmGridControl
> pVclControl
= GetAs
< FmGridControl
>();
2617 Sequence
< Any
> aSelectionBookmarks
= pVclControl
->getSelectionBookmarks();
2618 return makeAny(aSelectionBookmarks
);
2622 void SAL_CALL
FmXGridPeer::addSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
) throw (RuntimeException
, std::exception
)
2624 m_aSelectionListeners
.addInterface( _rxListener
);
2628 void SAL_CALL
FmXGridPeer::removeSelectionChangeListener( const Reference
< XSelectionChangeListener
>& _rxListener
) throw (RuntimeException
, std::exception
)
2630 m_aSelectionListeners
.removeInterface( _rxListener
);
2634 void FmXGridPeer::resetted(const EventObject
& rEvent
) throw( RuntimeException
, std::exception
)
2636 if (m_xColumns
== rEvent
.Source
)
2637 { // my model was reset -> refresh the grid content
2638 SolarMutexGuard aGuard
;
2639 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2642 pGrid
->resetCurrentRow();
2644 // if the cursor fired a reset event we seem to be on the insert row
2645 else if (m_xCursor
== rEvent
.Source
)
2647 SolarMutexGuard aGuard
;
2648 VclPtr
< FmGridControl
> pGrid
= GetAs
< FmGridControl
>();
2649 if (pGrid
&& pGrid
->IsOpen())
2650 pGrid
->positioned(rEvent
);
2655 Sequence
<sal_uInt16
>& FmXGridPeer::getSupportedGridSlots()
2657 static Sequence
<sal_uInt16
> aSupported
;
2658 if (aSupported
.getLength() == 0)
2660 sal_uInt16 nSupported
[] = {
2661 DbGridControl::NavigationBar::RECORD_FIRST
,
2662 DbGridControl::NavigationBar::RECORD_PREV
,
2663 DbGridControl::NavigationBar::RECORD_NEXT
,
2664 DbGridControl::NavigationBar::RECORD_LAST
,
2665 DbGridControl::NavigationBar::RECORD_NEW
,
2668 aSupported
.realloc(sizeof(nSupported
)/sizeof(nSupported
[0]));
2669 sal_uInt16
* pSupported
= aSupported
.getArray();
2670 for (sal_uInt16 i
=0; i
<aSupported
.getLength(); ++i
, ++pSupported
)
2671 *pSupported
= nSupported
[i
];
2677 Sequence
< ::com::sun::star::util::URL
>& FmXGridPeer::getSupportedURLs()
2679 static Sequence
< ::com::sun::star::util::URL
> aSupported
;
2680 if (aSupported
.getLength() == 0)
2682 static const char* sSupported
[] = {
2683 FMURL_RECORD_MOVEFIRST
,
2684 FMURL_RECORD_MOVEPREV
,
2685 FMURL_RECORD_MOVENEXT
,
2686 FMURL_RECORD_MOVELAST
,
2687 FMURL_RECORD_MOVETONEW
,
2690 aSupported
.realloc(sizeof(sSupported
)/sizeof(sSupported
[0]));
2691 ::com::sun::star::util::URL
* pSupported
= aSupported
.getArray();
2694 for ( i
= 0; i
< aSupported
.getLength(); ++i
, ++pSupported
)
2695 pSupported
->Complete
= OUString::createFromAscii(sSupported
[i
]);
2697 // let an ::com::sun::star::util::URL-transformer normalize the URLs
2698 Reference
< ::com::sun::star::util::XURLTransformer
> xTransformer(
2699 util::URLTransformer::create(::comphelper::getProcessComponentContext()) );
2700 pSupported
= aSupported
.getArray();
2701 for (i
=0; i
<aSupported
.getLength(); ++i
)
2702 xTransformer
->parseStrict(pSupported
[i
]);
2709 void FmXGridPeer::UpdateDispatches()
2712 { // we don't have any dispatchers yet -> do the initial connect
2713 ConnectToDispatcher();
2717 sal_uInt16 nDispatchersGot
= 0;
2718 const Sequence
< ::com::sun::star::util::URL
>& aSupportedURLs
= getSupportedURLs();
2719 const ::com::sun::star::util::URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
2720 Reference
< ::com::sun::star::frame::XDispatch
> xNewDispatch
;
2721 for (sal_uInt16 i
=0; i
<aSupportedURLs
.getLength(); ++i
, ++pSupportedURLs
)
2723 xNewDispatch
= queryDispatch(*pSupportedURLs
, OUString(), 0);
2724 if (xNewDispatch
!= m_pDispatchers
[i
])
2726 if (m_pDispatchers
[i
].is())
2727 m_pDispatchers
[i
]->removeStatusListener((::com::sun::star::frame::XStatusListener
*)this, *pSupportedURLs
);
2728 m_pDispatchers
[i
] = xNewDispatch
;
2729 if (m_pDispatchers
[i
].is())
2730 m_pDispatchers
[i
]->addStatusListener((::com::sun::star::frame::XStatusListener
*)this, *pSupportedURLs
);
2732 if (m_pDispatchers
[i
].is())
2736 if (!nDispatchersGot
)
2738 delete[] m_pStateCache
;
2739 delete[] m_pDispatchers
;
2740 m_pStateCache
= NULL
;
2741 m_pDispatchers
= NULL
;
2746 void FmXGridPeer::ConnectToDispatcher()
2748 DBG_ASSERT((m_pStateCache
!= NULL
) == (m_pDispatchers
!= NULL
), "FmXGridPeer::ConnectToDispatcher : inconsistent !");
2750 { // already connected -> just do an update
2755 const Sequence
< ::com::sun::star::util::URL
>& aSupportedURLs
= getSupportedURLs();
2757 // _before_ adding the status listeners (as the add should result in a statusChanged-call) !
2758 m_pStateCache
= new bool[aSupportedURLs
.getLength()];
2759 m_pDispatchers
= new Reference
< ::com::sun::star::frame::XDispatch
> [aSupportedURLs
.getLength()];
2761 sal_uInt16 nDispatchersGot
= 0;
2762 const ::com::sun::star::util::URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
2763 for (sal_uInt16 i
=0; i
<aSupportedURLs
.getLength(); ++i
, ++pSupportedURLs
)
2765 m_pStateCache
[i
] = false;
2766 m_pDispatchers
[i
] = queryDispatch(*pSupportedURLs
, OUString(), 0);
2767 if (m_pDispatchers
[i
].is())
2769 m_pDispatchers
[i
]->addStatusListener((::com::sun::star::frame::XStatusListener
*)this, *pSupportedURLs
);
2774 if (!nDispatchersGot
)
2776 delete[] m_pStateCache
;
2777 delete[] m_pDispatchers
;
2778 m_pStateCache
= NULL
;
2779 m_pDispatchers
= NULL
;
2784 void FmXGridPeer::DisConnectFromDispatcher()
2786 if (!m_pStateCache
|| !m_pDispatchers
)
2788 // we're not connected
2790 const Sequence
< ::com::sun::star::util::URL
>& aSupportedURLs
= getSupportedURLs();
2791 const ::com::sun::star::util::URL
* pSupportedURLs
= aSupportedURLs
.getConstArray();
2792 for (sal_uInt16 i
=0; i
<aSupportedURLs
.getLength(); ++i
, ++pSupportedURLs
)
2794 if (m_pDispatchers
[i
].is())
2795 m_pDispatchers
[i
]->removeStatusListener((::com::sun::star::frame::XStatusListener
*)this, *pSupportedURLs
);
2798 delete[] m_pStateCache
;
2799 delete[] m_pDispatchers
;
2800 m_pStateCache
= NULL
;
2801 m_pDispatchers
= NULL
;
2805 IMPL_LINK(FmXGridPeer
, OnQueryGridSlotState
, void*, pSlot
)
2808 return -1; // unspecified
2810 sal_uInt16 nSlot
= (sal_uInt16
)reinterpret_cast<sal_uIntPtr
>(pSlot
);
2812 // search the given slot with our supported sequence
2813 Sequence
<sal_uInt16
>& aSupported
= getSupportedGridSlots();
2814 const sal_uInt16
* pSlots
= aSupported
.getConstArray();
2815 for (sal_uInt16 i
=0; i
<aSupported
.getLength(); ++i
)
2817 if (pSlots
[i
] == nSlot
)
2819 if (!m_pDispatchers
[i
].is())
2820 return -1; // nothing known about this slot
2822 return m_pStateCache
[i
] ? 1 : 0;
2830 IMPL_LINK(FmXGridPeer
, OnExecuteGridSlot
, void*, pSlot
)
2832 if (!m_pDispatchers
)
2833 return 0; // not handled
2835 Sequence
< ::com::sun::star::util::URL
>& aUrls
= getSupportedURLs();
2836 const ::com::sun::star::util::URL
* pUrls
= aUrls
.getConstArray();
2838 Sequence
<sal_uInt16
> aSlots
= getSupportedGridSlots();
2839 const sal_uInt16
* pSlots
= aSlots
.getConstArray();
2841 DBG_ASSERT(aSlots
.getLength() == aUrls
.getLength(), "FmXGridPeer::OnExecuteGridSlot : inconstent data returned by getSupportedURLs/getSupportedGridSlots !");
2843 sal_uInt16 nSlot
= (sal_uInt16
)reinterpret_cast<sal_uIntPtr
>(pSlot
);
2844 for (sal_uInt16 i
=0; i
<aSlots
.getLength(); ++i
, ++pUrls
, ++pSlots
)
2846 if (*pSlots
== nSlot
)
2848 if (m_pDispatchers
[i
].is())
2850 // commit any changes done so far, if it's not the undoRecord URL
2851 if ( pUrls
->Complete
== FMURL_RECORD_UNDO
|| commit() )
2852 m_pDispatchers
[i
]->dispatch(*pUrls
, Sequence
< PropertyValue
>());
2854 return 1; // handled
2859 return 0; // not handled
2862 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */