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