1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: treedatamodel.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include "defaultgridcolumnmodel.hxx"
34 #include <comphelper/sequence.hxx>
35 #include <toolkit/helper/servicenames.hxx>
36 #include <rtl/ref.hxx>
38 using ::rtl::OUString
;
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::awt
;
42 using namespace ::com::sun::star::awt::grid
;
43 using namespace ::com::sun::star::lang
;
45 #define COLUMNSELECTIONALLOWED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnSelectionAllowed" ))
50 ///////////////////////////////////////////////////////////////////////
51 // class DefaultGridColumnModel
52 ///////////////////////////////////////////////////////////////////////
54 DefaultGridColumnModel::DefaultGridColumnModel()
55 : columns(std::vector
< Reference
< XGridColumn
> >())
59 //---------------------------------------------------------------------
61 DefaultGridColumnModel::~DefaultGridColumnModel()
65 //---------------------------------------------------------------------
67 void DefaultGridColumnModel::broadcast( broadcast_type eType
, const GridColumnEvent
& aEvent
)
69 ::cppu::OInterfaceContainerHelper
* pIter
= BrdcstHelper
.getContainer( XGridColumnListener::static_type() );
72 ::cppu::OInterfaceIteratorHelper
aListIter(*pIter
);
73 while(aListIter
.hasMoreElements())
75 XGridColumnListener
* pListener
= static_cast<XGridColumnListener
*>(aListIter
.next());
78 case column_added
: pListener
->columnAdded(aEvent
); break;
79 case column_removed
: pListener
->columnRemoved(aEvent
); break;
80 case column_changed
: pListener
->columnChanged(aEvent
); break;
86 //---------------------------------------------------------------------
88 void DefaultGridColumnModel::broadcast_changed( ::rtl::OUString name
, Any oldValue
, Any newValue
)
90 Reference
< XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
91 GridColumnEvent
aEvent( xSource
, name
, oldValue
, newValue
, 0, NULL
);
92 broadcast( column_changed
, aEvent
);
95 //---------------------------------------------------------------------
97 void DefaultGridColumnModel::broadcast_add( sal_Int32 index
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridColumn
> & rColumn
)
99 Reference
< XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
100 GridColumnEvent
aEvent( xSource
, ::rtl::OUString(), Any(), Any(), index
, rColumn
);
101 broadcast( column_added
, aEvent
);
104 //---------------------------------------------------------------------
106 void DefaultGridColumnModel::broadcast_remove( sal_Int32 index
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridColumn
> & rColumn
)
108 Reference
< XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
109 GridColumnEvent
aEvent( xSource
, ::rtl::OUString(), Any(), Any(), index
, rColumn
);
110 broadcast( column_changed
, aEvent
);
113 //---------------------------------------------------------------------
114 // XDefaultGridColumnModel
115 //---------------------------------------------------------------------
116 ::sal_Bool SAL_CALL
DefaultGridColumnModel::getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException
)
118 return selectionAllowed
;
121 //---------------------------------------------------------------------
123 void SAL_CALL
DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value
) throw (::com::sun::star::uno::RuntimeException
)
125 sal_Bool oldValue
= selectionAllowed
;
126 selectionAllowed
= value
;
127 broadcast_changed( COLUMNSELECTIONALLOWED
, Any(oldValue
) , Any(selectionAllowed
));
130 //---------------------------------------------------------------------
132 ::sal_Int32 SAL_CALL
DefaultGridColumnModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException
)
134 return columns
.size();
137 //---------------------------------------------------------------------
139 ::sal_Int32 SAL_CALL
DefaultGridColumnModel::addColumn(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridColumn
> & column
) throw (::com::sun::star::uno::RuntimeException
)
141 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
143 columns
.push_back(column
);
145 sal_Int32 index
= columns
.size() - 1;
146 broadcast_add(index
, column
);
150 //---------------------------------------------------------------------
152 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridColumn
> > SAL_CALL
DefaultGridColumnModel::getColumns() throw (::com::sun::star::uno::RuntimeException
)
154 return comphelper::containerToSequence(columns
);
157 //---------------------------------------------------------------------
159 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridColumn
> SAL_CALL
DefaultGridColumnModel::getColumn(::sal_Int32 index
) throw (::com::sun::star::uno::RuntimeException
)
161 if ( index
>=0 && index
< ((sal_Int32
)columns
.size()))
162 return columns
[index
];
164 return Reference
< XGridColumn
>();
167 void SAL_CALL
DefaultGridColumnModel::addColumnListener( const Reference
< XGridColumnListener
>& xListener
) throw (RuntimeException
)
169 BrdcstHelper
.addListener( XGridColumnListener::static_type(), xListener
);
172 //---------------------------------------------------------------------
174 void SAL_CALL
DefaultGridColumnModel::removeColumnListener( const Reference
< XGridColumnListener
>& xListener
) throw (RuntimeException
)
176 BrdcstHelper
.removeListener( XGridColumnListener::static_type(), xListener
);
179 //---------------------------------------------------------------------
181 //---------------------------------------------------------------------
183 void SAL_CALL
DefaultGridColumnModel::dispose() throw (RuntimeException
)
185 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
187 ::com::sun::star::lang::EventObject aEvent
;
188 aEvent
.Source
.set( static_cast< ::cppu::OWeakObject
* >( this ) );
189 BrdcstHelper
.aLC
.disposeAndClear( aEvent
);
193 //---------------------------------------------------------------------
195 void SAL_CALL
DefaultGridColumnModel::addEventListener( const Reference
< XEventListener
>& xListener
) throw (RuntimeException
)
197 BrdcstHelper
.addListener( XEventListener::static_type(), xListener
);
200 //---------------------------------------------------------------------
202 void SAL_CALL
DefaultGridColumnModel::removeEventListener( const Reference
< XEventListener
>& xListener
) throw (RuntimeException
)
204 BrdcstHelper
.removeListener( XEventListener::static_type(), xListener
);
207 //---------------------------------------------------------------------
209 //---------------------------------------------------------------------
211 ::rtl::OUString SAL_CALL
DefaultGridColumnModel::getImplementationName( ) throw (RuntimeException
)
213 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
214 static const OUString
aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.DefaultGridColumnModel" ) );
218 //---------------------------------------------------------------------
220 sal_Bool SAL_CALL
DefaultGridColumnModel::supportsService( const ::rtl::OUString
& ServiceName
) throw (RuntimeException
)
222 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
223 return ServiceName
.equalsAscii( szServiceName_DefaultGridColumnModel
);
226 //---------------------------------------------------------------------
228 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
DefaultGridColumnModel::getSupportedServiceNames( ) throw (RuntimeException
)
230 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
231 static const OUString
aServiceName( OUString::createFromAscii( szServiceName_DefaultGridColumnModel
) );
232 static const Sequence
< OUString
> aSeq( &aServiceName
, 1 );
238 Reference
< XInterface
> SAL_CALL
DefaultGridColumnModel_CreateInstance( const Reference
< XMultiServiceFactory
>& )
240 return Reference
< XInterface
>( ( ::cppu::OWeakObject
* ) new ::toolkit::DefaultGridColumnModel
);