2009-08-26 13:11:27 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* $RCSfile: treedatamodel.cxx,v $
|
|
|
|
* $Revision: 1.4 $
|
|
|
|
*
|
|
|
|
* This file is part of OpenOffice.org.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_toolkit.hxx"
|
|
|
|
#include "defaultgridcolumnmodel.hxx"
|
|
|
|
#include <comphelper/sequence.hxx>
|
|
|
|
#include <toolkit/helper/servicenames.hxx>
|
|
|
|
#include <rtl/ref.hxx>
|
|
|
|
|
|
|
|
using ::rtl::OUString;
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::awt;
|
|
|
|
using namespace ::com::sun::star::awt::grid;
|
|
|
|
using namespace ::com::sun::star::lang;
|
2010-02-12 17:05:02 +01:00
|
|
|
using namespace ::com::sun::star::style;
|
2009-08-26 13:11:27 +00:00
|
|
|
#define COLUMNSELECTIONALLOWED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnSelectionAllowed" ))
|
|
|
|
|
|
|
|
namespace toolkit
|
|
|
|
{
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// class DefaultGridColumnModel
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-02-12 17:05:02 +01:00
|
|
|
DefaultGridColumnModel::DefaultGridColumnModel(const Reference< XMultiServiceFactory >& xFactory)
|
2009-08-26 13:11:27 +00:00
|
|
|
: columns(std::vector< Reference< XGridColumn > >())
|
2010-02-12 17:05:02 +01:00
|
|
|
,m_nColumnHeaderHeight(10)
|
|
|
|
,m_xFactory(xFactory)
|
2009-08-26 13:11:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
DefaultGridColumnModel::~DefaultGridColumnModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DefaultGridColumnModel::broadcast( broadcast_type eType, const GridColumnEvent& aEvent )
|
|
|
|
{
|
|
|
|
::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridColumnListener::static_type() );
|
|
|
|
if( pIter )
|
|
|
|
{
|
|
|
|
::cppu::OInterfaceIteratorHelper aListIter(*pIter);
|
|
|
|
while(aListIter.hasMoreElements())
|
|
|
|
{
|
|
|
|
XGridColumnListener* pListener = static_cast<XGridColumnListener*>(aListIter.next());
|
|
|
|
switch( eType )
|
|
|
|
{
|
|
|
|
case column_added: pListener->columnAdded(aEvent); break;
|
|
|
|
case column_removed: pListener->columnRemoved(aEvent); break;
|
|
|
|
case column_changed: pListener->columnChanged(aEvent); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DefaultGridColumnModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue )
|
|
|
|
{
|
|
|
|
Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
|
|
|
|
GridColumnEvent aEvent( xSource, name, oldValue, newValue, 0, NULL );
|
|
|
|
broadcast( column_changed, aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DefaultGridColumnModel::broadcast_add( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn )
|
|
|
|
{
|
|
|
|
Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
|
|
|
|
GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn );
|
|
|
|
broadcast( column_added, aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DefaultGridColumnModel::broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn )
|
|
|
|
{
|
|
|
|
Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
|
|
|
|
GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn );
|
2010-02-12 17:05:02 +01:00
|
|
|
broadcast( column_removed, aEvent);
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// XDefaultGridColumnModel
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
::sal_Bool SAL_CALL DefaultGridColumnModel::getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return selectionAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value) throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
sal_Bool oldValue = selectionAllowed;
|
|
|
|
selectionAllowed = value;
|
|
|
|
broadcast_changed( COLUMNSELECTIONALLOWED, Any(oldValue) , Any(selectionAllowed));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
::sal_Int32 SAL_CALL DefaultGridColumnModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return columns.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
::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)
|
|
|
|
{
|
|
|
|
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
|
|
|
|
|
|
|
|
columns.push_back(column);
|
|
|
|
sal_Int32 index = columns.size() - 1;
|
|
|
|
broadcast_add(index, column );
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
::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)
|
|
|
|
{
|
|
|
|
return comphelper::containerToSequence(columns);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL DefaultGridColumnModel::getColumn(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
if ( index >=0 && index < ((sal_Int32)columns.size()))
|
|
|
|
return columns[index];
|
|
|
|
else
|
|
|
|
return Reference< XGridColumn >();
|
|
|
|
}
|
2010-02-12 17:05:02 +01:00
|
|
|
//---------------------------------------------------------------------
|
2009-08-26 13:11:27 +00:00
|
|
|
void SAL_CALL DefaultGridColumnModel::addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
BrdcstHelper.addListener( XGridColumnListener::static_type(), xListener );
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL DefaultGridColumnModel::removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
BrdcstHelper.removeListener( XGridColumnListener::static_type(), xListener );
|
|
|
|
}
|
|
|
|
|
2010-02-12 17:05:02 +01:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
void SAL_CALL DefaultGridColumnModel::setColumnHeaderHeight(sal_Int32 _value) throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
m_nColumnHeaderHeight = _value;
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL DefaultGridColumnModel::getColumnHeaderHeight() throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
return m_nColumnHeaderHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
void SAL_CALL DefaultGridColumnModel::setDefaultColumns(sal_Int32 rowElements) throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
|
|
|
|
|
|
|
|
Reference<XGridColumn> xColumn( m_xFactory->createInstance ( OUString::createFromAscii( "com.sun.star.awt.grid.GridColumn" ) ), UNO_QUERY );
|
|
|
|
for(sal_Int32 i=0;i<rowElements;i++)
|
|
|
|
columns.push_back(xColumn);
|
|
|
|
}
|
2009-08-26 13:11:27 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// XComponent
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL DefaultGridColumnModel::dispose() throw (RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
|
|
|
|
|
|
|
|
::com::sun::star::lang::EventObject aEvent;
|
|
|
|
aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) );
|
|
|
|
BrdcstHelper.aLC.disposeAndClear( aEvent );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL DefaultGridColumnModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
BrdcstHelper.addListener( XEventListener::static_type(), xListener );
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SAL_CALL DefaultGridColumnModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
BrdcstHelper.removeListener( XEventListener::static_type(), xListener );
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// XServiceInfo
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
::rtl::OUString SAL_CALL DefaultGridColumnModel::getImplementationName( ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
|
|
|
|
static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.DefaultGridColumnModel" ) );
|
|
|
|
return aImplName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL DefaultGridColumnModel::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
|
|
|
|
return ServiceName.equalsAscii( szServiceName_DefaultGridColumnModel );
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL DefaultGridColumnModel::getSupportedServiceNames( ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
|
|
|
|
static const OUString aServiceName( OUString::createFromAscii( szServiceName_DefaultGridColumnModel ) );
|
|
|
|
static const Sequence< OUString > aSeq( &aServiceName, 1 );
|
|
|
|
return aSeq;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-12 17:05:02 +01:00
|
|
|
Reference< XInterface > SAL_CALL DefaultGridColumnModel_CreateInstance( const Reference< XMultiServiceFactory >& _rFactory)
|
2009-08-26 13:11:27 +00:00
|
|
|
{
|
2010-02-12 17:05:02 +01:00
|
|
|
return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridColumnModel( _rFactory ) );
|
2009-08-26 13:11:27 +00:00
|
|
|
}
|
|
|
|
|