xref: /AOO41X/main/svx/source/fmcomp/fmgridif.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "svx/fmgridif.hxx"
32*cdf0e10cSrcweir #include "fmprop.hrc"
33*cdf0e10cSrcweir #include "fmservs.hxx"
34*cdf0e10cSrcweir #include "svx/fmtools.hxx"
35*cdf0e10cSrcweir #include "fmurl.hxx"
36*cdf0e10cSrcweir #include "formcontrolfactory.hxx"
37*cdf0e10cSrcweir #include "gridcell.hxx"
38*cdf0e10cSrcweir #include "sdbdatacolumn.hxx"
39*cdf0e10cSrcweir #include "svx/fmgridcl.hxx"
40*cdf0e10cSrcweir #include "svx/svxids.hrc"
41*cdf0e10cSrcweir #include <tools/urlobj.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir /** === begin UNO includes === **/
44*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/form/XFormComponent.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/form/XLoadable.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRowLocate.hpp>
55*cdf0e10cSrcweir /** === end UNO includes === **/
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include <comphelper/container.hxx>
58*cdf0e10cSrcweir #include <comphelper/enumhelper.hxx>
59*cdf0e10cSrcweir #include <comphelper/extract.hxx>
60*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
61*cdf0e10cSrcweir #include <comphelper/property.hxx>
62*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
63*cdf0e10cSrcweir #include <comphelper/types.hxx>
64*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
65*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
66*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir using namespace ::svxform;
69*cdf0e10cSrcweir using namespace ::com::sun::star::container;
70*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
71*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
72*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
73*cdf0e10cSrcweir using namespace ::com::sun::star::view;
74*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
75*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
76*cdf0e10cSrcweir using namespace ::com::sun::star::form;
77*cdf0e10cSrcweir using namespace ::com::sun::star::util;
78*cdf0e10cSrcweir using namespace ::com::sun::star;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir using ::com::sun::star::sdbcx::XColumnsSupplier;
81*cdf0e10cSrcweir using ::com::sun::star::frame::XDispatchProviderInterceptor;
82*cdf0e10cSrcweir using ::com::sun::star::frame::XDispatchProvider;
83*cdf0e10cSrcweir using ::com::sun::star::accessibility::XAccessible;
84*cdf0e10cSrcweir using ::com::sun::star::accessibility::XAccessibleContext;
85*cdf0e10cSrcweir using ::com::sun::star::sdb::XRowSetSupplier;
86*cdf0e10cSrcweir using ::com::sun::star::awt::XVclWindowPeer;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir //------------------------------------------------------------------
90*cdf0e10cSrcweir ::com::sun::star::awt::FontDescriptor ImplCreateFontDescriptor( const Font& rFont )
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir 	::com::sun::star::awt::FontDescriptor aFD;
93*cdf0e10cSrcweir 	aFD.Name = rFont.GetName();
94*cdf0e10cSrcweir 	aFD.StyleName = rFont.GetStyleName();
95*cdf0e10cSrcweir 	aFD.Height = (sal_Int16)rFont.GetSize().Height();
96*cdf0e10cSrcweir 	aFD.Width = (sal_Int16)rFont.GetSize().Width();
97*cdf0e10cSrcweir 	aFD.Family = (sal_Int16)rFont.GetFamily();
98*cdf0e10cSrcweir 	aFD.CharSet = rFont.GetCharSet();
99*cdf0e10cSrcweir 	aFD.Pitch = (sal_Int16)rFont.GetPitch();
100*cdf0e10cSrcweir 	aFD.CharacterWidth = VCLUnoHelper::ConvertFontWidth( rFont.GetWidthType() );
101*cdf0e10cSrcweir 	aFD.Weight= VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() );
102*cdf0e10cSrcweir 	aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
103*cdf0e10cSrcweir 	aFD.Underline = (sal_Int16)rFont.GetUnderline();
104*cdf0e10cSrcweir 	aFD.Strikeout = (sal_Int16)rFont.GetStrikeout();
105*cdf0e10cSrcweir 	aFD.Orientation = rFont.GetOrientation();
106*cdf0e10cSrcweir 	aFD.Kerning = rFont.IsKerning();
107*cdf0e10cSrcweir 	aFD.WordLineMode = rFont.IsWordLineMode();
108*cdf0e10cSrcweir 	aFD.Type = 0;   // ??? => Nur an Metric...
109*cdf0e10cSrcweir 	return aFD;
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir //------------------------------------------------------------------
113*cdf0e10cSrcweir Font ImplCreateFont( const ::com::sun::star::awt::FontDescriptor& rDescr )
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	Font aFont;
116*cdf0e10cSrcweir 	aFont.SetName( rDescr.Name );
117*cdf0e10cSrcweir 	aFont.SetStyleName( rDescr.StyleName );
118*cdf0e10cSrcweir 	aFont.SetSize( ::Size( rDescr.Width, rDescr.Height ) );
119*cdf0e10cSrcweir 	aFont.SetFamily( (FontFamily)rDescr.Family );
120*cdf0e10cSrcweir 	aFont.SetCharSet( (CharSet)rDescr.CharSet );
121*cdf0e10cSrcweir 	aFont.SetPitch( (FontPitch)rDescr.Pitch );
122*cdf0e10cSrcweir 	aFont.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr.CharacterWidth ) );
123*cdf0e10cSrcweir 	aFont.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr.Weight ) );
124*cdf0e10cSrcweir 	aFont.SetItalic( (FontItalic)rDescr.Slant );
125*cdf0e10cSrcweir 	aFont.SetUnderline( (::FontUnderline)rDescr.Underline );
126*cdf0e10cSrcweir 	aFont.SetStrikeout( (::FontStrikeout)rDescr.Strikeout );
127*cdf0e10cSrcweir 	aFont.SetOrientation( (sal_Int16)rDescr.Orientation );
128*cdf0e10cSrcweir 	aFont.SetKerning( rDescr.Kerning );
129*cdf0e10cSrcweir 	aFont.SetWordLineMode( rDescr.WordLineMode );
130*cdf0e10cSrcweir 	return aFont;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //==================================================================
134*cdf0e10cSrcweir //= FmXModifyMultiplexer
135*cdf0e10cSrcweir //==================================================================
136*cdf0e10cSrcweir //------------------------------------------------------------------
137*cdf0e10cSrcweir FmXModifyMultiplexer::FmXModifyMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex )
138*cdf0e10cSrcweir 					:OWeakSubObject( rSource )
139*cdf0e10cSrcweir 					,OInterfaceContainerHelper( _rMutex )
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir //------------------------------------------------------------------
144*cdf0e10cSrcweir Any	SAL_CALL FmXModifyMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir 	Any aReturn;
147*cdf0e10cSrcweir 	aReturn = ::cppu::queryInterface(_rType,
148*cdf0e10cSrcweir 		static_cast< ::com::sun::star::util::XModifyListener*>(this),
149*cdf0e10cSrcweir 		static_cast< XEventListener*>(this)
150*cdf0e10cSrcweir 	);
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	if (!aReturn.hasValue())
153*cdf0e10cSrcweir 		aReturn = OWeakSubObject::queryInterface( _rType );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	return aReturn;
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir //------------------------------------------------------------------
159*cdf0e10cSrcweir void FmXModifyMultiplexer::disposing(const EventObject& ) throw( RuntimeException )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir //------------------------------------------------------------------
164*cdf0e10cSrcweir void FmXModifyMultiplexer::modified(const EventObject& e) throw( RuntimeException )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	EventObject aMulti( e);
167*cdf0e10cSrcweir 	aMulti.Source = &m_rParent;
168*cdf0e10cSrcweir     notifyEach( &XModifyListener::modified, aMulti );
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir //==================================================================
172*cdf0e10cSrcweir //= FmXUpdateMultiplexer
173*cdf0e10cSrcweir //==================================================================
174*cdf0e10cSrcweir //------------------------------------------------------------------
175*cdf0e10cSrcweir FmXUpdateMultiplexer::FmXUpdateMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex )
176*cdf0e10cSrcweir 					:OWeakSubObject( rSource )
177*cdf0e10cSrcweir 					,OInterfaceContainerHelper( _rMutex )
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir //------------------------------------------------------------------
182*cdf0e10cSrcweir Any	SAL_CALL FmXUpdateMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException)
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir 	Any aReturn;
185*cdf0e10cSrcweir 	aReturn = ::cppu::queryInterface(_rType,
186*cdf0e10cSrcweir 		static_cast< XUpdateListener*>(this),
187*cdf0e10cSrcweir 		static_cast< XEventListener*>(this)
188*cdf0e10cSrcweir 	);
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	if (!aReturn.hasValue())
191*cdf0e10cSrcweir 		aReturn = OWeakSubObject::queryInterface( _rType );
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	return aReturn;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir //------------------------------------------------------------------
197*cdf0e10cSrcweir void FmXUpdateMultiplexer::disposing(const EventObject& ) throw( RuntimeException )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir //------------------------------------------------------------------
202*cdf0e10cSrcweir sal_Bool FmXUpdateMultiplexer::approveUpdate(const EventObject &e) throw( RuntimeException )
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	EventObject aMulti( e );
205*cdf0e10cSrcweir 	aMulti.Source = &m_rParent;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 	sal_Bool bResult = sal_True;
208*cdf0e10cSrcweir 	if (getLength())
209*cdf0e10cSrcweir 	{
210*cdf0e10cSrcweir 		::cppu::OInterfaceIteratorHelper aIter(*this);
211*cdf0e10cSrcweir 		while ( bResult && aIter.hasMoreElements() )
212*cdf0e10cSrcweir 			bResult = static_cast< XUpdateListener* >( aIter.next() )->approveUpdate( aMulti );
213*cdf0e10cSrcweir 	}
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 	return bResult;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir //------------------------------------------------------------------
219*cdf0e10cSrcweir void FmXUpdateMultiplexer::updated(const EventObject &e) throw( RuntimeException )
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir 	EventObject aMulti( e );
222*cdf0e10cSrcweir 	aMulti.Source = &m_rParent;
223*cdf0e10cSrcweir     notifyEach( &XUpdateListener::updated, aMulti );
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir //==================================================================
228*cdf0e10cSrcweir //= FmXSelectionMultiplexer
229*cdf0e10cSrcweir //==================================================================
230*cdf0e10cSrcweir //------------------------------------------------------------------
231*cdf0e10cSrcweir FmXSelectionMultiplexer::FmXSelectionMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex )
232*cdf0e10cSrcweir 	:OWeakSubObject( rSource )
233*cdf0e10cSrcweir 	,OInterfaceContainerHelper( _rMutex )
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir //------------------------------------------------------------------
238*cdf0e10cSrcweir Any	SAL_CALL FmXSelectionMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException)
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	Any aReturn;
241*cdf0e10cSrcweir 	aReturn = ::cppu::queryInterface(_rType,
242*cdf0e10cSrcweir 		static_cast< XSelectionChangeListener*>(this),
243*cdf0e10cSrcweir 		static_cast< XEventListener*>(this)
244*cdf0e10cSrcweir 	);
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	if (!aReturn.hasValue())
247*cdf0e10cSrcweir 		aReturn = OWeakSubObject::queryInterface( _rType );
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	return aReturn;
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir //------------------------------------------------------------------
253*cdf0e10cSrcweir void FmXSelectionMultiplexer::disposing(const EventObject& ) throw( RuntimeException )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir //------------------------------------------------------------------
258*cdf0e10cSrcweir void SAL_CALL FmXSelectionMultiplexer::selectionChanged( const EventObject& _rEvent ) throw (RuntimeException)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	EventObject aMulti(_rEvent);
261*cdf0e10cSrcweir 	aMulti.Source = &m_rParent;
262*cdf0e10cSrcweir     notifyEach( &XSelectionChangeListener::selectionChanged, aMulti );
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir //==================================================================
266*cdf0e10cSrcweir //= FmXContainerMultiplexer
267*cdf0e10cSrcweir //==================================================================
268*cdf0e10cSrcweir //------------------------------------------------------------------
269*cdf0e10cSrcweir FmXContainerMultiplexer::FmXContainerMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex )
270*cdf0e10cSrcweir 						:OWeakSubObject( rSource )
271*cdf0e10cSrcweir 						,OInterfaceContainerHelper( _rMutex )
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir //------------------------------------------------------------------
276*cdf0e10cSrcweir Any	SAL_CALL FmXContainerMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException)
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir 	Any aReturn;
279*cdf0e10cSrcweir 	aReturn = ::cppu::queryInterface(_rType,
280*cdf0e10cSrcweir 		static_cast< XContainerListener*>(this),
281*cdf0e10cSrcweir 		static_cast< XEventListener*>(this)
282*cdf0e10cSrcweir 	);
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	if (!aReturn.hasValue())
285*cdf0e10cSrcweir 		aReturn = OWeakSubObject::queryInterface( _rType );
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	return aReturn;
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir //------------------------------------------------------------------
291*cdf0e10cSrcweir void FmXContainerMultiplexer::disposing(const EventObject& ) throw( RuntimeException )
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir //------------------------------------------------------------------
295*cdf0e10cSrcweir void FmXContainerMultiplexer::elementInserted(const ContainerEvent& e) throw( RuntimeException )
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir 	ContainerEvent aMulti( e );
298*cdf0e10cSrcweir 	aMulti.Source = &m_rParent;
299*cdf0e10cSrcweir     notifyEach( &XContainerListener::elementInserted, aMulti );
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir //------------------------------------------------------------------
303*cdf0e10cSrcweir void FmXContainerMultiplexer::elementRemoved(const ContainerEvent& e) throw( RuntimeException )
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir 	ContainerEvent aMulti( e );
306*cdf0e10cSrcweir 	aMulti.Source = &m_rParent;
307*cdf0e10cSrcweir     notifyEach( &XContainerListener::elementRemoved, aMulti );
308*cdf0e10cSrcweir }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir //------------------------------------------------------------------
312*cdf0e10cSrcweir void FmXContainerMultiplexer::elementReplaced(const ContainerEvent& e) throw( RuntimeException )
313*cdf0e10cSrcweir {
314*cdf0e10cSrcweir 	ContainerEvent aMulti( e );
315*cdf0e10cSrcweir 	aMulti.Source = &m_rParent;
316*cdf0e10cSrcweir     notifyEach( &XContainerListener::elementReplaced, aMulti );
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir //==================================================================
320*cdf0e10cSrcweir //= FmXGridControlMultiplexer
321*cdf0e10cSrcweir //==================================================================
322*cdf0e10cSrcweir //------------------------------------------------------------------
323*cdf0e10cSrcweir FmXGridControlMultiplexer::FmXGridControlMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex )
324*cdf0e10cSrcweir 	:OWeakSubObject( rSource )
325*cdf0e10cSrcweir 	,OInterfaceContainerHelper( _rMutex )
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir //------------------------------------------------------------------
330*cdf0e10cSrcweir Any	SAL_CALL FmXGridControlMultiplexer::queryInterface(const Type& _rType) throw (RuntimeException)
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir 	Any aReturn;
333*cdf0e10cSrcweir 	aReturn = ::cppu::queryInterface( _rType,
334*cdf0e10cSrcweir 		static_cast< XGridControlListener*>(this)
335*cdf0e10cSrcweir 	);
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 	if (!aReturn.hasValue())
338*cdf0e10cSrcweir 		aReturn = OWeakSubObject::queryInterface( _rType );
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	return aReturn;
341*cdf0e10cSrcweir }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir //------------------------------------------------------------------
344*cdf0e10cSrcweir void FmXGridControlMultiplexer::disposing( const EventObject& ) throw( RuntimeException )
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir //------------------------------------------------------------------
349*cdf0e10cSrcweir void SAL_CALL FmXGridControlMultiplexer::columnChanged( const EventObject& _event ) throw (RuntimeException)
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir 	EventObject aForwardedEvent( _event );
352*cdf0e10cSrcweir 	aForwardedEvent.Source = &m_rParent;
353*cdf0e10cSrcweir     notifyEach( &XGridControlListener::columnChanged, aForwardedEvent );
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir //==================================================================
357*cdf0e10cSrcweir //= FmXGridControl
358*cdf0e10cSrcweir //==================================================================
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir //------------------------------------------------------------------
361*cdf0e10cSrcweir Reference< XInterface > SAL_CALL FmXGridControl_NewInstance_Impl(const Reference< XMultiServiceFactory>& _rxFactory)
362*cdf0e10cSrcweir {
363*cdf0e10cSrcweir 	return *(new FmXGridControl(_rxFactory));
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir DBG_NAME(FmXGridControl )
366*cdf0e10cSrcweir //------------------------------------------------------------------------------
367*cdf0e10cSrcweir FmXGridControl::FmXGridControl(const Reference< XMultiServiceFactory >& _rxFactory)
368*cdf0e10cSrcweir 			   :UnoControl( _rxFactory)
369*cdf0e10cSrcweir                ,m_aModifyListeners(*this, GetMutex())
370*cdf0e10cSrcweir 			   ,m_aUpdateListeners(*this, GetMutex())
371*cdf0e10cSrcweir 			   ,m_aContainerListeners(*this, GetMutex())
372*cdf0e10cSrcweir 			   ,m_aSelectionListeners(*this, GetMutex())
373*cdf0e10cSrcweir                ,m_aGridControlListeners(*this, GetMutex())
374*cdf0e10cSrcweir 			   ,m_nPeerCreationLevel(0)
375*cdf0e10cSrcweir 			   ,m_bInDraw(sal_False)
376*cdf0e10cSrcweir 			   ,m_xServiceFactory(_rxFactory)
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir 	DBG_CTOR(FmXGridControl ,NULL);
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir //------------------------------------------------------------------------------
382*cdf0e10cSrcweir FmXGridControl::~FmXGridControl()
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir 	DBG_DTOR(FmXGridControl ,NULL);
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir //------------------------------------------------------------------
388*cdf0e10cSrcweir Any	SAL_CALL FmXGridControl::queryAggregation(const Type& _rType) throw (RuntimeException)
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir 	Any aReturn = FmXGridControl_BASE::queryInterface(_rType);
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 	if (!aReturn.hasValue())
393*cdf0e10cSrcweir 		aReturn = UnoControl::queryAggregation( _rType );
394*cdf0e10cSrcweir 	return aReturn;
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir //------------------------------------------------------------------
398*cdf0e10cSrcweir Sequence< Type> SAL_CALL FmXGridControl::getTypes(  ) throw(RuntimeException)
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir 	return comphelper::concatSequences(UnoControl::getTypes(),FmXGridControl_BASE::getTypes());
401*cdf0e10cSrcweir }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir //------------------------------------------------------------------
404*cdf0e10cSrcweir Sequence<sal_Int8> SAL_CALL FmXGridControl::getImplementationId(  ) throw(RuntimeException)
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir     static ::cppu::OImplementationId* pId = 0;
407*cdf0e10cSrcweir 	if (! pId)
408*cdf0e10cSrcweir 	{
409*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
410*cdf0e10cSrcweir 		if (! pId)
411*cdf0e10cSrcweir 		{
412*cdf0e10cSrcweir 			static ::cppu::OImplementationId aId;
413*cdf0e10cSrcweir 			pId = &aId;
414*cdf0e10cSrcweir 		}
415*cdf0e10cSrcweir 	}
416*cdf0e10cSrcweir 	return pId->getImplementationId();
417*cdf0e10cSrcweir }
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir // XServiceInfo
420*cdf0e10cSrcweir //------------------------------------------------------------------------------
421*cdf0e10cSrcweir sal_Bool SAL_CALL FmXGridControl::supportsService(const ::rtl::OUString& ServiceName) throw()
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir 	::comphelper::StringSequence aSupported = getSupportedServiceNames();
424*cdf0e10cSrcweir 	const ::rtl::OUString * pArray = aSupported.getConstArray();
425*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < aSupported.getLength(); i++ )
426*cdf0e10cSrcweir 		if( pArray[i] == ServiceName )
427*cdf0e10cSrcweir 			return sal_True;
428*cdf0e10cSrcweir 	return sal_False;
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir //------------------------------------------------------------------------------
432*cdf0e10cSrcweir ::rtl::OUString	SAL_CALL FmXGridControl::getImplementationName() throw()
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii("com.sun.star.form.FmXGridControl");
435*cdf0e10cSrcweir }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir //------------------------------------------------------------------------------
438*cdf0e10cSrcweir ::comphelper::StringSequence SAL_CALL FmXGridControl::getSupportedServiceNames() throw()
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aServiceNames(2);
441*cdf0e10cSrcweir 	aServiceNames[0] = FM_SUN_CONTROL_GRIDCONTROL;
442*cdf0e10cSrcweir 	aServiceNames[1] = ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControl");
443*cdf0e10cSrcweir 	return aServiceNames;
444*cdf0e10cSrcweir }
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir //------------------------------------------------------------------------------
447*cdf0e10cSrcweir void SAL_CALL FmXGridControl::dispose() throw( RuntimeException )
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 	EventObject aEvt;
452*cdf0e10cSrcweir 	aEvt.Source = static_cast< ::cppu::OWeakObject* >(this);
453*cdf0e10cSrcweir 	m_aModifyListeners.disposeAndClear(aEvt);
454*cdf0e10cSrcweir 	m_aUpdateListeners.disposeAndClear(aEvt);
455*cdf0e10cSrcweir 	m_aContainerListeners.disposeAndClear(aEvt);
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir 	UnoControl::dispose();
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir //------------------------------------------------------------------------------
461*cdf0e10cSrcweir ::rtl::OUString	FmXGridControl::GetComponentServiceName()
462*cdf0e10cSrcweir {
463*cdf0e10cSrcweir 	::rtl::OUString aName = ::rtl::OUString::createFromAscii("DBGrid");
464*cdf0e10cSrcweir 	return aName;
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir //------------------------------------------------------------------------------
468*cdf0e10cSrcweir sal_Bool SAL_CALL FmXGridControl::setModel(const Reference< ::com::sun::star::awt::XControlModel >& rModel) throw( RuntimeException )
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 	if (!UnoControl::setModel(rModel))
473*cdf0e10cSrcweir 		return sal_False;
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 	Reference< XGridPeer > xGridPeer(getPeer(), UNO_QUERY);
476*cdf0e10cSrcweir 	if (xGridPeer.is())
477*cdf0e10cSrcweir 	{
478*cdf0e10cSrcweir 		Reference< XIndexContainer > xCols(mxModel, UNO_QUERY);
479*cdf0e10cSrcweir 		xGridPeer->setColumns(xCols);
480*cdf0e10cSrcweir 	}
481*cdf0e10cSrcweir 	return sal_True;
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir //------------------------------------------------------------------------------
485*cdf0e10cSrcweir FmXGridPeer* FmXGridControl::imp_CreatePeer(Window* pParent)
486*cdf0e10cSrcweir {
487*cdf0e10cSrcweir 	FmXGridPeer* pReturn = new FmXGridPeer(m_xServiceFactory);
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 	// translate properties into WinBits
490*cdf0e10cSrcweir 	WinBits nStyle = WB_TABSTOP;
491*cdf0e10cSrcweir 	Reference< XPropertySet >  xModelSet(getModel(), UNO_QUERY);
492*cdf0e10cSrcweir 	if (xModelSet.is())
493*cdf0e10cSrcweir 	{
494*cdf0e10cSrcweir 		try
495*cdf0e10cSrcweir 		{
496*cdf0e10cSrcweir 			if (::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_BORDER)))
497*cdf0e10cSrcweir 				nStyle |= WB_BORDER;
498*cdf0e10cSrcweir 		}
499*cdf0e10cSrcweir 		catch(const Exception&)
500*cdf0e10cSrcweir 		{
501*cdf0e10cSrcweir 			OSL_ASSERT(!"Can not get style");
502*cdf0e10cSrcweir 		}
503*cdf0e10cSrcweir 	}
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 	pReturn->Create(pParent, nStyle);
506*cdf0e10cSrcweir 	return pReturn;
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir //------------------------------------------------------------------------------
510*cdf0e10cSrcweir void SAL_CALL FmXGridControl::createPeer(const Reference< ::com::sun::star::awt::XToolkit >& /*rToolkit*/, const Reference< ::com::sun::star::awt::XWindowPeer >& rParentPeer) throw( RuntimeException )
511*cdf0e10cSrcweir {
512*cdf0e10cSrcweir 	if ( !mxModel.is() )
513*cdf0e10cSrcweir         throw DisposedException( ::rtl::OUString(), *this );
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 	DBG_ASSERT(/*(0 == m_nPeerCreationLevel) && */!mbCreatingPeer, "FmXGridControl::createPeer : recursion!");
516*cdf0e10cSrcweir 		// I think this should never assert, now that we're using the base class' mbCreatingPeer in addition to
517*cdf0e10cSrcweir 		// our own m_nPeerCreationLevel
518*cdf0e10cSrcweir 		// But I'm not sure as I don't _fully_ understand the underlying toolkit implementations ....
519*cdf0e10cSrcweir 		// (if this asserts, we still need m_nPeerCreationLevel. If not, we could omit it ....)
520*cdf0e10cSrcweir 		// 14.05.2001 - 86836 - frank.schoenheit@germany.sun.com
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 	// TODO: why the hell this whole class does not use any mutex?
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 	if (!getPeer().is())
525*cdf0e10cSrcweir 	{
526*cdf0e10cSrcweir 		mbCreatingPeer = sal_True;
527*cdf0e10cSrcweir 			// mbCreatingPeer is virtually the same as m_nPeerCreationLevel, but it's the base class' method
528*cdf0e10cSrcweir 			// to prevent recursion.
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 		Window* pParentWin = NULL;
531*cdf0e10cSrcweir 		if (rParentPeer.is())
532*cdf0e10cSrcweir 		{
533*cdf0e10cSrcweir 			VCLXWindow* pParent = VCLXWindow::GetImplementation(rParentPeer);
534*cdf0e10cSrcweir 			if (pParent)
535*cdf0e10cSrcweir 				pParentWin = pParent->GetWindow();
536*cdf0e10cSrcweir 		}
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 		FmXGridPeer* pPeer = imp_CreatePeer(pParentWin);
539*cdf0e10cSrcweir 		DBG_ASSERT(pPeer != NULL, "FmXGridControl::createPeer : imp_CreatePeer didn't return a peer !");
540*cdf0e10cSrcweir 		setPeer( pPeer );
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 		// lesen der properties aus dem model
543*cdf0e10cSrcweir //		++m_nPeerCreationLevel;
544*cdf0e10cSrcweir 		updateFromModel();
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 		// folgendes unschoene Szenario : updateFromModel fuehrt zu einem propertiesChanged am Control,
547*cdf0e10cSrcweir 		// das stellt fest, dass sich eine 'kritische' Property geaendert hat (zum Beispiel "Border") und
548*cdf0e10cSrcweir 		// legt daraufhin eine neue Peer an, was wieder hier im createPeer landet, wir legen also eine
549*cdf0e10cSrcweir 		// zweite FmXGridPeer an und initialisieren die. Dann kommen wir in der ersten Inkarnation aus
550*cdf0e10cSrcweir 		// dem updsateFromModel raus und arbeiten dort weiter mit dem pPeer, das jetzt eigentlich schon
551*cdf0e10cSrcweir 		// veraltet ist (da ja in der zweiten Inkarnation eine andere Peer angelegt wurde).
552*cdf0e10cSrcweir 		// Deswegen also der Aufwand mit dem PeerCreationLevel, das stellt sicher, dass wir die in dem
553*cdf0e10cSrcweir 		// tiefsten Level angelegte Peer wirklich verwenden, sie aber erst im top-level
554*cdf0e10cSrcweir 		// initialisieren.
555*cdf0e10cSrcweir //		if (--m_nPeerCreationLevel == 0)
556*cdf0e10cSrcweir 		{
557*cdf0e10cSrcweir 			DBG_ASSERT(getPeer().is(), "FmXGridControl::createPeer : something went wrong ... no top level peer !");
558*cdf0e10cSrcweir 			pPeer = FmXGridPeer::getImplementation(getPeer());
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 	        setPosSize( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight, ::com::sun::star::awt::PosSize::POSSIZE );
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir 			Reference< XIndexContainer >  xColumns(getModel(), UNO_QUERY);
563*cdf0e10cSrcweir 			if (xColumns.is())
564*cdf0e10cSrcweir 				pPeer->setColumns(xColumns);
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 			if (maComponentInfos.bVisible)
567*cdf0e10cSrcweir 				pPeer->setVisible(sal_True);
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir 			if (!maComponentInfos.bEnable)
570*cdf0e10cSrcweir 				pPeer->setEnable(sal_False);
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 			if (maWindowListeners.getLength())
573*cdf0e10cSrcweir 				pPeer->addWindowListener( &maWindowListeners );
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 			if (maFocusListeners.getLength())
576*cdf0e10cSrcweir 				pPeer->addFocusListener( &maFocusListeners );
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir 			if (maKeyListeners.getLength())
579*cdf0e10cSrcweir 				pPeer->addKeyListener( &maKeyListeners );
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir 			if (maMouseListeners.getLength())
582*cdf0e10cSrcweir 				pPeer->addMouseListener( &maMouseListeners );
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 			if (maMouseMotionListeners.getLength())
585*cdf0e10cSrcweir 				pPeer->addMouseMotionListener( &maMouseMotionListeners );
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir 			if (maPaintListeners.getLength())
588*cdf0e10cSrcweir 				pPeer->addPaintListener( &maPaintListeners );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 			if (m_aModifyListeners.getLength())
591*cdf0e10cSrcweir 				pPeer->addModifyListener( &m_aModifyListeners );
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir 			if (m_aUpdateListeners.getLength())
594*cdf0e10cSrcweir 				pPeer->addUpdateListener( &m_aUpdateListeners );
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 			if (m_aContainerListeners.getLength())
597*cdf0e10cSrcweir 				pPeer->addContainerListener( &m_aContainerListeners );
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 			// forward the design mode
600*cdf0e10cSrcweir 			sal_Bool bForceAlivePeer = m_bInDraw && !maComponentInfos.bVisible;
601*cdf0e10cSrcweir 				// (we force a alive-mode peer if we're in "draw", cause in this case the peer will be used for drawing in
602*cdf0e10cSrcweir 				// foreign devices. We ensure this with the visibility check as an living peer is assumed to be noncritical
603*cdf0e10cSrcweir 				// only if invisible)
604*cdf0e10cSrcweir 			Any aOldCursorBookmark;
605*cdf0e10cSrcweir 			if (!mbDesignMode || bForceAlivePeer)
606*cdf0e10cSrcweir 			{
607*cdf0e10cSrcweir 				Reference< XFormComponent >  xComp(getModel(), UNO_QUERY);
608*cdf0e10cSrcweir 				if (xComp.is())
609*cdf0e10cSrcweir 				{
610*cdf0e10cSrcweir 					Reference< XRowSet >  xForm(xComp->getParent(), UNO_QUERY);
611*cdf0e10cSrcweir 					// is the form alive?
612*cdf0e10cSrcweir 					// we can see that if the form contains columns
613*cdf0e10cSrcweir 					Reference< ::com::sun::star::sdbcx::XColumnsSupplier >  xColumnsSupplier(xForm, UNO_QUERY);
614*cdf0e10cSrcweir 					if (xColumnsSupplier.is())
615*cdf0e10cSrcweir 					{
616*cdf0e10cSrcweir 						if (Reference< XIndexAccess > (xColumnsSupplier->getColumns(),UNO_QUERY)->getCount())
617*cdf0e10cSrcweir 						{
618*cdf0e10cSrcweir 							// we get only a new bookmark if the resultset is not forwardonly
619*cdf0e10cSrcweir 							if (::comphelper::getINT32(Reference< XPropertySet > (xForm, UNO_QUERY)->getPropertyValue(FM_PROP_RESULTSET_TYPE)) != ResultSetType::FORWARD_ONLY)
620*cdf0e10cSrcweir 							{
621*cdf0e10cSrcweir 								// as the FmGridControl touches the data source it is connected to we have to remember the current
622*cdf0e10cSrcweir 								// cursor position (and restore afterwards)
623*cdf0e10cSrcweir 								// OJ: but only when we stand on a valid row
624*cdf0e10cSrcweir 								Reference< XResultSet > xResultSet(xForm, UNO_QUERY);
625*cdf0e10cSrcweir 								if ( !xResultSet->isBeforeFirst() && !xResultSet->isAfterLast() )
626*cdf0e10cSrcweir                                 {
627*cdf0e10cSrcweir                                     try
628*cdf0e10cSrcweir                                     {
629*cdf0e10cSrcweir 									    aOldCursorBookmark = Reference< ::com::sun::star::sdbcx::XRowLocate > (xForm, UNO_QUERY)->getBookmark();
630*cdf0e10cSrcweir                                     }
631*cdf0e10cSrcweir                                     catch( const Exception& e )
632*cdf0e10cSrcweir                                     {
633*cdf0e10cSrcweir                                         DBG_UNHANDLED_EXCEPTION();
634*cdf0e10cSrcweir                                         (void)e;
635*cdf0e10cSrcweir                                     }
636*cdf0e10cSrcweir                                 }
637*cdf0e10cSrcweir 							}
638*cdf0e10cSrcweir 						}
639*cdf0e10cSrcweir 					}
640*cdf0e10cSrcweir 					pPeer->setRowSet(xForm);
641*cdf0e10cSrcweir 				}
642*cdf0e10cSrcweir 			}
643*cdf0e10cSrcweir 			pPeer->setDesignMode(mbDesignMode && !bForceAlivePeer);
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir             try
646*cdf0e10cSrcweir             {
647*cdf0e10cSrcweir 			    if (aOldCursorBookmark.hasValue())
648*cdf0e10cSrcweir 			    {	// we have a valid bookmark, so we have to restore the cursor's position
649*cdf0e10cSrcweir 				    Reference< XFormComponent >  xComp(getModel(), UNO_QUERY);
650*cdf0e10cSrcweir 				    Reference< ::com::sun::star::sdbcx::XRowLocate >  xLocate(xComp->getParent(), UNO_QUERY);
651*cdf0e10cSrcweir 				    xLocate->moveToBookmark(aOldCursorBookmark);
652*cdf0e10cSrcweir 			    }
653*cdf0e10cSrcweir             }
654*cdf0e10cSrcweir             catch( const Exception& e )
655*cdf0e10cSrcweir             {
656*cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
657*cdf0e10cSrcweir                 (void)e;
658*cdf0e10cSrcweir             }
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 			Reference< ::com::sun::star::awt::XView >  xPeerView(getPeer(), UNO_QUERY);
661*cdf0e10cSrcweir 			xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY );
662*cdf0e10cSrcweir 			xPeerView->setGraphics( mxGraphics );
663*cdf0e10cSrcweir 		}
664*cdf0e10cSrcweir 		mbCreatingPeer = sal_False;
665*cdf0e10cSrcweir 	}
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir //------------------------------------------------------------------------------
669*cdf0e10cSrcweir void FmXGridControl::addModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException )
670*cdf0e10cSrcweir {
671*cdf0e10cSrcweir 	m_aModifyListeners.addInterface( l );
672*cdf0e10cSrcweir 	if( getPeer().is() && m_aModifyListeners.getLength() == 1 )
673*cdf0e10cSrcweir 	{
674*cdf0e10cSrcweir 		Reference< ::com::sun::star::util::XModifyBroadcaster >  xGrid(getPeer(), UNO_QUERY);
675*cdf0e10cSrcweir 		xGrid->addModifyListener( &m_aModifyListeners);
676*cdf0e10cSrcweir 	}
677*cdf0e10cSrcweir }
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir //------------------------------------------------------------------------------
680*cdf0e10cSrcweir sal_Bool SAL_CALL FmXGridControl::select( const Any& _rSelection ) throw (IllegalArgumentException, RuntimeException)
681*cdf0e10cSrcweir {
682*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
683*cdf0e10cSrcweir 	Reference< XSelectionSupplier > xPeer(getPeer(), UNO_QUERY);
684*cdf0e10cSrcweir 	return xPeer->select(_rSelection);
685*cdf0e10cSrcweir }
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir //------------------------------------------------------------------------------
688*cdf0e10cSrcweir Any SAL_CALL FmXGridControl::getSelection(  ) throw (RuntimeException)
689*cdf0e10cSrcweir {
690*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
691*cdf0e10cSrcweir 	Reference< XSelectionSupplier > xPeer(getPeer(), UNO_QUERY);
692*cdf0e10cSrcweir 	return xPeer->getSelection();
693*cdf0e10cSrcweir }
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir //------------------------------------------------------------------------------
696*cdf0e10cSrcweir void SAL_CALL FmXGridControl::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
697*cdf0e10cSrcweir {
698*cdf0e10cSrcweir 	m_aSelectionListeners.addInterface( _rxListener );
699*cdf0e10cSrcweir 	if( getPeer().is() && 1 == m_aSelectionListeners.getLength() )
700*cdf0e10cSrcweir 	{
701*cdf0e10cSrcweir 		Reference< XSelectionSupplier > xGrid(getPeer(), UNO_QUERY);
702*cdf0e10cSrcweir 		xGrid->addSelectionChangeListener( &m_aSelectionListeners);
703*cdf0e10cSrcweir 	}
704*cdf0e10cSrcweir }
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir //------------------------------------------------------------------------------
707*cdf0e10cSrcweir void SAL_CALL FmXGridControl::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
708*cdf0e10cSrcweir {
709*cdf0e10cSrcweir 	if( getPeer().is() && 1 == m_aSelectionListeners.getLength() )
710*cdf0e10cSrcweir 	{
711*cdf0e10cSrcweir 		Reference< XSelectionSupplier > xGrid(getPeer(), UNO_QUERY);
712*cdf0e10cSrcweir 		xGrid->removeSelectionChangeListener( &m_aSelectionListeners);
713*cdf0e10cSrcweir 	}
714*cdf0e10cSrcweir 	m_aSelectionListeners.removeInterface( _rxListener );
715*cdf0e10cSrcweir }
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir //------------------------------------------------------------------------------
718*cdf0e10cSrcweir Sequence< sal_Bool > SAL_CALL FmXGridControl::queryFieldDataType( const Type& xType ) throw(RuntimeException)
719*cdf0e10cSrcweir {
720*cdf0e10cSrcweir 	if (getPeer().is())
721*cdf0e10cSrcweir 	{
722*cdf0e10cSrcweir 		Reference< XGridFieldDataSupplier >  xPeerSupplier(getPeer(), UNO_QUERY);
723*cdf0e10cSrcweir 		if (xPeerSupplier.is())
724*cdf0e10cSrcweir 			return xPeerSupplier->queryFieldDataType(xType);
725*cdf0e10cSrcweir 	}
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir 	return Sequence<sal_Bool>();
728*cdf0e10cSrcweir }
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir //------------------------------------------------------------------------------
731*cdf0e10cSrcweir Sequence< Any > SAL_CALL FmXGridControl::queryFieldData( sal_Int32 nRow, const Type& xType ) throw(RuntimeException)
732*cdf0e10cSrcweir {
733*cdf0e10cSrcweir 	if (getPeer().is())
734*cdf0e10cSrcweir 	{
735*cdf0e10cSrcweir 		Reference< XGridFieldDataSupplier >  xPeerSupplier(getPeer(), UNO_QUERY);
736*cdf0e10cSrcweir 		if (xPeerSupplier.is())
737*cdf0e10cSrcweir 			return xPeerSupplier->queryFieldData(nRow, xType);
738*cdf0e10cSrcweir 	}
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 	return Sequence< Any>();
741*cdf0e10cSrcweir }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir //------------------------------------------------------------------------------
744*cdf0e10cSrcweir void SAL_CALL FmXGridControl::removeModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException )
745*cdf0e10cSrcweir {
746*cdf0e10cSrcweir 	if( getPeer().is() && m_aModifyListeners.getLength() == 1 )
747*cdf0e10cSrcweir 	{
748*cdf0e10cSrcweir 		Reference< ::com::sun::star::util::XModifyBroadcaster >  xGrid(getPeer(), UNO_QUERY);
749*cdf0e10cSrcweir 		xGrid->removeModifyListener( &m_aModifyListeners);
750*cdf0e10cSrcweir 	}
751*cdf0e10cSrcweir 	m_aModifyListeners.removeInterface( l );
752*cdf0e10cSrcweir }
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir //------------------------------------------------------------------------------
755*cdf0e10cSrcweir void SAL_CALL FmXGridControl::draw( sal_Int32 x, sal_Int32 y ) throw( RuntimeException )
756*cdf0e10cSrcweir {
757*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
758*cdf0e10cSrcweir 	m_bInDraw = sal_True;
759*cdf0e10cSrcweir 	UnoControl::draw(x, y);
760*cdf0e10cSrcweir 	m_bInDraw = sal_False;
761*cdf0e10cSrcweir }
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir //------------------------------------------------------------------------------
764*cdf0e10cSrcweir void SAL_CALL FmXGridControl::setDesignMode(sal_Bool bOn) throw( RuntimeException )
765*cdf0e10cSrcweir {
766*cdf0e10cSrcweir 	::com::sun::star::util::ModeChangeEvent aModeChangeEvent;
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir     // --- <mutex_lock> ---
769*cdf0e10cSrcweir     {
770*cdf0e10cSrcweir     	::vos::OGuard aGuard( Application::GetSolarMutex() );
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 	    Reference< XRowSetSupplier >  xGrid(getPeer(), UNO_QUERY);
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir 	    if (xGrid.is() && (bOn != mbDesignMode || (!bOn && !xGrid->getRowSet().is())))
775*cdf0e10cSrcweir 	    {
776*cdf0e10cSrcweir 		    if (bOn)
777*cdf0e10cSrcweir 		    {
778*cdf0e10cSrcweir 			    xGrid->setRowSet(Reference< XRowSet > ());
779*cdf0e10cSrcweir 		    }
780*cdf0e10cSrcweir 		    else
781*cdf0e10cSrcweir 		    {
782*cdf0e10cSrcweir 			    Reference< XFormComponent >  xComp(getModel(), UNO_QUERY);
783*cdf0e10cSrcweir 			    if (xComp.is())
784*cdf0e10cSrcweir 			    {
785*cdf0e10cSrcweir 				    Reference< XRowSet >  xForm(xComp->getParent(), UNO_QUERY);
786*cdf0e10cSrcweir 				    xGrid->setRowSet(xForm);
787*cdf0e10cSrcweir 			    }
788*cdf0e10cSrcweir 		    }
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir 		    mbDesignMode = bOn;
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir 		    Reference< XVclWindowPeer >  xVclWindowPeer( getPeer(), UNO_QUERY );
793*cdf0e10cSrcweir 		    if (xVclWindowPeer.is())
794*cdf0e10cSrcweir 			    xVclWindowPeer->setDesignMode(bOn);
795*cdf0e10cSrcweir         }
796*cdf0e10cSrcweir 	    mbDesignMode = bOn;
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir 		// dispose our current AccessibleContext, if we have one
799*cdf0e10cSrcweir 		// (changing the design mode implies having a new implementation for this context,
800*cdf0e10cSrcweir 		// so the old one must be declared DEFUNC)
801*cdf0e10cSrcweir 		disposeAccessibleContext();
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir         // prepare firing an event
804*cdf0e10cSrcweir         aModeChangeEvent.Source = *this;
805*cdf0e10cSrcweir 		aModeChangeEvent.NewMode = ::rtl::OUString::createFromAscii( mbDesignMode ? "design" : "alive" );
806*cdf0e10cSrcweir     }
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir     // --- </mutex_lock> ---
809*cdf0e10cSrcweir     maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent );
810*cdf0e10cSrcweir }
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir // XBoundComponent
813*cdf0e10cSrcweir //------------------------------------------------------------------------------
814*cdf0e10cSrcweir void SAL_CALL FmXGridControl::addUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException )
815*cdf0e10cSrcweir {
816*cdf0e10cSrcweir 	m_aUpdateListeners.addInterface( l );
817*cdf0e10cSrcweir 	if( getPeer().is() && m_aUpdateListeners.getLength() == 1 )
818*cdf0e10cSrcweir 	{
819*cdf0e10cSrcweir 		Reference< XBoundComponent >  xBound(getPeer(), UNO_QUERY);
820*cdf0e10cSrcweir 		xBound->addUpdateListener( &m_aUpdateListeners);
821*cdf0e10cSrcweir 	}
822*cdf0e10cSrcweir }
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir //------------------------------------------------------------------------------
825*cdf0e10cSrcweir void SAL_CALL FmXGridControl::removeUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException )
826*cdf0e10cSrcweir {
827*cdf0e10cSrcweir 	if( getPeer().is() && m_aUpdateListeners.getLength() == 1 )
828*cdf0e10cSrcweir 	{
829*cdf0e10cSrcweir 		Reference< XBoundComponent >  xBound(getPeer(), UNO_QUERY);
830*cdf0e10cSrcweir 		xBound->removeUpdateListener( &m_aUpdateListeners);
831*cdf0e10cSrcweir 	}
832*cdf0e10cSrcweir 	m_aUpdateListeners.removeInterface( l );
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir //------------------------------------------------------------------------------
836*cdf0e10cSrcweir sal_Bool SAL_CALL FmXGridControl::commit() throw( RuntimeException )
837*cdf0e10cSrcweir {
838*cdf0e10cSrcweir 	Reference< XBoundComponent >  xBound(getPeer(), UNO_QUERY);
839*cdf0e10cSrcweir 	if (xBound.is())
840*cdf0e10cSrcweir 		return xBound->commit();
841*cdf0e10cSrcweir 	else
842*cdf0e10cSrcweir 		return sal_True;
843*cdf0e10cSrcweir }
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir // XContainer
846*cdf0e10cSrcweir //------------------------------------------------------------------------------
847*cdf0e10cSrcweir void SAL_CALL FmXGridControl::addContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException )
848*cdf0e10cSrcweir {
849*cdf0e10cSrcweir 	m_aContainerListeners.addInterface( l );
850*cdf0e10cSrcweir 	if( getPeer().is() && m_aContainerListeners.getLength() == 1 )
851*cdf0e10cSrcweir 	{
852*cdf0e10cSrcweir 		Reference< XContainer >  xContainer(getPeer(), UNO_QUERY);
853*cdf0e10cSrcweir 		xContainer->addContainerListener( &m_aContainerListeners);
854*cdf0e10cSrcweir 	}
855*cdf0e10cSrcweir }
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir //------------------------------------------------------------------------------
858*cdf0e10cSrcweir void SAL_CALL FmXGridControl::removeContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException )
859*cdf0e10cSrcweir {
860*cdf0e10cSrcweir 	if( getPeer().is() && m_aContainerListeners.getLength() == 1 )
861*cdf0e10cSrcweir 	{
862*cdf0e10cSrcweir 		Reference< XContainer >  xContainer(getPeer(), UNO_QUERY);
863*cdf0e10cSrcweir 		xContainer->removeContainerListener( &m_aContainerListeners);
864*cdf0e10cSrcweir 	}
865*cdf0e10cSrcweir 	m_aContainerListeners.removeInterface( l );
866*cdf0e10cSrcweir }
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir //------------------------------------------------------------------------------
869*cdf0e10cSrcweir Reference< ::com::sun::star::frame::XDispatch >  SAL_CALL FmXGridControl::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
870*cdf0e10cSrcweir {
871*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatchProvider >  xPeerProvider(getPeer(), UNO_QUERY);
872*cdf0e10cSrcweir 	if (xPeerProvider.is())
873*cdf0e10cSrcweir 		return xPeerProvider->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
874*cdf0e10cSrcweir 	else
875*cdf0e10cSrcweir 		return Reference< ::com::sun::star::frame::XDispatch > ();
876*cdf0e10cSrcweir }
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir //------------------------------------------------------------------------------
879*cdf0e10cSrcweir Sequence< Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL FmXGridControl::queryDispatches(const Sequence< ::com::sun::star::frame::DispatchDescriptor>& aDescripts) throw( RuntimeException )
880*cdf0e10cSrcweir {
881*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatchProvider >  xPeerProvider(getPeer(), UNO_QUERY);
882*cdf0e10cSrcweir 	if (xPeerProvider.is())
883*cdf0e10cSrcweir 		return xPeerProvider->queryDispatches(aDescripts);
884*cdf0e10cSrcweir 	else
885*cdf0e10cSrcweir 		return Sequence< Reference< ::com::sun::star::frame::XDispatch > >();
886*cdf0e10cSrcweir }
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir //------------------------------------------------------------------------------
889*cdf0e10cSrcweir void SAL_CALL FmXGridControl::registerDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException )
890*cdf0e10cSrcweir {
891*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatchProviderInterception >  xPeerInterception(getPeer(), UNO_QUERY);
892*cdf0e10cSrcweir 	if (xPeerInterception.is())
893*cdf0e10cSrcweir 		xPeerInterception->registerDispatchProviderInterceptor(_xInterceptor);
894*cdf0e10cSrcweir }
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir //------------------------------------------------------------------------------
897*cdf0e10cSrcweir void SAL_CALL FmXGridControl::releaseDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException )
898*cdf0e10cSrcweir {
899*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatchProviderInterception >  xPeerInterception(getPeer(), UNO_QUERY);
900*cdf0e10cSrcweir 	if (xPeerInterception.is())
901*cdf0e10cSrcweir 		xPeerInterception->releaseDispatchProviderInterceptor(_xInterceptor);
902*cdf0e10cSrcweir }
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir //------------------------------------------------------------------------------
905*cdf0e10cSrcweir void SAL_CALL FmXGridControl::addGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException )
906*cdf0e10cSrcweir {
907*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( GetMutex() );
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir 	m_aGridControlListeners.addInterface( _listener );
910*cdf0e10cSrcweir 	if ( getPeer().is() && 1 == m_aGridControlListeners.getLength() )
911*cdf0e10cSrcweir 	{
912*cdf0e10cSrcweir 		Reference< XGridControl > xPeerGrid( getPeer(), UNO_QUERY );
913*cdf0e10cSrcweir         if ( xPeerGrid.is() )
914*cdf0e10cSrcweir 		    xPeerGrid->addGridControlListener( &m_aGridControlListeners );
915*cdf0e10cSrcweir 	}
916*cdf0e10cSrcweir }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir //------------------------------------------------------------------------------
919*cdf0e10cSrcweir void SAL_CALL FmXGridControl::removeGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException )
920*cdf0e10cSrcweir {
921*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( GetMutex() );
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir 	if( getPeer().is() && 1 == m_aGridControlListeners.getLength() )
924*cdf0e10cSrcweir 	{
925*cdf0e10cSrcweir 		Reference< XGridControl > xPeerGrid( getPeer(), UNO_QUERY );
926*cdf0e10cSrcweir         if ( xPeerGrid.is() )
927*cdf0e10cSrcweir 		    xPeerGrid->removeGridControlListener( &m_aGridControlListeners );
928*cdf0e10cSrcweir 	}
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir     m_aGridControlListeners.removeInterface( _listener );
931*cdf0e10cSrcweir }
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir //------------------------------------------------------------------------------
934*cdf0e10cSrcweir sal_Int16 SAL_CALL FmXGridControl::getCurrentColumnPosition() throw( RuntimeException )
935*cdf0e10cSrcweir {
936*cdf0e10cSrcweir     Reference< XGridControl > xGrid( getPeer(), UNO_QUERY );
937*cdf0e10cSrcweir 	return xGrid.is() ? xGrid->getCurrentColumnPosition() : -1;
938*cdf0e10cSrcweir }
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir //------------------------------------------------------------------------------
941*cdf0e10cSrcweir void SAL_CALL FmXGridControl::setCurrentColumnPosition(sal_Int16 nPos) throw( RuntimeException )
942*cdf0e10cSrcweir {
943*cdf0e10cSrcweir     Reference< XGridControl > xGrid( getPeer(), UNO_QUERY );
944*cdf0e10cSrcweir 	if ( xGrid.is() )
945*cdf0e10cSrcweir 	{
946*cdf0e10cSrcweir 		::vos::OGuard aGuard( Application::GetSolarMutex() );
947*cdf0e10cSrcweir 		xGrid->setCurrentColumnPosition( nPos );
948*cdf0e10cSrcweir 	}
949*cdf0e10cSrcweir }
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir // XElementAccess
952*cdf0e10cSrcweir //------------------------------------------------------------------------------
953*cdf0e10cSrcweir sal_Bool SAL_CALL FmXGridControl::hasElements() throw( RuntimeException )
954*cdf0e10cSrcweir {
955*cdf0e10cSrcweir 	Reference< XElementAccess >  xPeer(getPeer(), UNO_QUERY);
956*cdf0e10cSrcweir 	return xPeer.is() ? xPeer->hasElements() : 0;
957*cdf0e10cSrcweir }
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir //------------------------------------------------------------------------------
960*cdf0e10cSrcweir Type SAL_CALL FmXGridControl::getElementType(  ) throw(RuntimeException)
961*cdf0e10cSrcweir {
962*cdf0e10cSrcweir 	return ::getCppuType((const Reference< ::com::sun::star::awt::XTextComponent >*)NULL);
963*cdf0e10cSrcweir }
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir // XEnumerationAccess
966*cdf0e10cSrcweir //------------------------------------------------------------------------------
967*cdf0e10cSrcweir Reference< XEnumeration >  SAL_CALL FmXGridControl::createEnumeration() throw( RuntimeException )
968*cdf0e10cSrcweir {
969*cdf0e10cSrcweir 	Reference< XEnumerationAccess >  xPeer(getPeer(), UNO_QUERY);
970*cdf0e10cSrcweir 	if (xPeer.is())
971*cdf0e10cSrcweir 		return xPeer->createEnumeration();
972*cdf0e10cSrcweir 	else
973*cdf0e10cSrcweir 		return new ::comphelper::OEnumerationByIndex(this);
974*cdf0e10cSrcweir }
975*cdf0e10cSrcweir 
976*cdf0e10cSrcweir // XIndexAccess
977*cdf0e10cSrcweir //------------------------------------------------------------------------------
978*cdf0e10cSrcweir sal_Int32 SAL_CALL FmXGridControl::getCount() throw( RuntimeException )
979*cdf0e10cSrcweir {
980*cdf0e10cSrcweir 	Reference< XIndexAccess >  xPeer(getPeer(), UNO_QUERY);
981*cdf0e10cSrcweir 	return xPeer.is() ? xPeer->getCount() : 0;
982*cdf0e10cSrcweir }
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir //------------------------------------------------------------------------------
985*cdf0e10cSrcweir Any SAL_CALL FmXGridControl::getByIndex(sal_Int32 _nIndex) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
986*cdf0e10cSrcweir {
987*cdf0e10cSrcweir 	Reference< XIndexAccess >  xPeer(getPeer(), UNO_QUERY);
988*cdf0e10cSrcweir 	if (!xPeer.is())
989*cdf0e10cSrcweir 		throw IndexOutOfBoundsException();
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir 	return xPeer->getByIndex(_nIndex);
992*cdf0e10cSrcweir }
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir // ::com::sun::star::util::XModeSelector
995*cdf0e10cSrcweir //------------------------------------------------------------------------------
996*cdf0e10cSrcweir void SAL_CALL FmXGridControl::setMode(const ::rtl::OUString& Mode) throw( NoSupportException, RuntimeException )
997*cdf0e10cSrcweir {
998*cdf0e10cSrcweir 	Reference< ::com::sun::star::util::XModeSelector >  xPeer(getPeer(), UNO_QUERY);
999*cdf0e10cSrcweir 	if (!xPeer.is())
1000*cdf0e10cSrcweir 		throw NoSupportException();
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir 	xPeer->setMode(Mode);
1003*cdf0e10cSrcweir }
1004*cdf0e10cSrcweir 
1005*cdf0e10cSrcweir //------------------------------------------------------------------------------
1006*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXGridControl::getMode() throw( RuntimeException )
1007*cdf0e10cSrcweir {
1008*cdf0e10cSrcweir 	Reference< ::com::sun::star::util::XModeSelector >  xPeer(getPeer(), UNO_QUERY);
1009*cdf0e10cSrcweir 	return xPeer.is() ? xPeer->getMode() : ::rtl::OUString();
1010*cdf0e10cSrcweir }
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir //------------------------------------------------------------------------------
1013*cdf0e10cSrcweir ::comphelper::StringSequence SAL_CALL FmXGridControl::getSupportedModes() throw( RuntimeException )
1014*cdf0e10cSrcweir {
1015*cdf0e10cSrcweir 	Reference< ::com::sun::star::util::XModeSelector >  xPeer(getPeer(), UNO_QUERY);
1016*cdf0e10cSrcweir 	return xPeer.is() ? xPeer->getSupportedModes() : ::comphelper::StringSequence();
1017*cdf0e10cSrcweir }
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir //------------------------------------------------------------------------------
1020*cdf0e10cSrcweir sal_Bool SAL_CALL FmXGridControl::supportsMode(const ::rtl::OUString& Mode) throw( RuntimeException )
1021*cdf0e10cSrcweir {
1022*cdf0e10cSrcweir 	Reference< ::com::sun::star::util::XModeSelector >  xPeer(getPeer(), UNO_QUERY);
1023*cdf0e10cSrcweir 	return xPeer.is() ? xPeer->supportsMode(Mode) : sal_False;
1024*cdf0e10cSrcweir }
1025*cdf0e10cSrcweir 
1026*cdf0e10cSrcweir //==============================================================================
1027*cdf0e10cSrcweir //= FmXGridPeer
1028*cdf0e10cSrcweir //==============================================================================
1029*cdf0e10cSrcweir // helper class which prevents that in the peer's header the FmGridListener must be known
1030*cdf0e10cSrcweir class FmXGridPeer::GridListenerDelegator : public FmGridListener
1031*cdf0e10cSrcweir {
1032*cdf0e10cSrcweir protected:
1033*cdf0e10cSrcweir 	FmXGridPeer*		m_pPeer;
1034*cdf0e10cSrcweir 
1035*cdf0e10cSrcweir public:
1036*cdf0e10cSrcweir 	GridListenerDelegator( FmXGridPeer* _pPeer );
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir protected:
1039*cdf0e10cSrcweir 	virtual void selectionChanged();
1040*cdf0e10cSrcweir     virtual void columnChanged();
1041*cdf0e10cSrcweir };
1042*cdf0e10cSrcweir 
1043*cdf0e10cSrcweir //------------------------------------------------------------------
1044*cdf0e10cSrcweir FmXGridPeer::GridListenerDelegator::GridListenerDelegator(FmXGridPeer* _pPeer)
1045*cdf0e10cSrcweir 	:m_pPeer(_pPeer)
1046*cdf0e10cSrcweir {
1047*cdf0e10cSrcweir 	DBG_ASSERT(m_pPeer, "GridListenerDelegator::GridListenerDelegator");
1048*cdf0e10cSrcweir }
1049*cdf0e10cSrcweir 
1050*cdf0e10cSrcweir //------------------------------------------------------------------
1051*cdf0e10cSrcweir void FmXGridPeer::GridListenerDelegator::selectionChanged()
1052*cdf0e10cSrcweir {
1053*cdf0e10cSrcweir 	m_pPeer->selectionChanged();
1054*cdf0e10cSrcweir }
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir //------------------------------------------------------------------
1057*cdf0e10cSrcweir void FmXGridPeer::GridListenerDelegator::columnChanged()
1058*cdf0e10cSrcweir {
1059*cdf0e10cSrcweir 	m_pPeer->columnChanged();
1060*cdf0e10cSrcweir }
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir //==============================================================================
1063*cdf0e10cSrcweir //------------------------------------------------------------------
1064*cdf0e10cSrcweir Reference< XInterface >  FmXGridPeer_CreateInstance(const Reference< XMultiServiceFactory>& _rxFactory)
1065*cdf0e10cSrcweir {
1066*cdf0e10cSrcweir 	FmXGridPeer* pNewObject = new FmXGridPeer(_rxFactory);
1067*cdf0e10cSrcweir 	pNewObject->Create(NULL, WB_TABSTOP);
1068*cdf0e10cSrcweir 	return *pNewObject;
1069*cdf0e10cSrcweir }
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir //------------------------------------------------------------------
1072*cdf0e10cSrcweir Sequence< Type> SAL_CALL FmXGridPeer::getTypes(  ) throw(RuntimeException)
1073*cdf0e10cSrcweir {
1074*cdf0e10cSrcweir     return comphelper::concatSequences( VCLXWindow::getTypes(), FmXGridPeer_BASE::getTypes() );
1075*cdf0e10cSrcweir }
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir //------------------------------------------------------------------
1078*cdf0e10cSrcweir Sequence<sal_Int8> SAL_CALL FmXGridPeer::getImplementationId(  ) throw(RuntimeException)
1079*cdf0e10cSrcweir {
1080*cdf0e10cSrcweir     static ::cppu::OImplementationId* pId = 0;
1081*cdf0e10cSrcweir 	if (! pId)
1082*cdf0e10cSrcweir 	{
1083*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1084*cdf0e10cSrcweir 		if (! pId)
1085*cdf0e10cSrcweir 		{
1086*cdf0e10cSrcweir 			static ::cppu::OImplementationId aId;
1087*cdf0e10cSrcweir 			pId = &aId;
1088*cdf0e10cSrcweir 		}
1089*cdf0e10cSrcweir 	}
1090*cdf0e10cSrcweir 	return pId->getImplementationId();
1091*cdf0e10cSrcweir }
1092*cdf0e10cSrcweir 
1093*cdf0e10cSrcweir //------------------------------------------------------------------
1094*cdf0e10cSrcweir Any	SAL_CALL FmXGridPeer::queryInterface(const Type& _rType) throw (RuntimeException)
1095*cdf0e10cSrcweir {
1096*cdf0e10cSrcweir     Any aReturn = FmXGridPeer_BASE::queryInterface(_rType);
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir 	if (!aReturn.hasValue())
1099*cdf0e10cSrcweir 		aReturn = VCLXWindow::queryInterface( _rType );
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir 	return aReturn;
1102*cdf0e10cSrcweir }
1103*cdf0e10cSrcweir 
1104*cdf0e10cSrcweir //------------------------------------------------------------------
1105*cdf0e10cSrcweir void FmXGridPeer::selectionChanged()
1106*cdf0e10cSrcweir {
1107*cdf0e10cSrcweir 	EventObject aSource;
1108*cdf0e10cSrcweir 	aSource.Source = static_cast< ::cppu::OWeakObject* >(this);
1109*cdf0e10cSrcweir     m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aSource);
1110*cdf0e10cSrcweir }
1111*cdf0e10cSrcweir 
1112*cdf0e10cSrcweir //------------------------------------------------------------------
1113*cdf0e10cSrcweir void FmXGridPeer::columnChanged()
1114*cdf0e10cSrcweir {
1115*cdf0e10cSrcweir 	EventObject aEvent( *this );
1116*cdf0e10cSrcweir     m_aGridControlListeners.notifyEach( &XGridControlListener::columnChanged, aEvent );
1117*cdf0e10cSrcweir }
1118*cdf0e10cSrcweir 
1119*cdf0e10cSrcweir //------------------------------------------------------------------
1120*cdf0e10cSrcweir namespace fmgridif
1121*cdf0e10cSrcweir {
1122*cdf0e10cSrcweir 	const ::rtl::OUString getDataModeIdentifier()
1123*cdf0e10cSrcweir 	{
1124*cdf0e10cSrcweir 		static ::rtl::OUString s_sDataModeIdentifier = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) );
1125*cdf0e10cSrcweir 		return s_sDataModeIdentifier;
1126*cdf0e10cSrcweir 	}
1127*cdf0e10cSrcweir }
1128*cdf0e10cSrcweir using namespace fmgridif;
1129*cdf0e10cSrcweir 
1130*cdf0e10cSrcweir //------------------------------------------------------------------
1131*cdf0e10cSrcweir FmXGridPeer::FmXGridPeer(const Reference< XMultiServiceFactory >& _rxFactory)
1132*cdf0e10cSrcweir 			:m_aModifyListeners(m_aMutex)
1133*cdf0e10cSrcweir 			,m_aUpdateListeners(m_aMutex)
1134*cdf0e10cSrcweir 			,m_aContainerListeners(m_aMutex)
1135*cdf0e10cSrcweir 			,m_aSelectionListeners(m_aMutex)
1136*cdf0e10cSrcweir             ,m_aGridControlListeners(m_aMutex)
1137*cdf0e10cSrcweir             ,m_aMode( getDataModeIdentifier() )
1138*cdf0e10cSrcweir             ,m_nCursorListening(0)
1139*cdf0e10cSrcweir             ,m_bInterceptingDispatch(sal_False)
1140*cdf0e10cSrcweir 			,m_pStateCache(NULL)
1141*cdf0e10cSrcweir 			,m_pDispatchers(NULL)
1142*cdf0e10cSrcweir             ,m_pGridListener(NULL)
1143*cdf0e10cSrcweir 			,m_xServiceFactory(_rxFactory)
1144*cdf0e10cSrcweir {
1145*cdf0e10cSrcweir 	// nach diesem Constructor muss Create gerufen werden !
1146*cdf0e10cSrcweir 	m_pGridListener = new GridListenerDelegator( this );
1147*cdf0e10cSrcweir }
1148*cdf0e10cSrcweir 
1149*cdf0e10cSrcweir //------------------------------------------------------------------------------
1150*cdf0e10cSrcweir FmGridControl* FmXGridPeer::imp_CreateControl(Window* pParent, WinBits nStyle)
1151*cdf0e10cSrcweir {
1152*cdf0e10cSrcweir 	return new FmGridControl(m_xServiceFactory, pParent, this, nStyle);
1153*cdf0e10cSrcweir }
1154*cdf0e10cSrcweir 
1155*cdf0e10cSrcweir //------------------------------------------------------------------------------
1156*cdf0e10cSrcweir void FmXGridPeer::Create(Window* pParent, WinBits nStyle)
1157*cdf0e10cSrcweir {
1158*cdf0e10cSrcweir 	FmGridControl* pWin = imp_CreateControl(pParent, nStyle);
1159*cdf0e10cSrcweir 	DBG_ASSERT(pWin != NULL, "FmXGridPeer::Create : imp_CreateControl didn't return a control !");
1160*cdf0e10cSrcweir 
1161*cdf0e10cSrcweir 	pWin->SetStateProvider(LINK(this, FmXGridPeer, OnQueryGridSlotState));
1162*cdf0e10cSrcweir 	pWin->SetSlotExecutor(LINK(this, FmXGridPeer, OnExecuteGridSlot));
1163*cdf0e10cSrcweir 
1164*cdf0e10cSrcweir 	// want to hear about row selections
1165*cdf0e10cSrcweir 	pWin->setGridListener( m_pGridListener );
1166*cdf0e10cSrcweir 
1167*cdf0e10cSrcweir 	// Init mu� immer aufgerufen werden
1168*cdf0e10cSrcweir 	pWin->Init();
1169*cdf0e10cSrcweir 	pWin->SetComponentInterface(this);
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir 	getSupportedURLs();
1172*cdf0e10cSrcweir }
1173*cdf0e10cSrcweir 
1174*cdf0e10cSrcweir //------------------------------------------------------------------------------
1175*cdf0e10cSrcweir FmXGridPeer::~FmXGridPeer()
1176*cdf0e10cSrcweir {
1177*cdf0e10cSrcweir 	setRowSet(Reference< XRowSet > ());
1178*cdf0e10cSrcweir 	setColumns(Reference< XIndexContainer > ());
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir 	delete m_pGridListener;
1181*cdf0e10cSrcweir }
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir //------------------------------------------------------------------------------
1184*cdf0e10cSrcweir const Sequence< sal_Int8 >&	FmXGridPeer::getUnoTunnelImplementationId() throw()
1185*cdf0e10cSrcweir {
1186*cdf0e10cSrcweir 	static Sequence< sal_Int8 > * pSeq = 0;
1187*cdf0e10cSrcweir 	if( !pSeq )
1188*cdf0e10cSrcweir 	{
1189*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1190*cdf0e10cSrcweir 		if( !pSeq )
1191*cdf0e10cSrcweir 		{
1192*cdf0e10cSrcweir 			static Sequence< sal_Int8 > aSeq( 16 );
1193*cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1194*cdf0e10cSrcweir 			pSeq = &aSeq;
1195*cdf0e10cSrcweir 		}
1196*cdf0e10cSrcweir 	}
1197*cdf0e10cSrcweir 	return *pSeq;
1198*cdf0e10cSrcweir }
1199*cdf0e10cSrcweir 
1200*cdf0e10cSrcweir //------------------------------------------------------------------------------
1201*cdf0e10cSrcweir FmXGridPeer* FmXGridPeer::getImplementation( const Reference< XInterface >& _rxIFace ) throw()
1202*cdf0e10cSrcweir {
1203*cdf0e10cSrcweir 	FmXGridPeer* pReturn = NULL;
1204*cdf0e10cSrcweir 	Reference< XUnoTunnel >  xTunnel(_rxIFace, UNO_QUERY);
1205*cdf0e10cSrcweir 	if (xTunnel.is())
1206*cdf0e10cSrcweir 		pReturn = reinterpret_cast<FmXGridPeer*>(xTunnel->getSomething(getUnoTunnelImplementationId()));
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir 	return pReturn;
1209*cdf0e10cSrcweir }
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir //------------------------------------------------------------------------------
1212*cdf0e10cSrcweir sal_Int64 SAL_CALL FmXGridPeer::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
1213*cdf0e10cSrcweir {
1214*cdf0e10cSrcweir 	sal_Int64 nReturn(0);
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir 	if	(	(_rIdentifier.getLength() == 16)
1217*cdf0e10cSrcweir 		&&	(0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ))
1218*cdf0e10cSrcweir 		)
1219*cdf0e10cSrcweir 	{
1220*cdf0e10cSrcweir 		nReturn = reinterpret_cast<sal_Int64>(this);
1221*cdf0e10cSrcweir 	}
1222*cdf0e10cSrcweir 	else
1223*cdf0e10cSrcweir 		nReturn = VCLXWindow::getSomething(_rIdentifier);
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 	return nReturn;
1226*cdf0e10cSrcweir }
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir // XEventListener
1229*cdf0e10cSrcweir //------------------------------------------------------------------------------
1230*cdf0e10cSrcweir void FmXGridPeer::disposing(const EventObject& e) throw( RuntimeException )
1231*cdf0e10cSrcweir {
1232*cdf0e10cSrcweir using namespace ::com::sun::star::util;
1233*cdf0e10cSrcweir     bool bKnownSender = false;
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir     Reference< XIndexContainer >  xCols( e.Source, UNO_QUERY );
1236*cdf0e10cSrcweir 	if ( xCols.is() )
1237*cdf0e10cSrcweir     {
1238*cdf0e10cSrcweir 		setColumns(Reference< XIndexContainer > ());
1239*cdf0e10cSrcweir         bKnownSender = true;
1240*cdf0e10cSrcweir     }
1241*cdf0e10cSrcweir 
1242*cdf0e10cSrcweir 	Reference< XRowSet >  xCursor(e.Source, UNO_QUERY);
1243*cdf0e10cSrcweir 	if (xCursor.is())
1244*cdf0e10cSrcweir 	{
1245*cdf0e10cSrcweir 		setRowSet( m_xCursor );
1246*cdf0e10cSrcweir 		m_xCursor = NULL;
1247*cdf0e10cSrcweir         bKnownSender = true;
1248*cdf0e10cSrcweir 	}
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir 
1251*cdf0e10cSrcweir 	if ( !bKnownSender && m_pDispatchers )
1252*cdf0e10cSrcweir 	{
1253*cdf0e10cSrcweir 		const Sequence< URL>& aSupportedURLs = getSupportedURLs();
1254*cdf0e10cSrcweir 		const URL* pSupportedURLs = aSupportedURLs.getConstArray();
1255*cdf0e10cSrcweir 		for ( sal_uInt16 i=0; i < ( aSupportedURLs.getLength() ) && !bKnownSender; ++i, ++pSupportedURLs )
1256*cdf0e10cSrcweir 		{
1257*cdf0e10cSrcweir 			if ( m_pDispatchers[i] == e.Source )
1258*cdf0e10cSrcweir 			{
1259*cdf0e10cSrcweir 				m_pDispatchers[i]->removeStatusListener( static_cast< ::com::sun::star::frame::XStatusListener* >( this ), *pSupportedURLs );
1260*cdf0e10cSrcweir 				m_pDispatchers[i] = NULL;
1261*cdf0e10cSrcweir 				m_pStateCache[i] = 0;
1262*cdf0e10cSrcweir                 bKnownSender = true;
1263*cdf0e10cSrcweir 			}
1264*cdf0e10cSrcweir 		}
1265*cdf0e10cSrcweir 	}
1266*cdf0e10cSrcweir 
1267*cdf0e10cSrcweir     if ( !bKnownSender )
1268*cdf0e10cSrcweir         VCLXWindow::disposing(e);
1269*cdf0e10cSrcweir }
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir //------------------------------------------------------------------------------
1272*cdf0e10cSrcweir void FmXGridPeer::addModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException )
1273*cdf0e10cSrcweir {
1274*cdf0e10cSrcweir 	m_aModifyListeners.addInterface( l );
1275*cdf0e10cSrcweir }
1276*cdf0e10cSrcweir 
1277*cdf0e10cSrcweir //------------------------------------------------------------------------------
1278*cdf0e10cSrcweir void FmXGridPeer::removeModifyListener(const Reference< ::com::sun::star::util::XModifyListener >& l) throw( RuntimeException )
1279*cdf0e10cSrcweir {
1280*cdf0e10cSrcweir 	m_aModifyListeners.removeInterface( l );
1281*cdf0e10cSrcweir }
1282*cdf0e10cSrcweir 
1283*cdf0e10cSrcweir //------------------------------------------------------------------------------
1284*cdf0e10cSrcweir #define LAST_KNOWN_TYPE		FormComponentType::PATTERNFIELD
1285*cdf0e10cSrcweir Sequence< sal_Bool > SAL_CALL FmXGridPeer::queryFieldDataType( const Type& xType ) throw(RuntimeException)
1286*cdf0e10cSrcweir {
1287*cdf0e10cSrcweir 	// eine 'Konvertierungstabelle'
1288*cdf0e10cSrcweir 	static sal_Bool bCanConvert[LAST_KNOWN_TYPE][4] =
1289*cdf0e10cSrcweir 	{
1290*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::CONTROL
1291*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::COMMANDBUTTON
1292*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::RADIOBUTTON
1293*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::IMAGEBUTTON
1294*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_True  },	//	FormComponentType::CHECKBOX
1295*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::LISTBOX
1296*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::COMBOBOX
1297*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::GROUPBOX
1298*cdf0e10cSrcweir 		{ sal_True , sal_False, sal_False, sal_False },	//	FormComponentType::TEXTFIELD
1299*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::FIXEDTEXT
1300*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::GRIDCONTROL
1301*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::FILECONTROL
1302*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::HIDDENCONTROL
1303*cdf0e10cSrcweir 		{ sal_False, sal_False, sal_False, sal_False },	//	FormComponentType::IMAGECONTROL
1304*cdf0e10cSrcweir 		{ sal_True , sal_True , sal_True , sal_False },	//	FormComponentType::DATEFIELD
1305*cdf0e10cSrcweir 		{ sal_True , sal_True , sal_False, sal_False },	//	FormComponentType::TIMEFIELD
1306*cdf0e10cSrcweir 		{ sal_True , sal_True , sal_False, sal_False },	//	FormComponentType::NUMERICFIELD
1307*cdf0e10cSrcweir 		{ sal_True , sal_True , sal_False, sal_False },	//	FormComponentType::CURRENCYFIELD
1308*cdf0e10cSrcweir 		{ sal_True , sal_False, sal_False, sal_False } 	//	FormComponentType::PATTERNFIELD
1309*cdf0e10cSrcweir 	};
1310*cdf0e10cSrcweir 
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir 	sal_Int16 nMapColumn = -1;
1313*cdf0e10cSrcweir 	switch (xType.getTypeClass())
1314*cdf0e10cSrcweir 	{
1315*cdf0e10cSrcweir 		case TypeClass_STRING			: nMapColumn = 0; break;
1316*cdf0e10cSrcweir 		case TypeClass_FLOAT:
1317*cdf0e10cSrcweir 		case TypeClass_DOUBLE			: nMapColumn = 1; break;
1318*cdf0e10cSrcweir 		case TypeClass_SHORT:
1319*cdf0e10cSrcweir 		case TypeClass_LONG:
1320*cdf0e10cSrcweir 		case TypeClass_UNSIGNED_LONG:
1321*cdf0e10cSrcweir 		case TypeClass_UNSIGNED_SHORT	: nMapColumn = 2; break;
1322*cdf0e10cSrcweir 		case TypeClass_BOOLEAN			: nMapColumn = 3; break;
1323*cdf0e10cSrcweir         default:
1324*cdf0e10cSrcweir             break;
1325*cdf0e10cSrcweir 	}
1326*cdf0e10cSrcweir 
1327*cdf0e10cSrcweir 	Reference< XIndexContainer >  xColumns = getColumns();
1328*cdf0e10cSrcweir 
1329*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1330*cdf0e10cSrcweir 	sal_Int32 nColumns = pGrid->GetViewColCount();
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir 	DbGridColumns aColumns = pGrid->GetColumns();
1333*cdf0e10cSrcweir 
1334*cdf0e10cSrcweir 	Sequence<sal_Bool> aReturnSequence(nColumns);
1335*cdf0e10cSrcweir 	sal_Bool* pReturnArray = aReturnSequence.getArray();
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir 	sal_Bool bRequestedAsAny = (xType.getTypeClass() == TypeClass_ANY);
1338*cdf0e10cSrcweir 
1339*cdf0e10cSrcweir 	DbGridColumn* pCol;
1340*cdf0e10cSrcweir 	Reference< ::com::sun::star::sdb::XColumn >  xFieldContent;
1341*cdf0e10cSrcweir 	Reference< XPropertySet >  xCurrentColumn;
1342*cdf0e10cSrcweir 	for (sal_Int32 i=0; i<nColumns; ++i)
1343*cdf0e10cSrcweir 	{
1344*cdf0e10cSrcweir 		if (bRequestedAsAny)
1345*cdf0e10cSrcweir 		{
1346*cdf0e10cSrcweir 			pReturnArray[i] = sal_True;
1347*cdf0e10cSrcweir 			continue;
1348*cdf0e10cSrcweir 		}
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir 		pReturnArray[i] = sal_False;
1351*cdf0e10cSrcweir 
1352*cdf0e10cSrcweir 		sal_uInt16 nModelPos = pGrid->GetModelColumnPos(pGrid->GetColumnIdFromViewPos((sal_uInt16)i));
1353*cdf0e10cSrcweir 		DBG_ASSERT(nModelPos != (sal_uInt16)-1, "FmXGridPeer::queryFieldDataType : no model pos !");
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir 		pCol = aColumns.GetObject(nModelPos);
1356*cdf0e10cSrcweir 		const DbGridRowRef xRow = pGrid->GetSeekRow();
1357*cdf0e10cSrcweir 		xFieldContent = (xRow.Is() && xRow->HasField(pCol->GetFieldPos())) ? xRow->GetField(pCol->GetFieldPos()).getColumn() : Reference< ::com::sun::star::sdb::XColumn > ();
1358*cdf0e10cSrcweir 		if (!xFieldContent.is())
1359*cdf0e10cSrcweir 			// can't supply anything without a field content
1360*cdf0e10cSrcweir 			// FS - 07.12.99 - 54391
1361*cdf0e10cSrcweir 			continue;
1362*cdf0e10cSrcweir 
1363*cdf0e10cSrcweir 		xColumns->getByIndex(nModelPos) >>= xCurrentColumn;
1364*cdf0e10cSrcweir 		if (!::comphelper::hasProperty(FM_PROP_CLASSID, xCurrentColumn))
1365*cdf0e10cSrcweir 			continue;
1366*cdf0e10cSrcweir 
1367*cdf0e10cSrcweir 		sal_Int16 nClassId = sal_Int16();
1368*cdf0e10cSrcweir 		xCurrentColumn->getPropertyValue(FM_PROP_CLASSID) >>= nClassId;
1369*cdf0e10cSrcweir 		if (nClassId>LAST_KNOWN_TYPE)
1370*cdf0e10cSrcweir 			continue;
1371*cdf0e10cSrcweir 		DBG_ASSERT(nClassId>0, "FmXGridPeer::queryFieldDataType : somebody changed the definition of the FormComponentType enum !");
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir 		if (nMapColumn != -1)
1374*cdf0e10cSrcweir 			pReturnArray[i] = bCanConvert[nClassId-1][nMapColumn];
1375*cdf0e10cSrcweir 	}
1376*cdf0e10cSrcweir 
1377*cdf0e10cSrcweir 	return aReturnSequence;
1378*cdf0e10cSrcweir }
1379*cdf0e10cSrcweir 
1380*cdf0e10cSrcweir //------------------------------------------------------------------------------
1381*cdf0e10cSrcweir Sequence< Any > SAL_CALL FmXGridPeer::queryFieldData( sal_Int32 nRow, const Type& xType ) throw(RuntimeException)
1382*cdf0e10cSrcweir {
1383*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1384*cdf0e10cSrcweir 	DBG_ASSERT(pGrid && pGrid->IsOpen(), "FmXGridPeer::queryFieldData : have no valid grid window !");
1385*cdf0e10cSrcweir 	if (!pGrid || !pGrid->IsOpen())
1386*cdf0e10cSrcweir 		return Sequence< Any>();
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir 	// das Control zur angegebenen Row fahren
1389*cdf0e10cSrcweir 	if (!pGrid->SeekRow(nRow))
1390*cdf0e10cSrcweir 	{
1391*cdf0e10cSrcweir 		throw IllegalArgumentException();
1392*cdf0e10cSrcweir 	}
1393*cdf0e10cSrcweir 
1394*cdf0e10cSrcweir 	// don't use GetCurrentRow as this isn't affected by the above SeekRow
1395*cdf0e10cSrcweir 	// FS - 30.09.99 - 68644
1396*cdf0e10cSrcweir 	DbGridRowRef xPaintRow = pGrid->GetPaintRow();
1397*cdf0e10cSrcweir     ENSURE_OR_THROW( xPaintRow.Is(), "invalid paint row" );
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir 	// die Columns des Controls brauche ich fuer GetFieldText
1400*cdf0e10cSrcweir 	DbGridColumns aColumns = pGrid->GetColumns();
1401*cdf0e10cSrcweir 
1402*cdf0e10cSrcweir 	// und durch alle Spalten durch
1403*cdf0e10cSrcweir 	sal_Int32 nColumnCount = pGrid->GetViewColCount();
1404*cdf0e10cSrcweir 
1405*cdf0e10cSrcweir 	Sequence< Any> aReturnSequence(nColumnCount);
1406*cdf0e10cSrcweir 	Any* pReturnArray = aReturnSequence.getArray();
1407*cdf0e10cSrcweir 
1408*cdf0e10cSrcweir 	sal_Bool bRequestedAsAny = (xType.getTypeClass() == TypeClass_ANY);
1409*cdf0e10cSrcweir 	Reference< ::com::sun::star::sdb::XColumn >  xFieldContent;
1410*cdf0e10cSrcweir 	DbGridColumn* pCol;
1411*cdf0e10cSrcweir 	for (sal_Int32 i=0; i < nColumnCount; ++i)
1412*cdf0e10cSrcweir 	{
1413*cdf0e10cSrcweir 		sal_uInt16 nModelPos = pGrid->GetModelColumnPos(pGrid->GetColumnIdFromViewPos((sal_uInt16)i));
1414*cdf0e10cSrcweir 		DBG_ASSERT(nModelPos != (sal_uInt16)-1, "FmXGridPeer::queryFieldData : invalid model pos !");
1415*cdf0e10cSrcweir 
1416*cdf0e10cSrcweir 		// don't use GetCurrentFieldValue to determine the field content as this isn't affected by the above SeekRow
1417*cdf0e10cSrcweir 		// FS - 30.09.99 - 68644
1418*cdf0e10cSrcweir 		pCol = aColumns.GetObject(nModelPos);
1419*cdf0e10cSrcweir 		xFieldContent = xPaintRow->HasField( pCol->GetFieldPos() )
1420*cdf0e10cSrcweir                     ?   xPaintRow->GetField( pCol->GetFieldPos() ).getColumn()
1421*cdf0e10cSrcweir                     :   Reference< XColumn > ();
1422*cdf0e10cSrcweir 
1423*cdf0e10cSrcweir 		if ( !xFieldContent.is() )
1424*cdf0e10cSrcweir             continue;
1425*cdf0e10cSrcweir 
1426*cdf0e10cSrcweir 		if (bRequestedAsAny)
1427*cdf0e10cSrcweir 		{
1428*cdf0e10cSrcweir 			Reference< XPropertySet >  xFieldSet(xFieldContent, UNO_QUERY);
1429*cdf0e10cSrcweir 			pReturnArray[i] = xFieldSet->getPropertyValue(FM_PROP_VALUE);
1430*cdf0e10cSrcweir 		}
1431*cdf0e10cSrcweir 		else
1432*cdf0e10cSrcweir 		{
1433*cdf0e10cSrcweir 			switch (xType.getTypeClass())
1434*cdf0e10cSrcweir 			{
1435*cdf0e10cSrcweir 				// Strings werden direkt ueber das GetFieldText abgehandelt
1436*cdf0e10cSrcweir 				case TypeClass_STRING			:
1437*cdf0e10cSrcweir 				{
1438*cdf0e10cSrcweir 					String sText = aColumns.GetObject(nModelPos)->GetCellText( xPaintRow, pGrid->getNumberFormatter() );
1439*cdf0e10cSrcweir 					pReturnArray[i] <<= ::rtl::OUString(sText);
1440*cdf0e10cSrcweir 				}
1441*cdf0e10cSrcweir 				break;
1442*cdf0e10cSrcweir 				// alles andere wird an der DatabaseVariant erfragt
1443*cdf0e10cSrcweir 				case TypeClass_FLOAT			: pReturnArray[i] <<= xFieldContent->getFloat(); break;
1444*cdf0e10cSrcweir 				case TypeClass_DOUBLE		    : pReturnArray[i] <<= xFieldContent->getDouble(); break;
1445*cdf0e10cSrcweir 				case TypeClass_SHORT			: pReturnArray[i] <<= (sal_Int16)xFieldContent->getShort(); break;
1446*cdf0e10cSrcweir 				case TypeClass_LONG			    : pReturnArray[i] <<= (sal_Int32)xFieldContent->getLong(); break;
1447*cdf0e10cSrcweir 				case TypeClass_UNSIGNED_SHORT   : pReturnArray[i] <<= (sal_uInt16)xFieldContent->getShort(); break;
1448*cdf0e10cSrcweir 				case TypeClass_UNSIGNED_LONG	: pReturnArray[i] <<= (sal_uInt32)xFieldContent->getLong(); break;
1449*cdf0e10cSrcweir 				case TypeClass_BOOLEAN		    : ::comphelper::setBOOL(pReturnArray[i],xFieldContent->getBoolean()); break;
1450*cdf0e10cSrcweir 				default:
1451*cdf0e10cSrcweir 				{
1452*cdf0e10cSrcweir 					throw IllegalArgumentException();
1453*cdf0e10cSrcweir 				}
1454*cdf0e10cSrcweir 			}
1455*cdf0e10cSrcweir 		}
1456*cdf0e10cSrcweir 	}
1457*cdf0e10cSrcweir 	return aReturnSequence;
1458*cdf0e10cSrcweir }
1459*cdf0e10cSrcweir 
1460*cdf0e10cSrcweir //------------------------------------------------------------------------------
1461*cdf0e10cSrcweir void FmXGridPeer::CellModified()
1462*cdf0e10cSrcweir {
1463*cdf0e10cSrcweir 	EventObject aEvt;
1464*cdf0e10cSrcweir 	aEvt.Source = static_cast< ::cppu::OWeakObject* >(this);
1465*cdf0e10cSrcweir     m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvt );
1466*cdf0e10cSrcweir }
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir // XPropertyChangeListener
1469*cdf0e10cSrcweir //------------------------------------------------------------------------------
1470*cdf0e10cSrcweir void FmXGridPeer::propertyChange(const PropertyChangeEvent& evt) throw( RuntimeException )
1471*cdf0e10cSrcweir {
1472*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1473*cdf0e10cSrcweir 		// want to do a lot of VCL stuff here ...
1474*cdf0e10cSrcweir 		// this should not be (deadlock) critical, as by definition, every component should release
1475*cdf0e10cSrcweir 		// any own mutexes before notifying
1476*cdf0e10cSrcweir 
1477*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1478*cdf0e10cSrcweir 	if (!pGrid)
1479*cdf0e10cSrcweir 		return;
1480*cdf0e10cSrcweir 
1481*cdf0e10cSrcweir 	// DatenbankEvent
1482*cdf0e10cSrcweir 	Reference< XRowSet >  xCursor(evt.Source, UNO_QUERY);
1483*cdf0e10cSrcweir 	if (evt.PropertyName == FM_PROP_VALUE || m_xCursor == evt.Source)
1484*cdf0e10cSrcweir 		pGrid->propertyChange(evt);
1485*cdf0e10cSrcweir 	else if (pGrid && m_xColumns.is() && m_xColumns->hasElements())
1486*cdf0e10cSrcweir 	{
1487*cdf0e10cSrcweir 		// zunaechst raussuchen welche Column sich geaendert hat
1488*cdf0e10cSrcweir 		::comphelper::InterfaceRef xCurrent;
1489*cdf0e10cSrcweir 		sal_Int32 i;
1490*cdf0e10cSrcweir 
1491*cdf0e10cSrcweir 		for ( i = 0; i < m_xColumns->getCount(); i++)
1492*cdf0e10cSrcweir 		{
1493*cdf0e10cSrcweir 			::cppu::extractInterface(xCurrent, m_xColumns->getByIndex(i));
1494*cdf0e10cSrcweir 			if (evt.Source == xCurrent)
1495*cdf0e10cSrcweir 				break;
1496*cdf0e10cSrcweir 		}
1497*cdf0e10cSrcweir 
1498*cdf0e10cSrcweir 		if (i >= m_xColumns->getCount())
1499*cdf0e10cSrcweir 			// this is valid because we are listening at the cursor, too (RecordCount, -status, edit mode)
1500*cdf0e10cSrcweir 			return;
1501*cdf0e10cSrcweir 
1502*cdf0e10cSrcweir 		sal_uInt16 nId = pGrid->GetColumnIdFromModelPos((sal_uInt16)i);
1503*cdf0e10cSrcweir 		sal_Bool bInvalidateColumn = sal_False;
1504*cdf0e10cSrcweir 
1505*cdf0e10cSrcweir 		if (evt.PropertyName == FM_PROP_LABEL)
1506*cdf0e10cSrcweir 		{
1507*cdf0e10cSrcweir 			String aName = ::comphelper::getString(evt.NewValue);
1508*cdf0e10cSrcweir 			if (aName != pGrid->GetColumnTitle(nId))
1509*cdf0e10cSrcweir 				pGrid->SetColumnTitle(nId, aName);
1510*cdf0e10cSrcweir 		}
1511*cdf0e10cSrcweir 		else if (evt.PropertyName == FM_PROP_WIDTH)
1512*cdf0e10cSrcweir 		{
1513*cdf0e10cSrcweir 			sal_Int32 nWidth = 0;
1514*cdf0e10cSrcweir 			if (evt.NewValue.getValueType().getTypeClass() == TypeClass_VOID)
1515*cdf0e10cSrcweir 				nWidth = pGrid->GetDefaultColumnWidth(pGrid->GetColumnTitle(nId));
1516*cdf0e10cSrcweir 				// GetDefaultColumnWidth already considerd the zoom factor
1517*cdf0e10cSrcweir 			else
1518*cdf0e10cSrcweir 			{
1519*cdf0e10cSrcweir 				sal_Int32 nTest = 0;
1520*cdf0e10cSrcweir 				if (evt.NewValue >>= nTest)
1521*cdf0e10cSrcweir 				{
1522*cdf0e10cSrcweir 					nWidth = pGrid->LogicToPixel(Point(nTest,0),MAP_10TH_MM).X();
1523*cdf0e10cSrcweir 					// take the zoom factor into account
1524*cdf0e10cSrcweir 					nWidth = pGrid->CalcZoom(nWidth);
1525*cdf0e10cSrcweir 				}
1526*cdf0e10cSrcweir 			}
1527*cdf0e10cSrcweir 			if (nWidth != (sal_Int32(pGrid->GetColumnWidth(nId))))
1528*cdf0e10cSrcweir 			{
1529*cdf0e10cSrcweir 				if (pGrid->IsEditing())
1530*cdf0e10cSrcweir 				{
1531*cdf0e10cSrcweir 					pGrid->DeactivateCell();
1532*cdf0e10cSrcweir 					pGrid->ActivateCell();
1533*cdf0e10cSrcweir 				}
1534*cdf0e10cSrcweir 				pGrid->SetColumnWidth(nId, nWidth);
1535*cdf0e10cSrcweir 			}
1536*cdf0e10cSrcweir 		}
1537*cdf0e10cSrcweir 		else if (evt.PropertyName == FM_PROP_HIDDEN)
1538*cdf0e10cSrcweir 		{
1539*cdf0e10cSrcweir 			DBG_ASSERT(evt.NewValue.getValueType().getTypeClass() == TypeClass_BOOLEAN,
1540*cdf0e10cSrcweir 				"FmXGridPeer::propertyChange : the property 'hidden' should be of type boolean !");
1541*cdf0e10cSrcweir 			if (::comphelper::getBOOL(evt.NewValue))
1542*cdf0e10cSrcweir 				pGrid->HideColumn(nId);
1543*cdf0e10cSrcweir 			else
1544*cdf0e10cSrcweir 				pGrid->ShowColumn(nId);
1545*cdf0e10cSrcweir 		}
1546*cdf0e10cSrcweir 		else if (evt.PropertyName == FM_PROP_ALIGN)
1547*cdf0e10cSrcweir 		{
1548*cdf0e10cSrcweir 			// it design mode it doesn't matter
1549*cdf0e10cSrcweir 			if (!isDesignMode())
1550*cdf0e10cSrcweir 			{
1551*cdf0e10cSrcweir 				DbGridColumn* pCol = pGrid->GetColumns().GetObject(i);
1552*cdf0e10cSrcweir 
1553*cdf0e10cSrcweir 				pCol->SetAlignmentFromModel(-1);
1554*cdf0e10cSrcweir 				bInvalidateColumn = sal_True;
1555*cdf0e10cSrcweir 			}
1556*cdf0e10cSrcweir 		}
1557*cdf0e10cSrcweir 		else if (evt.PropertyName == FM_PROP_FORMATKEY)
1558*cdf0e10cSrcweir 		{
1559*cdf0e10cSrcweir 			if (!isDesignMode())
1560*cdf0e10cSrcweir 				bInvalidateColumn = sal_True;
1561*cdf0e10cSrcweir 		}
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir 		// need to invalidate the affected column ?
1564*cdf0e10cSrcweir 		if (bInvalidateColumn)
1565*cdf0e10cSrcweir 		{
1566*cdf0e10cSrcweir 			sal_Bool bWasEditing = pGrid->IsEditing();
1567*cdf0e10cSrcweir 			if (bWasEditing)
1568*cdf0e10cSrcweir 				pGrid->DeactivateCell();
1569*cdf0e10cSrcweir 
1570*cdf0e10cSrcweir 			::Rectangle aColRect = pGrid->GetFieldRect(nId);
1571*cdf0e10cSrcweir 			aColRect.Top() = 0;
1572*cdf0e10cSrcweir 			aColRect.Bottom() = pGrid->GetSizePixel().Height();
1573*cdf0e10cSrcweir 			pGrid->Invalidate(aColRect);
1574*cdf0e10cSrcweir 
1575*cdf0e10cSrcweir 			if (bWasEditing)
1576*cdf0e10cSrcweir 				pGrid->ActivateCell();
1577*cdf0e10cSrcweir 		}
1578*cdf0e10cSrcweir 	}
1579*cdf0e10cSrcweir }
1580*cdf0e10cSrcweir 
1581*cdf0e10cSrcweir // XBoundComponent
1582*cdf0e10cSrcweir //------------------------------------------------------------------------------
1583*cdf0e10cSrcweir void FmXGridPeer::addUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException )
1584*cdf0e10cSrcweir {
1585*cdf0e10cSrcweir 	m_aUpdateListeners.addInterface(l);
1586*cdf0e10cSrcweir }
1587*cdf0e10cSrcweir 
1588*cdf0e10cSrcweir //------------------------------------------------------------------------------
1589*cdf0e10cSrcweir void FmXGridPeer::removeUpdateListener(const Reference< XUpdateListener >& l) throw( RuntimeException )
1590*cdf0e10cSrcweir {
1591*cdf0e10cSrcweir 	m_aUpdateListeners.removeInterface(l);
1592*cdf0e10cSrcweir }
1593*cdf0e10cSrcweir 
1594*cdf0e10cSrcweir //------------------------------------------------------------------------------
1595*cdf0e10cSrcweir sal_Bool FmXGridPeer::commit() throw( RuntimeException )
1596*cdf0e10cSrcweir {
1597*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1598*cdf0e10cSrcweir 	if (!m_xCursor.is() || !pGrid)
1599*cdf0e10cSrcweir 		return sal_True;
1600*cdf0e10cSrcweir 
1601*cdf0e10cSrcweir 	EventObject aEvt(static_cast< ::cppu::OWeakObject* >(this));
1602*cdf0e10cSrcweir 	::cppu::OInterfaceIteratorHelper aIter(m_aUpdateListeners);
1603*cdf0e10cSrcweir 	sal_Bool bCancel = sal_False;
1604*cdf0e10cSrcweir 	while (aIter.hasMoreElements() && !bCancel)
1605*cdf0e10cSrcweir 		if ( !static_cast< XUpdateListener* >( aIter.next() )->approveUpdate( aEvt ) )
1606*cdf0e10cSrcweir 			bCancel = sal_True;
1607*cdf0e10cSrcweir 
1608*cdf0e10cSrcweir 	if (!bCancel)
1609*cdf0e10cSrcweir 		bCancel = !pGrid->commit();
1610*cdf0e10cSrcweir 
1611*cdf0e10cSrcweir 	if (!bCancel)
1612*cdf0e10cSrcweir         m_aUpdateListeners.notifyEach( &XUpdateListener::updated, aEvt );
1613*cdf0e10cSrcweir 	return !bCancel;
1614*cdf0e10cSrcweir }
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir 
1617*cdf0e10cSrcweir //------------------------------------------------------------------------------
1618*cdf0e10cSrcweir void FmXGridPeer::cursorMoved(const EventObject& _rEvent) throw( RuntimeException )
1619*cdf0e10cSrcweir {
1620*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1621*cdf0e10cSrcweir 	// we are not interested in move to insert row only in the resetted event
1622*cdf0e10cSrcweir 	// which is fired after positioning an the insert row
1623*cdf0e10cSrcweir 	if (pGrid && pGrid->IsOpen() && !::comphelper::getBOOL(Reference< XPropertySet > (_rEvent.Source, UNO_QUERY)->getPropertyValue(FM_PROP_ISNEW)))
1624*cdf0e10cSrcweir 		pGrid->positioned(_rEvent);
1625*cdf0e10cSrcweir }
1626*cdf0e10cSrcweir 
1627*cdf0e10cSrcweir //------------------------------------------------------------------------------
1628*cdf0e10cSrcweir void FmXGridPeer::rowChanged(const EventObject& _rEvent) throw( RuntimeException )
1629*cdf0e10cSrcweir {
1630*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1631*cdf0e10cSrcweir 	if (pGrid && pGrid->IsOpen())
1632*cdf0e10cSrcweir 	{
1633*cdf0e10cSrcweir 		if (m_xCursor->rowUpdated() && !pGrid->IsCurrentAppending())
1634*cdf0e10cSrcweir 			pGrid->RowModified(pGrid->GetCurrentPos());
1635*cdf0e10cSrcweir 		else if (m_xCursor->rowInserted())
1636*cdf0e10cSrcweir 			pGrid->inserted(_rEvent);
1637*cdf0e10cSrcweir 	}
1638*cdf0e10cSrcweir }
1639*cdf0e10cSrcweir 
1640*cdf0e10cSrcweir //------------------------------------------------------------------------------
1641*cdf0e10cSrcweir void FmXGridPeer::rowSetChanged(const EventObject& /*event*/) throw( RuntimeException )
1642*cdf0e10cSrcweir {
1643*cdf0e10cSrcweir 	// not interested in ...
1644*cdf0e10cSrcweir 	// (our parent is a form which means we get a loaded or reloaded after this rowSetChanged)
1645*cdf0e10cSrcweir }
1646*cdf0e10cSrcweir 
1647*cdf0e10cSrcweir // XLoadListener
1648*cdf0e10cSrcweir //------------------------------------------------------------------------------
1649*cdf0e10cSrcweir void FmXGridPeer::loaded(const EventObject& /*rEvent*/) throw( RuntimeException )
1650*cdf0e10cSrcweir {
1651*cdf0e10cSrcweir 	updateGrid(m_xCursor);
1652*cdf0e10cSrcweir }
1653*cdf0e10cSrcweir 
1654*cdf0e10cSrcweir //------------------------------------------------------------------------------
1655*cdf0e10cSrcweir void FmXGridPeer::unloaded(const EventObject& /*rEvent*/) throw( RuntimeException )
1656*cdf0e10cSrcweir {
1657*cdf0e10cSrcweir 	updateGrid( Reference< XRowSet > (NULL) );
1658*cdf0e10cSrcweir }
1659*cdf0e10cSrcweir 
1660*cdf0e10cSrcweir //------------------------------------------------------------------------------
1661*cdf0e10cSrcweir void FmXGridPeer::reloading(const EventObject& /*aEvent*/) throw( RuntimeException )
1662*cdf0e10cSrcweir {
1663*cdf0e10cSrcweir 	// empty the grid
1664*cdf0e10cSrcweir 	updateGrid( Reference< XRowSet > (NULL) );
1665*cdf0e10cSrcweir }
1666*cdf0e10cSrcweir 
1667*cdf0e10cSrcweir //------------------------------------------------------------------------------
1668*cdf0e10cSrcweir void FmXGridPeer::unloading(const EventObject& /*aEvent*/) throw( RuntimeException )
1669*cdf0e10cSrcweir {
1670*cdf0e10cSrcweir 	// empty the grid
1671*cdf0e10cSrcweir 	updateGrid( Reference< XRowSet > (NULL) );
1672*cdf0e10cSrcweir }
1673*cdf0e10cSrcweir 
1674*cdf0e10cSrcweir //------------------------------------------------------------------------------
1675*cdf0e10cSrcweir void FmXGridPeer::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
1676*cdf0e10cSrcweir {
1677*cdf0e10cSrcweir 	updateGrid(m_xCursor);
1678*cdf0e10cSrcweir }
1679*cdf0e10cSrcweir 
1680*cdf0e10cSrcweir // XGridPeer
1681*cdf0e10cSrcweir //------------------------------------------------------------------------------
1682*cdf0e10cSrcweir Reference< XIndexContainer >  FmXGridPeer::getColumns() throw( RuntimeException )
1683*cdf0e10cSrcweir {
1684*cdf0e10cSrcweir 	return m_xColumns;
1685*cdf0e10cSrcweir }
1686*cdf0e10cSrcweir 
1687*cdf0e10cSrcweir //------------------------------------------------------------------------------
1688*cdf0e10cSrcweir void FmXGridPeer::addColumnListeners(const Reference< XPropertySet >& xCol)
1689*cdf0e10cSrcweir {
1690*cdf0e10cSrcweir 	static const ::rtl::OUString aPropsListenedTo[] =
1691*cdf0e10cSrcweir 	{
1692*cdf0e10cSrcweir 		FM_PROP_LABEL, FM_PROP_WIDTH, FM_PROP_HIDDEN, FM_PROP_ALIGN, FM_PROP_FORMATKEY
1693*cdf0e10cSrcweir 	};
1694*cdf0e10cSrcweir 
1695*cdf0e10cSrcweir 	// as not all properties have to be supported by all columns we have to check this
1696*cdf0e10cSrcweir 	// before adding a listener
1697*cdf0e10cSrcweir 	Reference< XPropertySetInfo > xInfo = xCol->getPropertySetInfo();
1698*cdf0e10cSrcweir 	Property aPropDesc;
1699*cdf0e10cSrcweir 	const ::rtl::OUString* pProps = aPropsListenedTo;
1700*cdf0e10cSrcweir 	const ::rtl::OUString* pPropsEnd = pProps + sizeof( aPropsListenedTo ) / sizeof( aPropsListenedTo[ 0 ] );
1701*cdf0e10cSrcweir 	for (; pProps != pPropsEnd; ++pProps)
1702*cdf0e10cSrcweir 	{
1703*cdf0e10cSrcweir 		if ( xInfo->hasPropertyByName( *pProps ) )
1704*cdf0e10cSrcweir 		{
1705*cdf0e10cSrcweir 			aPropDesc = xInfo->getPropertyByName( *pProps );
1706*cdf0e10cSrcweir 			if ( 0 != ( aPropDesc.Attributes & PropertyAttribute::BOUND ) )
1707*cdf0e10cSrcweir 				xCol->addPropertyChangeListener( *pProps, this );
1708*cdf0e10cSrcweir 		}
1709*cdf0e10cSrcweir 	}
1710*cdf0e10cSrcweir }
1711*cdf0e10cSrcweir 
1712*cdf0e10cSrcweir //------------------------------------------------------------------------------
1713*cdf0e10cSrcweir void FmXGridPeer::removeColumnListeners(const Reference< XPropertySet >& xCol)
1714*cdf0e10cSrcweir {
1715*cdf0e10cSrcweir 	// the same props as in addColumnListeners ... linux has problems with global static UStrings, so
1716*cdf0e10cSrcweir 	// we have to do it this way ....
1717*cdf0e10cSrcweir 	static ::rtl::OUString aPropsListenedTo[] =
1718*cdf0e10cSrcweir 	{
1719*cdf0e10cSrcweir 		FM_PROP_LABEL, FM_PROP_WIDTH, FM_PROP_HIDDEN, FM_PROP_ALIGN, FM_PROP_FORMATKEY
1720*cdf0e10cSrcweir 	};
1721*cdf0e10cSrcweir 
1722*cdf0e10cSrcweir 	Reference< XPropertySetInfo >  xInfo = xCol->getPropertySetInfo();
1723*cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<sizeof(aPropsListenedTo)/sizeof(aPropsListenedTo[0]); ++i)
1724*cdf0e10cSrcweir 		if (xInfo->hasPropertyByName(aPropsListenedTo[i]))
1725*cdf0e10cSrcweir 			xCol->removePropertyChangeListener(aPropsListenedTo[i], this);
1726*cdf0e10cSrcweir }
1727*cdf0e10cSrcweir 
1728*cdf0e10cSrcweir //------------------------------------------------------------------------------
1729*cdf0e10cSrcweir void FmXGridPeer::setColumns(const Reference< XIndexContainer >& Columns) throw( RuntimeException )
1730*cdf0e10cSrcweir {
1731*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1732*cdf0e10cSrcweir 
1733*cdf0e10cSrcweir 	FmGridControl* pGrid = static_cast< FmGridControl* >( GetWindow() );
1734*cdf0e10cSrcweir 
1735*cdf0e10cSrcweir 	if (m_xColumns.is())
1736*cdf0e10cSrcweir 	{
1737*cdf0e10cSrcweir 		Reference< XPropertySet > xCol;
1738*cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < m_xColumns->getCount(); i++)
1739*cdf0e10cSrcweir 		{
1740*cdf0e10cSrcweir 			::cppu::extractInterface(xCol, m_xColumns->getByIndex(i));
1741*cdf0e10cSrcweir 			removeColumnListeners(xCol);
1742*cdf0e10cSrcweir 		}
1743*cdf0e10cSrcweir 		Reference< XContainer >  xContainer(m_xColumns, UNO_QUERY);
1744*cdf0e10cSrcweir 		xContainer->removeContainerListener(this);
1745*cdf0e10cSrcweir 
1746*cdf0e10cSrcweir 		Reference< XSelectionSupplier >  xSelSupplier(m_xColumns, UNO_QUERY);
1747*cdf0e10cSrcweir 		xSelSupplier->removeSelectionChangeListener(this);
1748*cdf0e10cSrcweir 
1749*cdf0e10cSrcweir 		Reference< XReset >  xColumnReset(m_xColumns, UNO_QUERY);
1750*cdf0e10cSrcweir 		if (xColumnReset.is())
1751*cdf0e10cSrcweir 			xColumnReset->removeResetListener((XResetListener*)this);
1752*cdf0e10cSrcweir 	}
1753*cdf0e10cSrcweir 	if (Columns.is())
1754*cdf0e10cSrcweir 	{
1755*cdf0e10cSrcweir 		Reference< XContainer >  xContainer(Columns, UNO_QUERY);
1756*cdf0e10cSrcweir 		xContainer->addContainerListener(this);
1757*cdf0e10cSrcweir 
1758*cdf0e10cSrcweir 		Reference< XSelectionSupplier >  xSelSupplier(Columns, UNO_QUERY);
1759*cdf0e10cSrcweir 		xSelSupplier->addSelectionChangeListener(this);
1760*cdf0e10cSrcweir 
1761*cdf0e10cSrcweir 		Reference< XPropertySet >  xCol;
1762*cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < Columns->getCount(); i++)
1763*cdf0e10cSrcweir 		{
1764*cdf0e10cSrcweir 			::cppu::extractInterface(xCol, Columns->getByIndex(i));
1765*cdf0e10cSrcweir 			addColumnListeners(xCol);
1766*cdf0e10cSrcweir 		}
1767*cdf0e10cSrcweir 
1768*cdf0e10cSrcweir 		Reference< XReset >  xColumnReset(Columns, UNO_QUERY);
1769*cdf0e10cSrcweir 		if (xColumnReset.is())
1770*cdf0e10cSrcweir 			xColumnReset->addResetListener((XResetListener*)this);
1771*cdf0e10cSrcweir 	}
1772*cdf0e10cSrcweir 	m_xColumns = Columns;
1773*cdf0e10cSrcweir 	if (pGrid)
1774*cdf0e10cSrcweir 	{
1775*cdf0e10cSrcweir 		pGrid->InitColumnsByModels(m_xColumns);
1776*cdf0e10cSrcweir 
1777*cdf0e10cSrcweir 		if (m_xColumns.is())
1778*cdf0e10cSrcweir 		{
1779*cdf0e10cSrcweir 			EventObject aEvt(m_xColumns);
1780*cdf0e10cSrcweir 			selectionChanged(aEvt);
1781*cdf0e10cSrcweir 		}
1782*cdf0e10cSrcweir 	}
1783*cdf0e10cSrcweir }
1784*cdf0e10cSrcweir 
1785*cdf0e10cSrcweir //------------------------------------------------------------------------------
1786*cdf0e10cSrcweir void FmXGridPeer::setDesignMode(sal_Bool bOn) throw( RuntimeException )
1787*cdf0e10cSrcweir {
1788*cdf0e10cSrcweir 	if (bOn != isDesignMode())
1789*cdf0e10cSrcweir 	{
1790*cdf0e10cSrcweir 		Window* pWin = GetWindow();
1791*cdf0e10cSrcweir 		if (pWin)
1792*cdf0e10cSrcweir 			((FmGridControl*) pWin)->SetDesignMode(bOn);
1793*cdf0e10cSrcweir 	}
1794*cdf0e10cSrcweir 
1795*cdf0e10cSrcweir 	if (bOn)
1796*cdf0e10cSrcweir 		DisConnectFromDispatcher();
1797*cdf0e10cSrcweir 	else
1798*cdf0e10cSrcweir 		UpdateDispatches();	// will connect if not already connected and just update else
1799*cdf0e10cSrcweir }
1800*cdf0e10cSrcweir 
1801*cdf0e10cSrcweir //------------------------------------------------------------------------------
1802*cdf0e10cSrcweir sal_Bool FmXGridPeer::isDesignMode() throw( RuntimeException )
1803*cdf0e10cSrcweir {
1804*cdf0e10cSrcweir 	Window* pWin = GetWindow();
1805*cdf0e10cSrcweir 	if (pWin)
1806*cdf0e10cSrcweir 		return ((FmGridControl*) pWin)->IsDesignMode();
1807*cdf0e10cSrcweir 	else
1808*cdf0e10cSrcweir 		return sal_False;
1809*cdf0e10cSrcweir }
1810*cdf0e10cSrcweir 
1811*cdf0e10cSrcweir //------------------------------------------------------------------------------
1812*cdf0e10cSrcweir void FmXGridPeer::elementInserted(const ContainerEvent& evt) throw( RuntimeException )
1813*cdf0e10cSrcweir {
1814*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1815*cdf0e10cSrcweir 
1816*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1817*cdf0e10cSrcweir 	// Handle Column beruecksichtigen
1818*cdf0e10cSrcweir 	if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove() || m_xColumns->getCount() == ((sal_Int32)pGrid->GetModelColCount()))
1819*cdf0e10cSrcweir 		return;
1820*cdf0e10cSrcweir 
1821*cdf0e10cSrcweir 	Reference< XPropertySet >  xSet;
1822*cdf0e10cSrcweir 	::cppu::extractInterface(xSet, evt.Element);
1823*cdf0e10cSrcweir 	addColumnListeners(xSet);
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir 	Reference< XPropertySet >  xNewColumn(xSet);
1826*cdf0e10cSrcweir 	String aName = ::comphelper::getString(xNewColumn->getPropertyValue(FM_PROP_LABEL));
1827*cdf0e10cSrcweir 	Any aWidth = xNewColumn->getPropertyValue(FM_PROP_WIDTH);
1828*cdf0e10cSrcweir 	sal_Int32 nWidth = 0;
1829*cdf0e10cSrcweir 	if (aWidth >>= nWidth)
1830*cdf0e10cSrcweir 		nWidth = pGrid->LogicToPixel(Point(nWidth,0),MAP_10TH_MM).X();
1831*cdf0e10cSrcweir 
1832*cdf0e10cSrcweir 	pGrid->AppendColumn(aName, (sal_uInt16)nWidth, (sal_Int16)::comphelper::getINT32(evt.Accessor));
1833*cdf0e10cSrcweir 
1834*cdf0e10cSrcweir 	// jetzt die Spalte setzen
1835*cdf0e10cSrcweir 	DbGridColumn* pCol = pGrid->GetColumns().GetObject(::comphelper::getINT32(evt.Accessor));
1836*cdf0e10cSrcweir 	pCol->setModel(xNewColumn);
1837*cdf0e10cSrcweir 
1838*cdf0e10cSrcweir 	Any aHidden = xNewColumn->getPropertyValue(FM_PROP_HIDDEN);
1839*cdf0e10cSrcweir 	if (::comphelper::getBOOL(aHidden))
1840*cdf0e10cSrcweir 		pGrid->HideColumn(pCol->GetId());
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir     FormControlFactory( m_xServiceFactory ).initializeTextFieldLineEnds( xNewColumn );
1843*cdf0e10cSrcweir }
1844*cdf0e10cSrcweir 
1845*cdf0e10cSrcweir //------------------------------------------------------------------------------
1846*cdf0e10cSrcweir void FmXGridPeer::elementReplaced(const ContainerEvent& evt) throw( RuntimeException )
1847*cdf0e10cSrcweir {
1848*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1849*cdf0e10cSrcweir 
1850*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1851*cdf0e10cSrcweir 
1852*cdf0e10cSrcweir 	// Handle Column beruecksichtigen
1853*cdf0e10cSrcweir 	if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove())
1854*cdf0e10cSrcweir 		return;
1855*cdf0e10cSrcweir 
1856*cdf0e10cSrcweir 	Reference< XPropertySet >  xNewColumn;
1857*cdf0e10cSrcweir 	Reference< XPropertySet >  xOldColumn;
1858*cdf0e10cSrcweir 	::cppu::extractInterface(xNewColumn, evt.Element);
1859*cdf0e10cSrcweir 	::cppu::extractInterface(xOldColumn, evt.ReplacedElement);
1860*cdf0e10cSrcweir 
1861*cdf0e10cSrcweir 	sal_Bool bWasEditing = pGrid->IsEditing();
1862*cdf0e10cSrcweir 	if (bWasEditing)
1863*cdf0e10cSrcweir 		pGrid->DeactivateCell();
1864*cdf0e10cSrcweir 
1865*cdf0e10cSrcweir 	pGrid->RemoveColumn(pGrid->GetColumnIdFromModelPos((sal_uInt16)::comphelper::getINT32(evt.Accessor)));
1866*cdf0e10cSrcweir 
1867*cdf0e10cSrcweir 	removeColumnListeners(xOldColumn);
1868*cdf0e10cSrcweir 	addColumnListeners(xNewColumn);
1869*cdf0e10cSrcweir 
1870*cdf0e10cSrcweir 	String aName = ::comphelper::getString(xNewColumn->getPropertyValue(FM_PROP_LABEL));
1871*cdf0e10cSrcweir 	Any aWidth = xNewColumn->getPropertyValue(FM_PROP_WIDTH);
1872*cdf0e10cSrcweir 	sal_Int32 nWidth = 0;
1873*cdf0e10cSrcweir 	if (aWidth >>= nWidth)
1874*cdf0e10cSrcweir 		nWidth = pGrid->LogicToPixel(Point(nWidth,0),MAP_10TH_MM).X();
1875*cdf0e10cSrcweir 	sal_uInt16 nNewId = pGrid->AppendColumn(aName, (sal_uInt16)nWidth, (sal_Int16)::comphelper::getINT32(evt.Accessor));
1876*cdf0e10cSrcweir 	sal_uInt16 nNewPos = pGrid->GetModelColumnPos(nNewId);
1877*cdf0e10cSrcweir 
1878*cdf0e10cSrcweir 	// set the model of the new column
1879*cdf0e10cSrcweir 	DbGridColumn* pCol = pGrid->GetColumns().GetObject(nNewPos);
1880*cdf0e10cSrcweir 
1881*cdf0e10cSrcweir 	// for initializong this grid column, we need the fields of the grid's data source
1882*cdf0e10cSrcweir 	Reference< XColumnsSupplier > xSuppColumns;
1883*cdf0e10cSrcweir 	CursorWrapper* pGridDataSource = pGrid->getDataSource();
1884*cdf0e10cSrcweir 	if ( pGridDataSource )
1885*cdf0e10cSrcweir 		xSuppColumns = xSuppColumns.query( (Reference< XInterface >)( *pGridDataSource ) );
1886*cdf0e10cSrcweir 	Reference< XNameAccess > xColumnsByName;
1887*cdf0e10cSrcweir 	if ( xSuppColumns.is() )
1888*cdf0e10cSrcweir 		xColumnsByName = xSuppColumns->getColumns();
1889*cdf0e10cSrcweir 	Reference< XIndexAccess > xColumnsByIndex( xColumnsByName, UNO_QUERY );
1890*cdf0e10cSrcweir 
1891*cdf0e10cSrcweir 	if ( xColumnsByIndex.is() )
1892*cdf0e10cSrcweir 		pGrid->InitColumnByField( pCol, xNewColumn, xColumnsByName, xColumnsByIndex );
1893*cdf0e10cSrcweir 	else
1894*cdf0e10cSrcweir 		// the simple version, applies when the grid is not yet connected to a data source
1895*cdf0e10cSrcweir 		pCol->setModel(xNewColumn);
1896*cdf0e10cSrcweir 
1897*cdf0e10cSrcweir 	if (bWasEditing)
1898*cdf0e10cSrcweir 		pGrid->ActivateCell();
1899*cdf0e10cSrcweir }
1900*cdf0e10cSrcweir 
1901*cdf0e10cSrcweir //------------------------------------------------------------------------------
1902*cdf0e10cSrcweir void FmXGridPeer::elementRemoved(const ContainerEvent& evt) throw( RuntimeException )
1903*cdf0e10cSrcweir {
1904*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1905*cdf0e10cSrcweir 
1906*cdf0e10cSrcweir 	FmGridControl* pGrid    = (FmGridControl*) GetWindow();
1907*cdf0e10cSrcweir 
1908*cdf0e10cSrcweir 	// Handle Column beruecksichtigen
1909*cdf0e10cSrcweir 	if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove() || m_xColumns->getCount() == ((sal_Int32)pGrid->GetModelColCount()))
1910*cdf0e10cSrcweir 		return;
1911*cdf0e10cSrcweir 
1912*cdf0e10cSrcweir 	pGrid->RemoveColumn(pGrid->GetColumnIdFromModelPos((sal_uInt16)::comphelper::getINT32(evt.Accessor)));
1913*cdf0e10cSrcweir 
1914*cdf0e10cSrcweir 	Reference< XPropertySet >  xOldColumn;
1915*cdf0e10cSrcweir 	::cppu::extractInterface(xOldColumn, evt.Element);
1916*cdf0e10cSrcweir 	removeColumnListeners(xOldColumn);
1917*cdf0e10cSrcweir }
1918*cdf0e10cSrcweir 
1919*cdf0e10cSrcweir //------------------------------------------------------------------------------
1920*cdf0e10cSrcweir void FmXGridPeer::setProperty( const ::rtl::OUString& PropertyName, const Any& Value) throw( RuntimeException )
1921*cdf0e10cSrcweir {
1922*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1923*cdf0e10cSrcweir 
1924*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
1925*cdf0e10cSrcweir 
1926*cdf0e10cSrcweir 	sal_Bool bVoid = !Value.hasValue();
1927*cdf0e10cSrcweir 
1928*cdf0e10cSrcweir 	if ( 0 == PropertyName.compareTo( FM_PROP_TEXTLINECOLOR ) )
1929*cdf0e10cSrcweir 	{
1930*cdf0e10cSrcweir         ::Color aTextLineColor( bVoid ? COL_TRANSPARENT : ::comphelper::getINT32( Value ) );
1931*cdf0e10cSrcweir 		if (bVoid)
1932*cdf0e10cSrcweir 		{
1933*cdf0e10cSrcweir 			pGrid->SetTextLineColor();
1934*cdf0e10cSrcweir 			pGrid->GetDataWindow().SetTextLineColor();
1935*cdf0e10cSrcweir 		}
1936*cdf0e10cSrcweir 		else
1937*cdf0e10cSrcweir 		{
1938*cdf0e10cSrcweir 			pGrid->SetTextLineColor(aTextLineColor);
1939*cdf0e10cSrcweir 			pGrid->GetDataWindow().SetTextLineColor(aTextLineColor);
1940*cdf0e10cSrcweir 		}
1941*cdf0e10cSrcweir 
1942*cdf0e10cSrcweir 		// need to forward this to the columns
1943*cdf0e10cSrcweir 		DbGridColumns& rColumns = const_cast<DbGridColumns&>(pGrid->GetColumns());
1944*cdf0e10cSrcweir 		DbGridColumn* pLoop = rColumns.First();
1945*cdf0e10cSrcweir 		while (pLoop)
1946*cdf0e10cSrcweir 		{
1947*cdf0e10cSrcweir 			FmXGridCell* pXCell = pLoop->GetCell();
1948*cdf0e10cSrcweir 			if (pXCell)
1949*cdf0e10cSrcweir 			{
1950*cdf0e10cSrcweir 				if (bVoid)
1951*cdf0e10cSrcweir 					pXCell->SetTextLineColor();
1952*cdf0e10cSrcweir 				else
1953*cdf0e10cSrcweir 					pXCell->SetTextLineColor(aTextLineColor);
1954*cdf0e10cSrcweir 			}
1955*cdf0e10cSrcweir 
1956*cdf0e10cSrcweir 			pLoop = rColumns.Next();
1957*cdf0e10cSrcweir 		}
1958*cdf0e10cSrcweir 
1959*cdf0e10cSrcweir 		if (isDesignMode())
1960*cdf0e10cSrcweir 			pGrid->Invalidate();
1961*cdf0e10cSrcweir 	}
1962*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_FONTEMPHASISMARK ) )
1963*cdf0e10cSrcweir 	{
1964*cdf0e10cSrcweir 		Font aGridFont = pGrid->GetControlFont();
1965*cdf0e10cSrcweir 		sal_Int16 nValue = ::comphelper::getINT16(Value);
1966*cdf0e10cSrcweir         aGridFont.SetEmphasisMark( nValue );
1967*cdf0e10cSrcweir 		pGrid->SetControlFont( aGridFont );
1968*cdf0e10cSrcweir 	}
1969*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_FONTRELIEF ) )
1970*cdf0e10cSrcweir 	{
1971*cdf0e10cSrcweir 		Font aGridFont = pGrid->GetControlFont();
1972*cdf0e10cSrcweir 		sal_Int16 nValue = ::comphelper::getINT16(Value);
1973*cdf0e10cSrcweir         aGridFont.SetRelief( (FontRelief)nValue );
1974*cdf0e10cSrcweir 		pGrid->SetControlFont( aGridFont );
1975*cdf0e10cSrcweir 	}
1976*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_HELPURL ) )
1977*cdf0e10cSrcweir 	{
1978*cdf0e10cSrcweir         ::rtl::OUString sHelpURL;
1979*cdf0e10cSrcweir         OSL_VERIFY( Value >>= sHelpURL );
1980*cdf0e10cSrcweir         INetURLObject aHID( sHelpURL );
1981*cdf0e10cSrcweir         if ( aHID.GetProtocol() == INET_PROT_HID )
1982*cdf0e10cSrcweir             sHelpURL = aHID.GetURLPath();
1983*cdf0e10cSrcweir         pGrid->SetHelpId( rtl::OUStringToOString( sHelpURL, RTL_TEXTENCODING_UTF8 ) );
1984*cdf0e10cSrcweir 	}
1985*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_DISPLAYSYNCHRON ) )
1986*cdf0e10cSrcweir 	{
1987*cdf0e10cSrcweir 		pGrid->setDisplaySynchron(::comphelper::getBOOL(Value));
1988*cdf0e10cSrcweir 	}
1989*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_CURSORCOLOR ) )
1990*cdf0e10cSrcweir 	{
1991*cdf0e10cSrcweir 		if (bVoid)
1992*cdf0e10cSrcweir 			pGrid->SetCursorColor(COL_TRANSPARENT);
1993*cdf0e10cSrcweir 		else
1994*cdf0e10cSrcweir             pGrid->SetCursorColor( ::Color(::comphelper::getINT32(Value)));
1995*cdf0e10cSrcweir 		if (isDesignMode())
1996*cdf0e10cSrcweir 			pGrid->Invalidate();
1997*cdf0e10cSrcweir 	}
1998*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_ALWAYSSHOWCURSOR ) )
1999*cdf0e10cSrcweir 	{
2000*cdf0e10cSrcweir 		pGrid->EnablePermanentCursor(::comphelper::getBOOL(Value));
2001*cdf0e10cSrcweir 		if (isDesignMode())
2002*cdf0e10cSrcweir 			pGrid->Invalidate();
2003*cdf0e10cSrcweir 	}
2004*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_FONT ) )
2005*cdf0e10cSrcweir 	{
2006*cdf0e10cSrcweir 		if ( bVoid )
2007*cdf0e10cSrcweir 			pGrid->SetControlFont( Font() );
2008*cdf0e10cSrcweir 		else
2009*cdf0e10cSrcweir 		{
2010*cdf0e10cSrcweir 			::com::sun::star::awt::FontDescriptor aFont;
2011*cdf0e10cSrcweir 			if (Value >>= aFont)
2012*cdf0e10cSrcweir 			{
2013*cdf0e10cSrcweir 				Font aNewVclFont;
2014*cdf0e10cSrcweir 				if (::comphelper::operator!=(aFont, ::comphelper::getDefaultFont()))	// ist das der Default
2015*cdf0e10cSrcweir 					aNewVclFont = ImplCreateFont( aFont );
2016*cdf0e10cSrcweir 
2017*cdf0e10cSrcweir 				// need to add relief and emphasis (they're stored in a VCL-Font, but not in a FontDescriptor
2018*cdf0e10cSrcweir 				Font aOldVclFont = pGrid->GetControlFont();
2019*cdf0e10cSrcweir 				aNewVclFont.SetRelief( aOldVclFont.GetRelief() );
2020*cdf0e10cSrcweir 		        aNewVclFont.SetEmphasisMark( aOldVclFont.GetEmphasisMark() );
2021*cdf0e10cSrcweir 
2022*cdf0e10cSrcweir 				// now set it ...
2023*cdf0e10cSrcweir 				pGrid->SetControlFont( aNewVclFont );
2024*cdf0e10cSrcweir 
2025*cdf0e10cSrcweir 				// if our row-height property is void (which means "calculate it font-dependent") we have
2026*cdf0e10cSrcweir 				// to adjust the control's row height
2027*cdf0e10cSrcweir 				Reference< XPropertySet >  xModelSet(getColumns(), UNO_QUERY);
2028*cdf0e10cSrcweir 				if (xModelSet.is() && ::comphelper::hasProperty(FM_PROP_ROWHEIGHT, xModelSet))
2029*cdf0e10cSrcweir 				{
2030*cdf0e10cSrcweir 					Any aHeight = xModelSet->getPropertyValue(FM_PROP_ROWHEIGHT);
2031*cdf0e10cSrcweir 					if (!aHeight.hasValue())
2032*cdf0e10cSrcweir 						pGrid->SetDataRowHeight(0);
2033*cdf0e10cSrcweir 				}
2034*cdf0e10cSrcweir 
2035*cdf0e10cSrcweir 			}
2036*cdf0e10cSrcweir 		}
2037*cdf0e10cSrcweir 	}
2038*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_BACKGROUNDCOLOR ) )
2039*cdf0e10cSrcweir 	{
2040*cdf0e10cSrcweir 		if ( bVoid )
2041*cdf0e10cSrcweir 		{
2042*cdf0e10cSrcweir 			pGrid->SetControlBackground();
2043*cdf0e10cSrcweir 		}
2044*cdf0e10cSrcweir 		else
2045*cdf0e10cSrcweir 		{
2046*cdf0e10cSrcweir             ::Color aColor( ::comphelper::getINT32(Value) );
2047*cdf0e10cSrcweir 			pGrid->SetBackground( aColor );
2048*cdf0e10cSrcweir 			pGrid->SetControlBackground( aColor );
2049*cdf0e10cSrcweir 		}
2050*cdf0e10cSrcweir 	}
2051*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_TEXTCOLOR ) )
2052*cdf0e10cSrcweir 	{
2053*cdf0e10cSrcweir 		if ( bVoid )
2054*cdf0e10cSrcweir 		{
2055*cdf0e10cSrcweir 			pGrid->SetControlForeground();
2056*cdf0e10cSrcweir 		}
2057*cdf0e10cSrcweir 		else
2058*cdf0e10cSrcweir 		{
2059*cdf0e10cSrcweir             ::Color aColor( ::comphelper::getINT32(Value) );
2060*cdf0e10cSrcweir 			pGrid->SetTextColor( aColor );
2061*cdf0e10cSrcweir 			pGrid->SetControlForeground( aColor );
2062*cdf0e10cSrcweir 		}
2063*cdf0e10cSrcweir 	}
2064*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_ROWHEIGHT ) )
2065*cdf0e10cSrcweir 	{
2066*cdf0e10cSrcweir 		sal_Int32 nLogHeight(0);
2067*cdf0e10cSrcweir 		if (Value >>= nLogHeight)
2068*cdf0e10cSrcweir 		{
2069*cdf0e10cSrcweir 			sal_Int32 nHeight = pGrid->LogicToPixel(Point(0,nLogHeight),MAP_10TH_MM).Y();
2070*cdf0e10cSrcweir 			// take the zoom factor into account
2071*cdf0e10cSrcweir 			nHeight = pGrid->CalcZoom(nHeight);
2072*cdf0e10cSrcweir 			pGrid->SetDataRowHeight(nHeight);
2073*cdf0e10cSrcweir 		}
2074*cdf0e10cSrcweir 		else if (bVoid)
2075*cdf0e10cSrcweir 			pGrid->SetDataRowHeight(0);
2076*cdf0e10cSrcweir 	}
2077*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_HASNAVIGATION ) )
2078*cdf0e10cSrcweir 	{
2079*cdf0e10cSrcweir         sal_Bool bValue( sal_True );
2080*cdf0e10cSrcweir         OSL_VERIFY( Value >>= bValue );
2081*cdf0e10cSrcweir 		pGrid->EnableNavigationBar( bValue );
2082*cdf0e10cSrcweir 	}
2083*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_RECORDMARKER ) )
2084*cdf0e10cSrcweir 	{
2085*cdf0e10cSrcweir         sal_Bool bValue( sal_True );
2086*cdf0e10cSrcweir         OSL_VERIFY( Value >>= bValue );
2087*cdf0e10cSrcweir 		pGrid->EnableHandle( bValue );
2088*cdf0e10cSrcweir 	}
2089*cdf0e10cSrcweir 	else if ( 0 == PropertyName.compareTo( FM_PROP_ENABLED ) )
2090*cdf0e10cSrcweir 	{
2091*cdf0e10cSrcweir         sal_Bool bValue( sal_True );
2092*cdf0e10cSrcweir         OSL_VERIFY( Value >>= bValue );
2093*cdf0e10cSrcweir 		pGrid->EnableHandle( bValue );
2094*cdf0e10cSrcweir 
2095*cdf0e10cSrcweir         // Im DesignModus nur das Datenfenster disablen
2096*cdf0e10cSrcweir 		// Sonst kann das Control nicht mehr konfiguriert werden
2097*cdf0e10cSrcweir 		if (isDesignMode())
2098*cdf0e10cSrcweir 			pGrid->GetDataWindow().Enable( bValue );
2099*cdf0e10cSrcweir 		else
2100*cdf0e10cSrcweir 			pGrid->Enable( bValue );
2101*cdf0e10cSrcweir 	}
2102*cdf0e10cSrcweir 	else
2103*cdf0e10cSrcweir 		VCLXWindow::setProperty( PropertyName, Value );
2104*cdf0e10cSrcweir }
2105*cdf0e10cSrcweir 
2106*cdf0e10cSrcweir //------------------------------------------------------------------------------
2107*cdf0e10cSrcweir Reference< XAccessibleContext > FmXGridPeer::CreateAccessibleContext()
2108*cdf0e10cSrcweir {
2109*cdf0e10cSrcweir     Reference< XAccessibleContext > xContext;
2110*cdf0e10cSrcweir 
2111*cdf0e10cSrcweir     // use the AccessibleContext provided by the VCL window
2112*cdf0e10cSrcweir     Window* pGrid = GetWindow();
2113*cdf0e10cSrcweir     if ( pGrid )
2114*cdf0e10cSrcweir     {
2115*cdf0e10cSrcweir         Reference< XAccessible > xAcc( pGrid->GetAccessible( sal_True ) );
2116*cdf0e10cSrcweir         if ( xAcc.is() )
2117*cdf0e10cSrcweir             xContext = xAcc->getAccessibleContext();
2118*cdf0e10cSrcweir         // TODO: this has a slight conceptual problem:
2119*cdf0e10cSrcweir         //
2120*cdf0e10cSrcweir         // We know that the XAccessible and XAccessibleContext implementation of the browse
2121*cdf0e10cSrcweir         // box is the same (the class implements both interfaces), which, speaking strictly,
2122*cdf0e10cSrcweir         // is bad here (means when a browse box acts as UnoControl): We (the FmXGridPeer) are
2123*cdf0e10cSrcweir         // the XAccessible here, and the browse box should be able to provide us an XAccessibleContext,
2124*cdf0e10cSrcweir         // but it should _not_ be the XAccessible itself.
2125*cdf0e10cSrcweir         // However, as long as no client implementation uses dirty hacks such as querying an
2126*cdf0e10cSrcweir         // XAccessibleContext for XAccessible, this should not be a problem.
2127*cdf0e10cSrcweir     }
2128*cdf0e10cSrcweir 
2129*cdf0e10cSrcweir     if ( !xContext.is() )
2130*cdf0e10cSrcweir         xContext = VCLXWindow::CreateAccessibleContext( );
2131*cdf0e10cSrcweir 
2132*cdf0e10cSrcweir     return xContext;
2133*cdf0e10cSrcweir }
2134*cdf0e10cSrcweir 
2135*cdf0e10cSrcweir //------------------------------------------------------------------------------
2136*cdf0e10cSrcweir Any FmXGridPeer::getProperty( const ::rtl::OUString& _rPropertyName ) throw( RuntimeException )
2137*cdf0e10cSrcweir {
2138*cdf0e10cSrcweir 	Any aProp;
2139*cdf0e10cSrcweir 	if (GetWindow())
2140*cdf0e10cSrcweir 	{
2141*cdf0e10cSrcweir 		FmGridControl* pGrid = (FmGridControl*) GetWindow();
2142*cdf0e10cSrcweir 		Window* pDataWindow  = &pGrid->GetDataWindow();
2143*cdf0e10cSrcweir 
2144*cdf0e10cSrcweir 		if ( 0 == _rPropertyName.compareTo( FM_PROP_NAME ) )
2145*cdf0e10cSrcweir 		{
2146*cdf0e10cSrcweir 			Font aFont = pDataWindow->GetControlFont();
2147*cdf0e10cSrcweir 			aProp <<= ImplCreateFontDescriptor( aFont );
2148*cdf0e10cSrcweir 		}
2149*cdf0e10cSrcweir 		else if ( 0 == _rPropertyName.compareTo( FM_PROP_TEXTCOLOR ) )
2150*cdf0e10cSrcweir 		{
2151*cdf0e10cSrcweir 			aProp <<= (sal_Int32)pDataWindow->GetControlForeground().GetColor();
2152*cdf0e10cSrcweir 		}
2153*cdf0e10cSrcweir 		else if ( 0 == _rPropertyName.compareTo( FM_PROP_BACKGROUNDCOLOR ) )
2154*cdf0e10cSrcweir 		{
2155*cdf0e10cSrcweir 			aProp <<= (sal_Int32)pDataWindow->GetControlBackground().GetColor();
2156*cdf0e10cSrcweir 		}
2157*cdf0e10cSrcweir 		else if ( 0 == _rPropertyName.compareTo( FM_PROP_ROWHEIGHT ) )
2158*cdf0e10cSrcweir 		{
2159*cdf0e10cSrcweir 			sal_Int32 nPixelHeight = pGrid->GetDataRowHeight();
2160*cdf0e10cSrcweir 			// take the zoom factor into account
2161*cdf0e10cSrcweir 			nPixelHeight = pGrid->CalcReverseZoom(nPixelHeight);
2162*cdf0e10cSrcweir 			aProp <<= (sal_Int32)pGrid->PixelToLogic(Point(0,nPixelHeight),MAP_10TH_MM).Y();
2163*cdf0e10cSrcweir 		}
2164*cdf0e10cSrcweir 		else if ( 0 == _rPropertyName.compareTo( FM_PROP_HASNAVIGATION ) )
2165*cdf0e10cSrcweir 		{
2166*cdf0e10cSrcweir 			sal_Bool bHasNavBar = pGrid->HasNavigationBar();
2167*cdf0e10cSrcweir 			aProp <<= (sal_Bool)bHasNavBar;
2168*cdf0e10cSrcweir 		}
2169*cdf0e10cSrcweir 		else if ( 0 == _rPropertyName.compareTo( FM_PROP_RECORDMARKER ) )
2170*cdf0e10cSrcweir 		{
2171*cdf0e10cSrcweir 			sal_Bool bHasHandle = pGrid->HasHandle();
2172*cdf0e10cSrcweir 			aProp <<= (sal_Bool)bHasHandle;
2173*cdf0e10cSrcweir 		}
2174*cdf0e10cSrcweir 		else if ( 0 == _rPropertyName.compareTo( FM_PROP_ENABLED ) )
2175*cdf0e10cSrcweir 		{
2176*cdf0e10cSrcweir 			aProp <<= (sal_Bool)pDataWindow->IsEnabled();
2177*cdf0e10cSrcweir 		}
2178*cdf0e10cSrcweir 		else
2179*cdf0e10cSrcweir 			aProp = VCLXWindow::getProperty( _rPropertyName );
2180*cdf0e10cSrcweir 	}
2181*cdf0e10cSrcweir 	return aProp;
2182*cdf0e10cSrcweir }
2183*cdf0e10cSrcweir 
2184*cdf0e10cSrcweir //------------------------------------------------------------------------------
2185*cdf0e10cSrcweir void FmXGridPeer::dispose() throw( RuntimeException )
2186*cdf0e10cSrcweir {
2187*cdf0e10cSrcweir 	EventObject aEvt;
2188*cdf0e10cSrcweir 	aEvt.Source = static_cast< ::cppu::OWeakObject* >(this);
2189*cdf0e10cSrcweir 	m_aModifyListeners.disposeAndClear(aEvt);
2190*cdf0e10cSrcweir 	m_aUpdateListeners.disposeAndClear(aEvt);
2191*cdf0e10cSrcweir 	m_aContainerListeners.disposeAndClear(aEvt);
2192*cdf0e10cSrcweir 	VCLXWindow::dispose();
2193*cdf0e10cSrcweir 
2194*cdf0e10cSrcweir 	// release all interceptors
2195*cdf0e10cSrcweir 	// discovered during #100312# - 2002-10-23 - fs@openoffice.org
2196*cdf0e10cSrcweir 	Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor );
2197*cdf0e10cSrcweir 	m_xFirstDispatchInterceptor.clear();
2198*cdf0e10cSrcweir 	while ( xInterceptor.is() )
2199*cdf0e10cSrcweir 	{
2200*cdf0e10cSrcweir 		// tell the interceptor it has a new (means no) predecessor
2201*cdf0e10cSrcweir 		xInterceptor->setMasterDispatchProvider( NULL );
2202*cdf0e10cSrcweir 
2203*cdf0e10cSrcweir 		// ask for it's successor
2204*cdf0e10cSrcweir 		Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider();
2205*cdf0e10cSrcweir 		// and give it the new (means no) successoert
2206*cdf0e10cSrcweir 		xInterceptor->setSlaveDispatchProvider( NULL );
2207*cdf0e10cSrcweir 
2208*cdf0e10cSrcweir 		// start over with the next chain element
2209*cdf0e10cSrcweir 		xInterceptor = xInterceptor.query( xSlave );
2210*cdf0e10cSrcweir 	}
2211*cdf0e10cSrcweir 
2212*cdf0e10cSrcweir 	DisConnectFromDispatcher();
2213*cdf0e10cSrcweir 	setRowSet(Reference< XRowSet > ());
2214*cdf0e10cSrcweir }
2215*cdf0e10cSrcweir 
2216*cdf0e10cSrcweir // XContainer
2217*cdf0e10cSrcweir //------------------------------------------------------------------------------
2218*cdf0e10cSrcweir void FmXGridPeer::addContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException )
2219*cdf0e10cSrcweir {
2220*cdf0e10cSrcweir 	m_aContainerListeners.addInterface( l );
2221*cdf0e10cSrcweir }
2222*cdf0e10cSrcweir //------------------------------------------------------------------------------
2223*cdf0e10cSrcweir void FmXGridPeer::removeContainerListener(const Reference< XContainerListener >& l) throw( RuntimeException )
2224*cdf0e10cSrcweir {
2225*cdf0e10cSrcweir 	m_aContainerListeners.removeInterface( l );
2226*cdf0e10cSrcweir }
2227*cdf0e10cSrcweir 
2228*cdf0e10cSrcweir // ::com::sun::star::data::XDatabaseCursorSupplier
2229*cdf0e10cSrcweir //------------------------------------------------------------------------------
2230*cdf0e10cSrcweir void FmXGridPeer::startCursorListening()
2231*cdf0e10cSrcweir {
2232*cdf0e10cSrcweir 	if (!m_nCursorListening)
2233*cdf0e10cSrcweir 	{
2234*cdf0e10cSrcweir 		Reference< XRowSet >  xRowSet(m_xCursor, UNO_QUERY);
2235*cdf0e10cSrcweir 		if (xRowSet.is())
2236*cdf0e10cSrcweir 			xRowSet->addRowSetListener(this);
2237*cdf0e10cSrcweir 
2238*cdf0e10cSrcweir 		Reference< XReset >  xReset(m_xCursor, UNO_QUERY);
2239*cdf0e10cSrcweir 		if (xReset.is())
2240*cdf0e10cSrcweir 			xReset->addResetListener(this);
2241*cdf0e10cSrcweir 
2242*cdf0e10cSrcweir 		// alle Listener anmelden
2243*cdf0e10cSrcweir 		Reference< XPropertySet >  xSet(m_xCursor, UNO_QUERY);
2244*cdf0e10cSrcweir 		if (xSet.is())
2245*cdf0e10cSrcweir 		{
2246*cdf0e10cSrcweir 			xSet->addPropertyChangeListener(FM_PROP_ISMODIFIED, this);
2247*cdf0e10cSrcweir 			xSet->addPropertyChangeListener(FM_PROP_ROWCOUNT, this);
2248*cdf0e10cSrcweir 		}
2249*cdf0e10cSrcweir 	}
2250*cdf0e10cSrcweir 	m_nCursorListening++;
2251*cdf0e10cSrcweir }
2252*cdf0e10cSrcweir 
2253*cdf0e10cSrcweir //------------------------------------------------------------------------------
2254*cdf0e10cSrcweir void FmXGridPeer::stopCursorListening()
2255*cdf0e10cSrcweir {
2256*cdf0e10cSrcweir 	if (!--m_nCursorListening)
2257*cdf0e10cSrcweir 	{
2258*cdf0e10cSrcweir 		Reference< XRowSet >  xRowSet(m_xCursor, UNO_QUERY);
2259*cdf0e10cSrcweir 		if (xRowSet.is())
2260*cdf0e10cSrcweir 			xRowSet->removeRowSetListener(this);
2261*cdf0e10cSrcweir 
2262*cdf0e10cSrcweir 		Reference< XReset >  xReset(m_xCursor, UNO_QUERY);
2263*cdf0e10cSrcweir 		if (xReset.is())
2264*cdf0e10cSrcweir 			xReset->removeResetListener(this);
2265*cdf0e10cSrcweir 
2266*cdf0e10cSrcweir 		Reference< XPropertySet >  xSet(m_xCursor, UNO_QUERY);
2267*cdf0e10cSrcweir 		if (xSet.is())
2268*cdf0e10cSrcweir 		{
2269*cdf0e10cSrcweir 			xSet->removePropertyChangeListener(FM_PROP_ISMODIFIED, this);
2270*cdf0e10cSrcweir 			xSet->removePropertyChangeListener(FM_PROP_ROWCOUNT, this);
2271*cdf0e10cSrcweir 		}
2272*cdf0e10cSrcweir 	}
2273*cdf0e10cSrcweir }
2274*cdf0e10cSrcweir 
2275*cdf0e10cSrcweir //------------------------------------------------------------------------------
2276*cdf0e10cSrcweir void FmXGridPeer::updateGrid(const Reference< XRowSet >& _rxCursor)
2277*cdf0e10cSrcweir {
2278*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*)GetWindow();
2279*cdf0e10cSrcweir 	if (pGrid)
2280*cdf0e10cSrcweir 		pGrid->setDataSource(_rxCursor);
2281*cdf0e10cSrcweir }
2282*cdf0e10cSrcweir 
2283*cdf0e10cSrcweir //------------------------------------------------------------------------------
2284*cdf0e10cSrcweir Reference< XRowSet >  FmXGridPeer::getRowSet() throw( RuntimeException )
2285*cdf0e10cSrcweir {
2286*cdf0e10cSrcweir 	return m_xCursor;
2287*cdf0e10cSrcweir }
2288*cdf0e10cSrcweir 
2289*cdf0e10cSrcweir //------------------------------------------------------------------------------
2290*cdf0e10cSrcweir void FmXGridPeer::setRowSet(const Reference< XRowSet >& _rDatabaseCursor) throw( RuntimeException )
2291*cdf0e10cSrcweir {
2292*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2293*cdf0e10cSrcweir 	if (!pGrid || !m_xColumns.is() || !m_xColumns->getCount())
2294*cdf0e10cSrcweir 		return;
2295*cdf0e10cSrcweir 	// alle Listener abmelden
2296*cdf0e10cSrcweir 	if (m_xCursor.is())
2297*cdf0e10cSrcweir 	{
2298*cdf0e10cSrcweir 		Reference< XLoadable >  xLoadable(m_xCursor, UNO_QUERY);
2299*cdf0e10cSrcweir 		// only if the form is loaded we set the rowset
2300*cdf0e10cSrcweir 		if (xLoadable.is())
2301*cdf0e10cSrcweir 		{
2302*cdf0e10cSrcweir 			stopCursorListening();
2303*cdf0e10cSrcweir 			xLoadable->removeLoadListener(this);
2304*cdf0e10cSrcweir 		}
2305*cdf0e10cSrcweir 	}
2306*cdf0e10cSrcweir 
2307*cdf0e10cSrcweir 	m_xCursor = _rDatabaseCursor;
2308*cdf0e10cSrcweir 
2309*cdf0e10cSrcweir 	if (pGrid)
2310*cdf0e10cSrcweir 	{
2311*cdf0e10cSrcweir 		Reference< XLoadable >  xLoadable(m_xCursor, UNO_QUERY);
2312*cdf0e10cSrcweir 		// only if the form is loaded we set the rowset
2313*cdf0e10cSrcweir 		if (xLoadable.is() && xLoadable->isLoaded())
2314*cdf0e10cSrcweir 			pGrid->setDataSource(m_xCursor);
2315*cdf0e10cSrcweir 		else
2316*cdf0e10cSrcweir 			pGrid->setDataSource(Reference< XRowSet > ());
2317*cdf0e10cSrcweir 
2318*cdf0e10cSrcweir 		if (xLoadable.is())
2319*cdf0e10cSrcweir 		{
2320*cdf0e10cSrcweir 			startCursorListening();
2321*cdf0e10cSrcweir 			xLoadable->addLoadListener(this);
2322*cdf0e10cSrcweir 		}
2323*cdf0e10cSrcweir 	}
2324*cdf0e10cSrcweir }
2325*cdf0e10cSrcweir 
2326*cdf0e10cSrcweir //------------------------------------------------------------------------------
2327*cdf0e10cSrcweir void SAL_CALL FmXGridPeer::addGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException )
2328*cdf0e10cSrcweir {
2329*cdf0e10cSrcweir     m_aGridControlListeners.addInterface( _listener );
2330*cdf0e10cSrcweir }
2331*cdf0e10cSrcweir 
2332*cdf0e10cSrcweir //------------------------------------------------------------------------------
2333*cdf0e10cSrcweir void SAL_CALL FmXGridPeer::removeGridControlListener( const Reference< XGridControlListener >& _listener ) throw( RuntimeException )
2334*cdf0e10cSrcweir {
2335*cdf0e10cSrcweir     m_aGridControlListeners.removeInterface( _listener );
2336*cdf0e10cSrcweir }
2337*cdf0e10cSrcweir 
2338*cdf0e10cSrcweir //------------------------------------------------------------------------------
2339*cdf0e10cSrcweir sal_Int16 FmXGridPeer::getCurrentColumnPosition() throw( RuntimeException )
2340*cdf0e10cSrcweir {
2341*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2342*cdf0e10cSrcweir 	return pGrid ? pGrid->GetViewColumnPos(pGrid->GetCurColumnId()) : -1;
2343*cdf0e10cSrcweir }
2344*cdf0e10cSrcweir 
2345*cdf0e10cSrcweir //------------------------------------------------------------------------------
2346*cdf0e10cSrcweir void FmXGridPeer::setCurrentColumnPosition(sal_Int16 nPos) throw( RuntimeException )
2347*cdf0e10cSrcweir {
2348*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2349*cdf0e10cSrcweir 	if (pGrid)
2350*cdf0e10cSrcweir 		pGrid->GoToColumnId(pGrid->GetColumnIdFromViewPos(nPos));
2351*cdf0e10cSrcweir }
2352*cdf0e10cSrcweir 
2353*cdf0e10cSrcweir //------------------------------------------------------------------------------
2354*cdf0e10cSrcweir void FmXGridPeer::selectionChanged(const EventObject& evt) throw( RuntimeException )
2355*cdf0e10cSrcweir {
2356*cdf0e10cSrcweir 	::vos::OGuard aGuard(Application::GetSolarMutex());
2357*cdf0e10cSrcweir 
2358*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2359*cdf0e10cSrcweir 	if (pGrid)
2360*cdf0e10cSrcweir 	{
2361*cdf0e10cSrcweir 		Reference< ::com::sun::star::view::XSelectionSupplier >  xSelSupplier(evt.Source, UNO_QUERY);
2362*cdf0e10cSrcweir 		Any aSelection = xSelSupplier->getSelection();
2363*cdf0e10cSrcweir 		DBG_ASSERT(aSelection.getValueType().getTypeClass() == TypeClass_INTERFACE, "FmXGridPeer::selectionChanged : invalid selection !");
2364*cdf0e10cSrcweir 		Reference< XPropertySet >  xSelection;
2365*cdf0e10cSrcweir 		 aSelection >>= xSelection;
2366*cdf0e10cSrcweir 		if (xSelection.is())
2367*cdf0e10cSrcweir 		{
2368*cdf0e10cSrcweir 			Reference< XPropertySet > xCol;
2369*cdf0e10cSrcweir 			sal_Int32 i = 0;
2370*cdf0e10cSrcweir 			sal_Int32 nColCount = m_xColumns->getCount();
2371*cdf0e10cSrcweir 
2372*cdf0e10cSrcweir 			for (; i < nColCount; ++i)
2373*cdf0e10cSrcweir 			{
2374*cdf0e10cSrcweir 				m_xColumns->getByIndex(i) >>= xCol;
2375*cdf0e10cSrcweir 				if ( xCol == xSelection )
2376*cdf0e10cSrcweir 				{
2377*cdf0e10cSrcweir 					pGrid->markColumn(pGrid->GetColumnIdFromModelPos((sal_uInt16)i));
2378*cdf0e10cSrcweir 					break;
2379*cdf0e10cSrcweir 				}
2380*cdf0e10cSrcweir 			}
2381*cdf0e10cSrcweir 			// fuer das VCL-Control muessen die Columns 1-basiert sein
2382*cdf0e10cSrcweir 			// die Selektion an das VCL-Control weiterreichen, wenn noetig
2383*cdf0e10cSrcweir 			if ( i != pGrid->GetSelectedColumn() )
2384*cdf0e10cSrcweir 			{	// (wenn das nicht greift, wurde das selectionChanged implizit von dem Control selber ausgeloest
2385*cdf0e10cSrcweir 				if ( i < nColCount )
2386*cdf0e10cSrcweir 				{
2387*cdf0e10cSrcweir 					pGrid->SelectColumnPos(pGrid->GetViewColumnPos(pGrid->GetColumnIdFromModelPos( (sal_uInt16)i )) + 1, sal_True);
2388*cdf0e10cSrcweir 					// SelectColumnPos hat wieder zu einem impliziten ActivateCell gefuehrt
2389*cdf0e10cSrcweir 					if (pGrid->IsEditing())
2390*cdf0e10cSrcweir 						pGrid->DeactivateCell();
2391*cdf0e10cSrcweir 				}
2392*cdf0e10cSrcweir 				else
2393*cdf0e10cSrcweir 					pGrid->SetNoSelection();
2394*cdf0e10cSrcweir 			}
2395*cdf0e10cSrcweir 		}
2396*cdf0e10cSrcweir 		else
2397*cdf0e10cSrcweir 			pGrid->markColumn(USHRT_MAX);
2398*cdf0e10cSrcweir 	}
2399*cdf0e10cSrcweir }
2400*cdf0e10cSrcweir 
2401*cdf0e10cSrcweir // XElementAccess
2402*cdf0e10cSrcweir //------------------------------------------------------------------------------
2403*cdf0e10cSrcweir sal_Bool FmXGridPeer::hasElements() throw( RuntimeException )
2404*cdf0e10cSrcweir {
2405*cdf0e10cSrcweir 	return getCount() != 0;
2406*cdf0e10cSrcweir }
2407*cdf0e10cSrcweir 
2408*cdf0e10cSrcweir //------------------------------------------------------------------------------
2409*cdf0e10cSrcweir Type SAL_CALL FmXGridPeer::getElementType(  ) throw(RuntimeException)
2410*cdf0e10cSrcweir {
2411*cdf0e10cSrcweir 	return ::getCppuType((Reference< ::com::sun::star::awt::XControl> *)NULL);
2412*cdf0e10cSrcweir }
2413*cdf0e10cSrcweir 
2414*cdf0e10cSrcweir // XEnumerationAccess
2415*cdf0e10cSrcweir //------------------------------------------------------------------------------
2416*cdf0e10cSrcweir Reference< XEnumeration >  FmXGridPeer::createEnumeration() throw( RuntimeException )
2417*cdf0e10cSrcweir {
2418*cdf0e10cSrcweir 	return new ::comphelper::OEnumerationByIndex(this);
2419*cdf0e10cSrcweir }
2420*cdf0e10cSrcweir 
2421*cdf0e10cSrcweir // XIndexAccess
2422*cdf0e10cSrcweir //------------------------------------------------------------------------------
2423*cdf0e10cSrcweir sal_Int32 FmXGridPeer::getCount() throw( RuntimeException )
2424*cdf0e10cSrcweir {
2425*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2426*cdf0e10cSrcweir 	if (pGrid)
2427*cdf0e10cSrcweir 		return pGrid->GetViewColCount();
2428*cdf0e10cSrcweir 	else
2429*cdf0e10cSrcweir 		return 0;
2430*cdf0e10cSrcweir }
2431*cdf0e10cSrcweir 
2432*cdf0e10cSrcweir //------------------------------------------------------------------------------
2433*cdf0e10cSrcweir Any FmXGridPeer::getByIndex(sal_Int32 _nIndex) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
2434*cdf0e10cSrcweir {
2435*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2436*cdf0e10cSrcweir 	if (_nIndex < 0 ||
2437*cdf0e10cSrcweir 		_nIndex >= getCount() || !pGrid)
2438*cdf0e10cSrcweir 		throw IndexOutOfBoundsException();
2439*cdf0e10cSrcweir 
2440*cdf0e10cSrcweir 	Any aElement;
2441*cdf0e10cSrcweir 	// get the columnid
2442*cdf0e10cSrcweir 	sal_uInt16 nId = pGrid->GetColumnIdFromViewPos((sal_uInt16)_nIndex);
2443*cdf0e10cSrcweir 	// get the list position
2444*cdf0e10cSrcweir 	sal_uInt16 nPos = pGrid->GetModelColumnPos(nId);
2445*cdf0e10cSrcweir 
2446*cdf0e10cSrcweir 	DbGridColumn* pCol = pGrid->GetColumns().GetObject(nPos);
2447*cdf0e10cSrcweir //	DBG_ASSERT(pCol && pCol->GetCell(), "FmXGridPeer::getByIndex(): Invalid cell");
2448*cdf0e10cSrcweir 	Reference< ::com::sun::star::awt::XControl >  xControl(pCol->GetCell());
2449*cdf0e10cSrcweir 	aElement <<= xControl;
2450*cdf0e10cSrcweir 
2451*cdf0e10cSrcweir 	return aElement;
2452*cdf0e10cSrcweir }
2453*cdf0e10cSrcweir 
2454*cdf0e10cSrcweir // ::com::sun::star::util::XModeSelector
2455*cdf0e10cSrcweir //------------------------------------------------------------------------------
2456*cdf0e10cSrcweir void FmXGridPeer::setMode(const ::rtl::OUString& Mode) throw( NoSupportException, RuntimeException )
2457*cdf0e10cSrcweir {
2458*cdf0e10cSrcweir 	if (!supportsMode(Mode))
2459*cdf0e10cSrcweir 		throw NoSupportException();
2460*cdf0e10cSrcweir 
2461*cdf0e10cSrcweir 	if (Mode == m_aMode)
2462*cdf0e10cSrcweir 		return;
2463*cdf0e10cSrcweir 
2464*cdf0e10cSrcweir 	m_aMode = Mode;
2465*cdf0e10cSrcweir 
2466*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2467*cdf0e10cSrcweir 	if ( Mode == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterMode" ) ) )
2468*cdf0e10cSrcweir 		pGrid->SetFilterMode(sal_True);
2469*cdf0e10cSrcweir 	else
2470*cdf0e10cSrcweir 	{
2471*cdf0e10cSrcweir 		pGrid->SetFilterMode(sal_False);
2472*cdf0e10cSrcweir 		pGrid->setDataSource(m_xCursor);
2473*cdf0e10cSrcweir 	}
2474*cdf0e10cSrcweir }
2475*cdf0e10cSrcweir 
2476*cdf0e10cSrcweir //------------------------------------------------------------------------------
2477*cdf0e10cSrcweir ::rtl::OUString FmXGridPeer::getMode() throw( RuntimeException )
2478*cdf0e10cSrcweir {
2479*cdf0e10cSrcweir 	return m_aMode;
2480*cdf0e10cSrcweir }
2481*cdf0e10cSrcweir 
2482*cdf0e10cSrcweir //------------------------------------------------------------------------------
2483*cdf0e10cSrcweir ::comphelper::StringSequence FmXGridPeer::getSupportedModes() throw( RuntimeException )
2484*cdf0e10cSrcweir {
2485*cdf0e10cSrcweir 	static ::comphelper::StringSequence aModes;
2486*cdf0e10cSrcweir 	if (!aModes.getLength())
2487*cdf0e10cSrcweir 	{
2488*cdf0e10cSrcweir 		aModes.realloc(2);
2489*cdf0e10cSrcweir 		::rtl::OUString* pModes = aModes.getArray();
2490*cdf0e10cSrcweir 		pModes[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) );
2491*cdf0e10cSrcweir 		pModes[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterMode" ) );
2492*cdf0e10cSrcweir 	}
2493*cdf0e10cSrcweir 	return aModes;
2494*cdf0e10cSrcweir }
2495*cdf0e10cSrcweir 
2496*cdf0e10cSrcweir //------------------------------------------------------------------------------
2497*cdf0e10cSrcweir sal_Bool FmXGridPeer::supportsMode(const ::rtl::OUString& Mode) throw( RuntimeException )
2498*cdf0e10cSrcweir {
2499*cdf0e10cSrcweir 	::comphelper::StringSequence aModes(getSupportedModes());
2500*cdf0e10cSrcweir 	const ::rtl::OUString* pModes = aModes.getConstArray();
2501*cdf0e10cSrcweir 	for (sal_Int32 i = aModes.getLength(); i > 0; )
2502*cdf0e10cSrcweir 	{
2503*cdf0e10cSrcweir 		if (pModes[--i] == Mode)
2504*cdf0e10cSrcweir 			return sal_True;
2505*cdf0e10cSrcweir 	}
2506*cdf0e10cSrcweir 	return sal_False;
2507*cdf0e10cSrcweir }
2508*cdf0e10cSrcweir 
2509*cdf0e10cSrcweir //------------------------------------------------------------------------------
2510*cdf0e10cSrcweir void FmXGridPeer::columnVisible(DbGridColumn* pColumn)
2511*cdf0e10cSrcweir {
2512*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2513*cdf0e10cSrcweir 
2514*cdf0e10cSrcweir 	sal_Int32 _nIndex = pGrid->GetModelColumnPos(pColumn->GetId());
2515*cdf0e10cSrcweir 	Reference< ::com::sun::star::awt::XControl >  xControl(pColumn->GetCell());
2516*cdf0e10cSrcweir 	ContainerEvent aEvt;
2517*cdf0e10cSrcweir 	aEvt.Source   = (XContainer*)this;
2518*cdf0e10cSrcweir 	aEvt.Accessor <<= _nIndex;
2519*cdf0e10cSrcweir 	aEvt.Element  <<= xControl;
2520*cdf0e10cSrcweir 
2521*cdf0e10cSrcweir     m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvt );
2522*cdf0e10cSrcweir }
2523*cdf0e10cSrcweir 
2524*cdf0e10cSrcweir //------------------------------------------------------------------------------
2525*cdf0e10cSrcweir void FmXGridPeer::columnHidden(DbGridColumn* pColumn)
2526*cdf0e10cSrcweir {
2527*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2528*cdf0e10cSrcweir 
2529*cdf0e10cSrcweir 	sal_Int32 _nIndex = pGrid->GetModelColumnPos(pColumn->GetId());
2530*cdf0e10cSrcweir 	Reference< ::com::sun::star::awt::XControl >  xControl(pColumn->GetCell());
2531*cdf0e10cSrcweir 	ContainerEvent aEvt;
2532*cdf0e10cSrcweir 	aEvt.Source   = (XContainer*)this;
2533*cdf0e10cSrcweir 	aEvt.Accessor <<= _nIndex;
2534*cdf0e10cSrcweir 	aEvt.Element  <<= xControl;
2535*cdf0e10cSrcweir 
2536*cdf0e10cSrcweir     m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvt );
2537*cdf0e10cSrcweir }
2538*cdf0e10cSrcweir 
2539*cdf0e10cSrcweir //------------------------------------------------------------------------------
2540*cdf0e10cSrcweir void FmXGridPeer::draw( sal_Int32 x, sal_Int32 y ) throw( RuntimeException )
2541*cdf0e10cSrcweir {
2542*cdf0e10cSrcweir 	FmGridControl* pGrid = (FmGridControl*) GetWindow();
2543*cdf0e10cSrcweir 	sal_Int32 nOldFlags = pGrid->GetBrowserFlags();
2544*cdf0e10cSrcweir 	pGrid->SetBrowserFlags(nOldFlags | EBBF_NOROWPICTURE);
2545*cdf0e10cSrcweir 
2546*cdf0e10cSrcweir 	VCLXWindow::draw(x, y);
2547*cdf0e10cSrcweir 
2548*cdf0e10cSrcweir 	pGrid->SetBrowserFlags(nOldFlags);
2549*cdf0e10cSrcweir }
2550*cdf0e10cSrcweir 
2551*cdf0e10cSrcweir //------------------------------------------------------------------------------
2552*cdf0e10cSrcweir Reference< ::com::sun::star::frame::XDispatch >  FmXGridPeer::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
2553*cdf0e10cSrcweir {
2554*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatch >  xResult;
2555*cdf0e10cSrcweir 
2556*cdf0e10cSrcweir 	// first ask our interceptor chain
2557*cdf0e10cSrcweir 	if (m_xFirstDispatchInterceptor.is() && !m_bInterceptingDispatch)
2558*cdf0e10cSrcweir 	{
2559*cdf0e10cSrcweir 		m_bInterceptingDispatch = sal_True;
2560*cdf0e10cSrcweir 			// safety against recursion : as we are master of the first chain element and slave of the last one we would
2561*cdf0e10cSrcweir 			// have an infinite loop without this if no dispatcher can fullfill the rewuest)
2562*cdf0e10cSrcweir 		xResult = m_xFirstDispatchInterceptor->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
2563*cdf0e10cSrcweir 		m_bInterceptingDispatch = sal_False;
2564*cdf0e10cSrcweir 	}
2565*cdf0e10cSrcweir 
2566*cdf0e10cSrcweir 	// then ask ourself : we don't have any dispatches
2567*cdf0e10cSrcweir 	return xResult;
2568*cdf0e10cSrcweir }
2569*cdf0e10cSrcweir 
2570*cdf0e10cSrcweir //------------------------------------------------------------------------------
2571*cdf0e10cSrcweir Sequence< Reference< ::com::sun::star::frame::XDispatch > > FmXGridPeer::queryDispatches(const Sequence< ::com::sun::star::frame::DispatchDescriptor>& aDescripts) throw( RuntimeException )
2572*cdf0e10cSrcweir {
2573*cdf0e10cSrcweir 	if (m_xFirstDispatchInterceptor.is())
2574*cdf0e10cSrcweir 		return m_xFirstDispatchInterceptor->queryDispatches(aDescripts);
2575*cdf0e10cSrcweir 
2576*cdf0e10cSrcweir 	// then ask ourself : we don't have any dispatches
2577*cdf0e10cSrcweir 	return Sequence< Reference< ::com::sun::star::frame::XDispatch > >();
2578*cdf0e10cSrcweir }
2579*cdf0e10cSrcweir 
2580*cdf0e10cSrcweir //------------------------------------------------------------------------------
2581*cdf0e10cSrcweir void FmXGridPeer::registerDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException )
2582*cdf0e10cSrcweir {
2583*cdf0e10cSrcweir 	if (_xInterceptor.is())
2584*cdf0e10cSrcweir 	{
2585*cdf0e10cSrcweir 		if (m_xFirstDispatchInterceptor.is())
2586*cdf0e10cSrcweir 		{
2587*cdf0e10cSrcweir 			Reference< ::com::sun::star::frame::XDispatchProvider > xFirstProvider(m_xFirstDispatchInterceptor, UNO_QUERY);
2588*cdf0e10cSrcweir 			// there is already an interceptor; the new one will become its master
2589*cdf0e10cSrcweir 			_xInterceptor->setSlaveDispatchProvider(xFirstProvider);
2590*cdf0e10cSrcweir 			m_xFirstDispatchInterceptor->setMasterDispatchProvider(xFirstProvider);
2591*cdf0e10cSrcweir 		}
2592*cdf0e10cSrcweir 		else
2593*cdf0e10cSrcweir 		{
2594*cdf0e10cSrcweir 			// it is the first interceptor; set ourself as slave
2595*cdf0e10cSrcweir 			_xInterceptor->setSlaveDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this);
2596*cdf0e10cSrcweir 		}
2597*cdf0e10cSrcweir 
2598*cdf0e10cSrcweir 		// we are the master of the chain's first interceptor
2599*cdf0e10cSrcweir 		m_xFirstDispatchInterceptor = _xInterceptor;
2600*cdf0e10cSrcweir 		m_xFirstDispatchInterceptor->setMasterDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this);
2601*cdf0e10cSrcweir 
2602*cdf0e10cSrcweir 		// we have a new interceptor and we're alive ?
2603*cdf0e10cSrcweir 		if (!isDesignMode())
2604*cdf0e10cSrcweir 			// -> check for new dispatchers
2605*cdf0e10cSrcweir 			UpdateDispatches();
2606*cdf0e10cSrcweir 	}
2607*cdf0e10cSrcweir }
2608*cdf0e10cSrcweir 
2609*cdf0e10cSrcweir //------------------------------------------------------------------------------
2610*cdf0e10cSrcweir void FmXGridPeer::releaseDispatchProviderInterceptor(const Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& _xInterceptor) throw( RuntimeException )
2611*cdf0e10cSrcweir {
2612*cdf0e10cSrcweir 	if (!_xInterceptor.is())
2613*cdf0e10cSrcweir 		return;
2614*cdf0e10cSrcweir 
2615*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >  xChainWalk(m_xFirstDispatchInterceptor);
2616*cdf0e10cSrcweir 
2617*cdf0e10cSrcweir 	if (m_xFirstDispatchInterceptor == _xInterceptor)
2618*cdf0e10cSrcweir 	{	// our chain will have a new first element
2619*cdf0e10cSrcweir 		Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >  xSlave(m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY);
2620*cdf0e10cSrcweir 		m_xFirstDispatchInterceptor = xSlave;
2621*cdf0e10cSrcweir 	}
2622*cdf0e10cSrcweir 	// do this before removing the interceptor from the chain as we won't know it's slave afterwards)
2623*cdf0e10cSrcweir 
2624*cdf0e10cSrcweir 	while (xChainWalk.is())
2625*cdf0e10cSrcweir 	{
2626*cdf0e10cSrcweir 		// walk along the chain of interceptors and look for the interceptor that has to be removed
2627*cdf0e10cSrcweir 		Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >  xSlave(xChainWalk->getSlaveDispatchProvider(), UNO_QUERY);
2628*cdf0e10cSrcweir 
2629*cdf0e10cSrcweir 		if (xChainWalk == _xInterceptor)
2630*cdf0e10cSrcweir 		{
2631*cdf0e10cSrcweir 			// old master may be an interceptor too
2632*cdf0e10cSrcweir 			Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >  xMaster(xChainWalk->getMasterDispatchProvider(), UNO_QUERY);
2633*cdf0e10cSrcweir 
2634*cdf0e10cSrcweir 			// unchain the interceptor that has to be removed
2635*cdf0e10cSrcweir 			xChainWalk->setSlaveDispatchProvider(Reference< ::com::sun::star::frame::XDispatchProvider > ());
2636*cdf0e10cSrcweir 			xChainWalk->setMasterDispatchProvider(Reference< ::com::sun::star::frame::XDispatchProvider > ());
2637*cdf0e10cSrcweir 
2638*cdf0e10cSrcweir 			// reconnect the chain
2639*cdf0e10cSrcweir 			if (xMaster.is())
2640*cdf0e10cSrcweir 			{
2641*cdf0e10cSrcweir 				if (xSlave.is())
2642*cdf0e10cSrcweir 					xMaster->setSlaveDispatchProvider(Reference< ::com::sun::star::frame::XDispatchProvider >::query(xSlave));
2643*cdf0e10cSrcweir 				else
2644*cdf0e10cSrcweir 					// it's the first interceptor of the chain, set ourself as slave
2645*cdf0e10cSrcweir 					xMaster->setSlaveDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this);
2646*cdf0e10cSrcweir 			}
2647*cdf0e10cSrcweir 			else
2648*cdf0e10cSrcweir 			{
2649*cdf0e10cSrcweir 				// the chain's first element was removed, set ourself as new master of the second one
2650*cdf0e10cSrcweir 				if (xSlave.is())
2651*cdf0e10cSrcweir 					xSlave->setMasterDispatchProvider((::com::sun::star::frame::XDispatchProvider*)this);
2652*cdf0e10cSrcweir 			}
2653*cdf0e10cSrcweir 		}
2654*cdf0e10cSrcweir 
2655*cdf0e10cSrcweir 		xChainWalk = xSlave;
2656*cdf0e10cSrcweir 	}
2657*cdf0e10cSrcweir 	// our interceptor chain has changed and we're alive ?
2658*cdf0e10cSrcweir 	if (!isDesignMode())
2659*cdf0e10cSrcweir 		// -> check the dispatchers
2660*cdf0e10cSrcweir 		UpdateDispatches();
2661*cdf0e10cSrcweir }
2662*cdf0e10cSrcweir 
2663*cdf0e10cSrcweir //------------------------------------------------------------------------------
2664*cdf0e10cSrcweir void FmXGridPeer::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( RuntimeException )
2665*cdf0e10cSrcweir {
2666*cdf0e10cSrcweir 	DBG_ASSERT(m_pStateCache, "FmXGridPeer::statusChanged : invalid call !");
2667*cdf0e10cSrcweir 	DBG_ASSERT(m_pDispatchers, "FmXGridPeer::statusChanged : invalid call !");
2668*cdf0e10cSrcweir 
2669*cdf0e10cSrcweir 	Sequence< ::com::sun::star::util::URL>& aUrls = getSupportedURLs();
2670*cdf0e10cSrcweir 	const ::com::sun::star::util::URL* pUrls = aUrls.getConstArray();
2671*cdf0e10cSrcweir 
2672*cdf0e10cSrcweir 	Sequence<sal_uInt16> aSlots = getSupportedGridSlots();
2673*cdf0e10cSrcweir 	const sal_uInt16* pSlots = aSlots.getConstArray();
2674*cdf0e10cSrcweir 
2675*cdf0e10cSrcweir     sal_uInt16 i;
2676*cdf0e10cSrcweir 	for (i=0; i<aUrls.getLength(); ++i, ++pUrls, ++pSlots)
2677*cdf0e10cSrcweir 	{
2678*cdf0e10cSrcweir 		if (pUrls->Main == Event.FeatureURL.Main)
2679*cdf0e10cSrcweir 		{
2680*cdf0e10cSrcweir 			DBG_ASSERT(m_pDispatchers[i] == Event.Source, "FmXGridPeer::statusChanged : the event source is a little bit suspect !");
2681*cdf0e10cSrcweir 			m_pStateCache[i] = Event.IsEnabled;
2682*cdf0e10cSrcweir 			FmGridControl* pGrid = (FmGridControl*) GetWindow();
2683*cdf0e10cSrcweir 			if (*pSlots != SID_FM_RECORD_UNDO)
2684*cdf0e10cSrcweir 				pGrid->GetNavigationBar().InvalidateState(*pSlots);
2685*cdf0e10cSrcweir 			break;
2686*cdf0e10cSrcweir 		}
2687*cdf0e10cSrcweir 	}
2688*cdf0e10cSrcweir 	DBG_ASSERT(i<aUrls.getLength(), "FmXGridPeer::statusChanged : got a call for an unknown url !");
2689*cdf0e10cSrcweir }
2690*cdf0e10cSrcweir 
2691*cdf0e10cSrcweir //------------------------------------------------------------------------------
2692*cdf0e10cSrcweir sal_Bool FmXGridPeer::approveReset(const EventObject& /*rEvent*/) throw( RuntimeException )
2693*cdf0e10cSrcweir {
2694*cdf0e10cSrcweir 	return sal_True;
2695*cdf0e10cSrcweir }
2696*cdf0e10cSrcweir 
2697*cdf0e10cSrcweir //------------------------------------------------------------------------------
2698*cdf0e10cSrcweir sal_Bool SAL_CALL FmXGridPeer::select( const Any& _rSelection ) throw (IllegalArgumentException, RuntimeException)
2699*cdf0e10cSrcweir {
2700*cdf0e10cSrcweir 	Sequence< Any > aBookmarks;
2701*cdf0e10cSrcweir 	if ( !( _rSelection >>= aBookmarks ) )
2702*cdf0e10cSrcweir 		throw IllegalArgumentException();
2703*cdf0e10cSrcweir 
2704*cdf0e10cSrcweir 	FmGridControl* pVclControl = static_cast<FmGridControl*>(GetWindow());
2705*cdf0e10cSrcweir 	return pVclControl->selectBookmarks(aBookmarks);
2706*cdf0e10cSrcweir 
2707*cdf0e10cSrcweir 	// TODO:
2708*cdf0e10cSrcweir 	// speaking strictly, we would have to adjust our model, as our ColumnSelection may have changed.
2709*cdf0e10cSrcweir 	// Our model is a XSelectionSupplier, too, it handles the selection of single columns.
2710*cdf0e10cSrcweir 	// This is somewhat strange, as selection should be a view (not a model) aspect.
2711*cdf0e10cSrcweir 	// So for a clean solution, we should handle column selection ourself, and the model shouldn't
2712*cdf0e10cSrcweir 	// deal with selection at all.
2713*cdf0e10cSrcweir }
2714*cdf0e10cSrcweir 
2715*cdf0e10cSrcweir //------------------------------------------------------------------------------
2716*cdf0e10cSrcweir Any SAL_CALL FmXGridPeer::getSelection(  ) throw (RuntimeException)
2717*cdf0e10cSrcweir {
2718*cdf0e10cSrcweir 	FmGridControl* pVclControl = static_cast<FmGridControl*>(GetWindow());
2719*cdf0e10cSrcweir 	Sequence< Any > aSelectionBookmarks = pVclControl->getSelectionBookmarks();
2720*cdf0e10cSrcweir 	return makeAny(aSelectionBookmarks);
2721*cdf0e10cSrcweir }
2722*cdf0e10cSrcweir 
2723*cdf0e10cSrcweir //------------------------------------------------------------------------------
2724*cdf0e10cSrcweir void SAL_CALL FmXGridPeer::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
2725*cdf0e10cSrcweir {
2726*cdf0e10cSrcweir 	m_aSelectionListeners.addInterface( _rxListener );
2727*cdf0e10cSrcweir }
2728*cdf0e10cSrcweir 
2729*cdf0e10cSrcweir //------------------------------------------------------------------------------
2730*cdf0e10cSrcweir void SAL_CALL FmXGridPeer::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
2731*cdf0e10cSrcweir {
2732*cdf0e10cSrcweir 	m_aSelectionListeners.removeInterface( _rxListener );
2733*cdf0e10cSrcweir }
2734*cdf0e10cSrcweir 
2735*cdf0e10cSrcweir //------------------------------------------------------------------------------
2736*cdf0e10cSrcweir void FmXGridPeer::resetted(const EventObject& rEvent) throw( RuntimeException )
2737*cdf0e10cSrcweir {
2738*cdf0e10cSrcweir 	if (m_xColumns == rEvent.Source)
2739*cdf0e10cSrcweir 	{	// my model was reset -> refresh the grid content
2740*cdf0e10cSrcweir 		FmGridControl* pGrid = (FmGridControl*)GetWindow();
2741*cdf0e10cSrcweir 		if (!pGrid)
2742*cdf0e10cSrcweir 			return;
2743*cdf0e10cSrcweir 		::vos::OGuard aGuard( Application::GetSolarMutex() );
2744*cdf0e10cSrcweir 		pGrid->resetCurrentRow();
2745*cdf0e10cSrcweir 	}
2746*cdf0e10cSrcweir 	// if the cursor fired a reset event we seem to be on the insert row
2747*cdf0e10cSrcweir 	else if (m_xCursor == rEvent.Source)
2748*cdf0e10cSrcweir 	{
2749*cdf0e10cSrcweir 		::vos::OGuard aGuard( Application::GetSolarMutex() );
2750*cdf0e10cSrcweir 		FmGridControl* pGrid = (FmGridControl*) GetWindow();
2751*cdf0e10cSrcweir 		if (pGrid && pGrid->IsOpen())
2752*cdf0e10cSrcweir 			pGrid->positioned(rEvent);
2753*cdf0e10cSrcweir 	}
2754*cdf0e10cSrcweir }
2755*cdf0e10cSrcweir 
2756*cdf0e10cSrcweir //------------------------------------------------------------------------------
2757*cdf0e10cSrcweir Sequence<sal_uInt16>& FmXGridPeer::getSupportedGridSlots()
2758*cdf0e10cSrcweir {
2759*cdf0e10cSrcweir 	static Sequence<sal_uInt16> aSupported;
2760*cdf0e10cSrcweir 	if (aSupported.getLength() == 0)
2761*cdf0e10cSrcweir 	{
2762*cdf0e10cSrcweir 		sal_uInt16 nSupported[] = {
2763*cdf0e10cSrcweir 			DbGridControl::NavigationBar::RECORD_FIRST,
2764*cdf0e10cSrcweir 			DbGridControl::NavigationBar::RECORD_PREV,
2765*cdf0e10cSrcweir 			DbGridControl::NavigationBar::RECORD_NEXT,
2766*cdf0e10cSrcweir 			DbGridControl::NavigationBar::RECORD_LAST,
2767*cdf0e10cSrcweir 			DbGridControl::NavigationBar::RECORD_NEW,
2768*cdf0e10cSrcweir 			SID_FM_RECORD_UNDO
2769*cdf0e10cSrcweir 		};
2770*cdf0e10cSrcweir 		aSupported.realloc(sizeof(nSupported)/sizeof(nSupported[0]));
2771*cdf0e10cSrcweir 		sal_uInt16* pSupported = aSupported.getArray();
2772*cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<aSupported.getLength(); ++i, ++pSupported)
2773*cdf0e10cSrcweir 			*pSupported = nSupported[i];
2774*cdf0e10cSrcweir 	}
2775*cdf0e10cSrcweir 	return aSupported;
2776*cdf0e10cSrcweir }
2777*cdf0e10cSrcweir 
2778*cdf0e10cSrcweir //------------------------------------------------------------------------------
2779*cdf0e10cSrcweir Sequence< ::com::sun::star::util::URL>& FmXGridPeer::getSupportedURLs()
2780*cdf0e10cSrcweir {
2781*cdf0e10cSrcweir 	static Sequence< ::com::sun::star::util::URL> aSupported;
2782*cdf0e10cSrcweir 	if (aSupported.getLength() == 0)
2783*cdf0e10cSrcweir 	{
2784*cdf0e10cSrcweir 		static ::rtl::OUString sSupported[] = {
2785*cdf0e10cSrcweir 			FMURL_RECORD_MOVEFIRST,
2786*cdf0e10cSrcweir 			FMURL_RECORD_MOVEPREV,
2787*cdf0e10cSrcweir 			FMURL_RECORD_MOVENEXT,
2788*cdf0e10cSrcweir 			FMURL_RECORD_MOVELAST,
2789*cdf0e10cSrcweir 			FMURL_RECORD_MOVETONEW,
2790*cdf0e10cSrcweir 			FMURL_RECORD_UNDO
2791*cdf0e10cSrcweir 		};
2792*cdf0e10cSrcweir 		aSupported.realloc(sizeof(sSupported)/sizeof(sSupported[0]));
2793*cdf0e10cSrcweir 		::com::sun::star::util::URL* pSupported = aSupported.getArray();
2794*cdf0e10cSrcweir 		sal_uInt16 i;
2795*cdf0e10cSrcweir 
2796*cdf0e10cSrcweir 		for ( i = 0; i < aSupported.getLength(); ++i, ++pSupported)
2797*cdf0e10cSrcweir 			pSupported->Complete = sSupported[i];
2798*cdf0e10cSrcweir 
2799*cdf0e10cSrcweir 		// let an ::com::sun::star::util::URL-transformer normalize the URLs
2800*cdf0e10cSrcweir 		Reference< ::com::sun::star::util::XURLTransformer >  xTransformer(
2801*cdf0e10cSrcweir 			::comphelper::getProcessServiceFactory()->createInstance(
2802*cdf0e10cSrcweir 				::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")),
2803*cdf0e10cSrcweir 			UNO_QUERY);
2804*cdf0e10cSrcweir 		pSupported = aSupported.getArray();
2805*cdf0e10cSrcweir 		if (xTransformer.is())
2806*cdf0e10cSrcweir 		{
2807*cdf0e10cSrcweir 			for (i=0; i<aSupported.getLength(); ++i)
2808*cdf0e10cSrcweir 				xTransformer->parseStrict(pSupported[i]);
2809*cdf0e10cSrcweir 		}
2810*cdf0e10cSrcweir 	}
2811*cdf0e10cSrcweir 
2812*cdf0e10cSrcweir 	return aSupported;
2813*cdf0e10cSrcweir }
2814*cdf0e10cSrcweir 
2815*cdf0e10cSrcweir //------------------------------------------------------------------------------
2816*cdf0e10cSrcweir void FmXGridPeer::UpdateDispatches()
2817*cdf0e10cSrcweir {
2818*cdf0e10cSrcweir 	if (!m_pStateCache)
2819*cdf0e10cSrcweir 	{	// we don't have any dispatchers yet -> do the initial connect
2820*cdf0e10cSrcweir 		ConnectToDispatcher();
2821*cdf0e10cSrcweir 		return;
2822*cdf0e10cSrcweir 	}
2823*cdf0e10cSrcweir 
2824*cdf0e10cSrcweir 	sal_uInt16 nDispatchersGot = 0;
2825*cdf0e10cSrcweir 	const Sequence< ::com::sun::star::util::URL>& aSupportedURLs = getSupportedURLs();
2826*cdf0e10cSrcweir 	const ::com::sun::star::util::URL* pSupportedURLs = aSupportedURLs.getConstArray();
2827*cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XDispatch >  xNewDispatch;
2828*cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs)
2829*cdf0e10cSrcweir 	{
2830*cdf0e10cSrcweir 		xNewDispatch = queryDispatch(*pSupportedURLs, rtl::OUString(), 0);
2831*cdf0e10cSrcweir 		if (xNewDispatch != m_pDispatchers[i])
2832*cdf0e10cSrcweir 		{
2833*cdf0e10cSrcweir 			if (m_pDispatchers[i].is())
2834*cdf0e10cSrcweir 				m_pDispatchers[i]->removeStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs);
2835*cdf0e10cSrcweir 			m_pDispatchers[i] = xNewDispatch;
2836*cdf0e10cSrcweir 			if (m_pDispatchers[i].is())
2837*cdf0e10cSrcweir 				m_pDispatchers[i]->addStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs);
2838*cdf0e10cSrcweir 		}
2839*cdf0e10cSrcweir 		if (m_pDispatchers[i].is())
2840*cdf0e10cSrcweir 			++nDispatchersGot;
2841*cdf0e10cSrcweir 	}
2842*cdf0e10cSrcweir 
2843*cdf0e10cSrcweir 	if (!nDispatchersGot)
2844*cdf0e10cSrcweir 	{
2845*cdf0e10cSrcweir 		delete[] m_pStateCache;
2846*cdf0e10cSrcweir 		delete[] m_pDispatchers;
2847*cdf0e10cSrcweir 		m_pStateCache = NULL;
2848*cdf0e10cSrcweir 		m_pDispatchers = NULL;
2849*cdf0e10cSrcweir 	}
2850*cdf0e10cSrcweir }
2851*cdf0e10cSrcweir 
2852*cdf0e10cSrcweir //------------------------------------------------------------------------------
2853*cdf0e10cSrcweir void FmXGridPeer::ConnectToDispatcher()
2854*cdf0e10cSrcweir {
2855*cdf0e10cSrcweir 	DBG_ASSERT((m_pStateCache != NULL) == (m_pDispatchers != NULL), "FmXGridPeer::ConnectToDispatcher : inconsistent !");
2856*cdf0e10cSrcweir 	if (m_pStateCache)
2857*cdf0e10cSrcweir 	{	// already connected -> just do an update
2858*cdf0e10cSrcweir 		UpdateDispatches();
2859*cdf0e10cSrcweir 		return;
2860*cdf0e10cSrcweir 	}
2861*cdf0e10cSrcweir 
2862*cdf0e10cSrcweir 	const Sequence< ::com::sun::star::util::URL>& aSupportedURLs = getSupportedURLs();
2863*cdf0e10cSrcweir 
2864*cdf0e10cSrcweir 	// _before_ adding the status listeners (as the add should result in a statusChanged-call) !
2865*cdf0e10cSrcweir 	m_pStateCache = new sal_Bool[aSupportedURLs.getLength()];
2866*cdf0e10cSrcweir 	m_pDispatchers = new Reference< ::com::sun::star::frame::XDispatch > [aSupportedURLs.getLength()];
2867*cdf0e10cSrcweir 
2868*cdf0e10cSrcweir 	sal_uInt16 nDispatchersGot = 0;
2869*cdf0e10cSrcweir 	const ::com::sun::star::util::URL* pSupportedURLs = aSupportedURLs.getConstArray();
2870*cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs)
2871*cdf0e10cSrcweir 	{
2872*cdf0e10cSrcweir 		m_pStateCache[i] = 0;
2873*cdf0e10cSrcweir 		m_pDispatchers[i] = queryDispatch(*pSupportedURLs, rtl::OUString(), 0);
2874*cdf0e10cSrcweir 		if (m_pDispatchers[i].is())
2875*cdf0e10cSrcweir 		{
2876*cdf0e10cSrcweir 			m_pDispatchers[i]->addStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs);
2877*cdf0e10cSrcweir 			++nDispatchersGot;
2878*cdf0e10cSrcweir 		}
2879*cdf0e10cSrcweir 	}
2880*cdf0e10cSrcweir 
2881*cdf0e10cSrcweir 	if (!nDispatchersGot)
2882*cdf0e10cSrcweir 	{
2883*cdf0e10cSrcweir 		delete[] m_pStateCache;
2884*cdf0e10cSrcweir 		delete[] m_pDispatchers;
2885*cdf0e10cSrcweir 		m_pStateCache = NULL;
2886*cdf0e10cSrcweir 		m_pDispatchers = NULL;
2887*cdf0e10cSrcweir 	}
2888*cdf0e10cSrcweir }
2889*cdf0e10cSrcweir 
2890*cdf0e10cSrcweir //------------------------------------------------------------------------------
2891*cdf0e10cSrcweir void FmXGridPeer::DisConnectFromDispatcher()
2892*cdf0e10cSrcweir {
2893*cdf0e10cSrcweir 	if (!m_pStateCache || !m_pDispatchers)
2894*cdf0e10cSrcweir 		return;
2895*cdf0e10cSrcweir 	// we're not connected
2896*cdf0e10cSrcweir 
2897*cdf0e10cSrcweir 	const Sequence< ::com::sun::star::util::URL>& aSupportedURLs = getSupportedURLs();
2898*cdf0e10cSrcweir 	const ::com::sun::star::util::URL* pSupportedURLs = aSupportedURLs.getConstArray();
2899*cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs)
2900*cdf0e10cSrcweir 	{
2901*cdf0e10cSrcweir 		if (m_pDispatchers[i].is())
2902*cdf0e10cSrcweir 			m_pDispatchers[i]->removeStatusListener((::com::sun::star::frame::XStatusListener*)this, *pSupportedURLs);
2903*cdf0e10cSrcweir 	}
2904*cdf0e10cSrcweir 
2905*cdf0e10cSrcweir 	delete[] m_pStateCache;
2906*cdf0e10cSrcweir 	delete[] m_pDispatchers;
2907*cdf0e10cSrcweir 	m_pStateCache = NULL;
2908*cdf0e10cSrcweir 	m_pDispatchers = NULL;
2909*cdf0e10cSrcweir }
2910*cdf0e10cSrcweir 
2911*cdf0e10cSrcweir //------------------------------------------------------------------------------
2912*cdf0e10cSrcweir IMPL_LINK(FmXGridPeer, OnQueryGridSlotState, void*, pSlot)
2913*cdf0e10cSrcweir {
2914*cdf0e10cSrcweir 	if (!m_pStateCache)
2915*cdf0e10cSrcweir 		return -1;	// unspecified
2916*cdf0e10cSrcweir 
2917*cdf0e10cSrcweir 	sal_uInt16 nSlot = (sal_uInt16)(sal_uIntPtr)pSlot;
2918*cdf0e10cSrcweir 
2919*cdf0e10cSrcweir 	// search the given slot with our supported sequence
2920*cdf0e10cSrcweir 	Sequence<sal_uInt16>& aSupported = getSupportedGridSlots();
2921*cdf0e10cSrcweir 	const sal_uInt16* pSlots = aSupported.getConstArray();
2922*cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<aSupported.getLength(); ++i)
2923*cdf0e10cSrcweir 	{
2924*cdf0e10cSrcweir 		if (pSlots[i] == nSlot)
2925*cdf0e10cSrcweir 		{
2926*cdf0e10cSrcweir 			if (!m_pDispatchers[i].is())
2927*cdf0e10cSrcweir 				return -1;	// nothing known about this slot
2928*cdf0e10cSrcweir 			else
2929*cdf0e10cSrcweir 				return m_pStateCache[i];
2930*cdf0e10cSrcweir 		}
2931*cdf0e10cSrcweir 	}
2932*cdf0e10cSrcweir 
2933*cdf0e10cSrcweir 	return  -1;
2934*cdf0e10cSrcweir }
2935*cdf0e10cSrcweir 
2936*cdf0e10cSrcweir //------------------------------------------------------------------------------
2937*cdf0e10cSrcweir IMPL_LINK(FmXGridPeer, OnExecuteGridSlot, void*, pSlot)
2938*cdf0e10cSrcweir {
2939*cdf0e10cSrcweir 	if (!m_pDispatchers)
2940*cdf0e10cSrcweir 		return 0;	// not handled
2941*cdf0e10cSrcweir 
2942*cdf0e10cSrcweir 	Sequence< ::com::sun::star::util::URL>& aUrls = getSupportedURLs();
2943*cdf0e10cSrcweir 	const ::com::sun::star::util::URL* pUrls = aUrls.getConstArray();
2944*cdf0e10cSrcweir 
2945*cdf0e10cSrcweir 	Sequence<sal_uInt16> aSlots = getSupportedGridSlots();
2946*cdf0e10cSrcweir 	const sal_uInt16* pSlots = aSlots.getConstArray();
2947*cdf0e10cSrcweir 
2948*cdf0e10cSrcweir 	DBG_ASSERT(aSlots.getLength() == aUrls.getLength(), "FmXGridPeer::OnExecuteGridSlot : inconstent data returned by getSupportedURLs/getSupportedGridSlots !");
2949*cdf0e10cSrcweir 
2950*cdf0e10cSrcweir 	sal_uInt16 nSlot = (sal_uInt16)(sal_uIntPtr)pSlot;
2951*cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<aSlots.getLength(); ++i, ++pUrls, ++pSlots)
2952*cdf0e10cSrcweir 	{
2953*cdf0e10cSrcweir 		if (*pSlots == nSlot)
2954*cdf0e10cSrcweir 		{
2955*cdf0e10cSrcweir 			if (m_pDispatchers[i].is())
2956*cdf0e10cSrcweir 			{
2957*cdf0e10cSrcweir 				// commit any changes done so far, if it's not the undoRecord URL
2958*cdf0e10cSrcweir 				if ( 0 == pUrls->Complete.compareTo( FMURL_RECORD_UNDO ) || commit() )
2959*cdf0e10cSrcweir 					m_pDispatchers[i]->dispatch(*pUrls, Sequence< PropertyValue>());
2960*cdf0e10cSrcweir 
2961*cdf0e10cSrcweir 				return 1;	// handled
2962*cdf0e10cSrcweir 			}
2963*cdf0e10cSrcweir 		}
2964*cdf0e10cSrcweir 	}
2965*cdf0e10cSrcweir 
2966*cdf0e10cSrcweir 	return 0;	// not handled
2967*cdf0e10cSrcweir }
2968*cdf0e10cSrcweir 
2969