1*b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b0724fc6SAndrew Rist * distributed with this work for additional information 6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17*b0724fc6SAndrew Rist * specific language governing permissions and limitations 18*b0724fc6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b0724fc6SAndrew Rist *************************************************************/ 21*b0724fc6SAndrew Rist 22*b0724fc6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 25cdf0e10cSrcweir #include "gridcolumn.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <comphelper/sequence.hxx> 28cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 29cdf0e10cSrcweir #include <toolkit/helper/servicenames.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace toolkit 32cdf0e10cSrcweir { 33cdf0e10cSrcweir using namespace ::com::sun::star; 34cdf0e10cSrcweir using namespace ::com::sun::star::uno; 35cdf0e10cSrcweir using namespace ::com::sun::star::awt; 36cdf0e10cSrcweir using namespace ::com::sun::star::awt::grid; 37cdf0e10cSrcweir using namespace ::com::sun::star::lang; 38cdf0e10cSrcweir using namespace ::com::sun::star::util; 39cdf0e10cSrcweir using namespace ::com::sun::star::style; 40cdf0e10cSrcweir 41cdf0e10cSrcweir //================================================================================================================== 42cdf0e10cSrcweir //= DefaultGridColumnModel 43cdf0e10cSrcweir //================================================================================================================== 44cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 45cdf0e10cSrcweir GridColumn::GridColumn() 46cdf0e10cSrcweir :GridColumn_Base( m_aMutex ) 47cdf0e10cSrcweir ,m_aIdentifier() 48cdf0e10cSrcweir ,m_nIndex(-1) 49cdf0e10cSrcweir ,m_nDataColumnIndex(-1) 50cdf0e10cSrcweir ,m_nColumnWidth(4) 51cdf0e10cSrcweir ,m_nMaxWidth(0) 52cdf0e10cSrcweir ,m_nMinWidth(0) 53cdf0e10cSrcweir ,m_nFlexibility(1) 54cdf0e10cSrcweir ,m_bResizeable(true) 55cdf0e10cSrcweir ,m_eHorizontalAlign( HorizontalAlignment_LEFT ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 60cdf0e10cSrcweir GridColumn::GridColumn( GridColumn const & i_copySource ) 61cdf0e10cSrcweir :cppu::BaseMutex() 62cdf0e10cSrcweir ,GridColumn_Base( m_aMutex ) 63cdf0e10cSrcweir ,m_aIdentifier( i_copySource.m_aIdentifier ) 64cdf0e10cSrcweir ,m_nIndex( -1 ) 65cdf0e10cSrcweir ,m_nDataColumnIndex( i_copySource.m_nDataColumnIndex ) 66cdf0e10cSrcweir ,m_nColumnWidth( i_copySource.m_nColumnWidth ) 67cdf0e10cSrcweir ,m_nMaxWidth( i_copySource.m_nMaxWidth ) 68cdf0e10cSrcweir ,m_nMinWidth( i_copySource.m_nMinWidth ) 69cdf0e10cSrcweir ,m_nFlexibility( i_copySource.m_nFlexibility ) 70cdf0e10cSrcweir ,m_bResizeable( i_copySource.m_bResizeable ) 71cdf0e10cSrcweir ,m_sTitle( i_copySource.m_sTitle ) 72cdf0e10cSrcweir ,m_sHelpText( i_copySource.m_sHelpText ) 73cdf0e10cSrcweir ,m_eHorizontalAlign( i_copySource.m_eHorizontalAlign ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 78cdf0e10cSrcweir GridColumn::~GridColumn() 79cdf0e10cSrcweir { 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 83cdf0e10cSrcweir void GridColumn::broadcast_changed( sal_Char const * const i_asciiAttributeName, Any i_oldValue, Any i_newValue, 84cdf0e10cSrcweir ::comphelper::ComponentGuard& i_Guard ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir Reference< XInterface > const xSource( static_cast< ::cppu::OWeakObject* >( this ) ); 87cdf0e10cSrcweir GridColumnEvent const aEvent( 88cdf0e10cSrcweir xSource, ::rtl::OUString::createFromAscii( i_asciiAttributeName ), 89cdf0e10cSrcweir i_oldValue, i_newValue, m_nIndex 90cdf0e10cSrcweir ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( XGridColumnListener::static_type() ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir i_Guard.clear(); 95cdf0e10cSrcweir if( pIter ) 96cdf0e10cSrcweir pIter->notifyEach( &XGridColumnListener::columnChanged, aEvent ); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 100cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL GridColumn::getIdentifier() throw (::com::sun::star::uno::RuntimeException) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 103cdf0e10cSrcweir return m_aIdentifier; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 107cdf0e10cSrcweir void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value) throw (::com::sun::star::uno::RuntimeException) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 110cdf0e10cSrcweir m_aIdentifier = value; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 114cdf0e10cSrcweir ::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 117cdf0e10cSrcweir return m_nColumnWidth; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 121cdf0e10cSrcweir void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir impl_set( m_nColumnWidth, value, "ColumnWidth" ); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 127cdf0e10cSrcweir ::sal_Int32 SAL_CALL GridColumn::getMaxWidth() throw (::com::sun::star::uno::RuntimeException) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 130cdf0e10cSrcweir return m_nMaxWidth; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 134cdf0e10cSrcweir void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir impl_set( m_nMaxWidth, value, "MaxWidth" ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 140cdf0e10cSrcweir ::sal_Int32 SAL_CALL GridColumn::getMinWidth() throw (::com::sun::star::uno::RuntimeException) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 143cdf0e10cSrcweir return m_nMinWidth; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 147cdf0e10cSrcweir void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir impl_set( m_nMinWidth, value, "MinWidth" ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 153cdf0e10cSrcweir ::rtl::OUString SAL_CALL GridColumn::getTitle() throw (::com::sun::star::uno::RuntimeException) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 156cdf0e10cSrcweir return m_sTitle; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 160cdf0e10cSrcweir void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir impl_set( m_sTitle, value, "Title" ); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 166cdf0e10cSrcweir ::rtl::OUString SAL_CALL GridColumn::getHelpText() throw (RuntimeException) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 169cdf0e10cSrcweir return m_sHelpText; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 173cdf0e10cSrcweir void SAL_CALL GridColumn::setHelpText( const ::rtl::OUString & value ) throw (RuntimeException) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir impl_set( m_sHelpText, value, "HelpText" ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 179cdf0e10cSrcweir sal_Bool SAL_CALL GridColumn::getResizeable() throw (::com::sun::star::uno::RuntimeException) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 182cdf0e10cSrcweir return m_bResizeable; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 186cdf0e10cSrcweir void SAL_CALL GridColumn::setResizeable(sal_Bool value) throw (::com::sun::star::uno::RuntimeException) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir impl_set( m_bResizeable, value, "Resizeable" ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 192cdf0e10cSrcweir ::sal_Int32 SAL_CALL GridColumn::getFlexibility() throw (RuntimeException) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 195cdf0e10cSrcweir return m_nFlexibility; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 199cdf0e10cSrcweir void SAL_CALL GridColumn::setFlexibility( ::sal_Int32 i_value ) throw (IllegalArgumentException, RuntimeException) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir if ( i_value < 0 ) 202cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 203cdf0e10cSrcweir impl_set( m_nFlexibility, i_value, "Flexibility" ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 207cdf0e10cSrcweir HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 210cdf0e10cSrcweir return m_eHorizontalAlign; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 214cdf0e10cSrcweir void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir impl_set( m_eHorizontalAlign, align, "HorizontalAlign" ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 220cdf0e10cSrcweir void SAL_CALL GridColumn::addGridColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir rBHelper.addListener( XGridColumnListener::static_type(), xListener ); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 226cdf0e10cSrcweir void SAL_CALL GridColumn::removeGridColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir rBHelper.removeListener( XGridColumnListener::static_type(), xListener ); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 232cdf0e10cSrcweir void SAL_CALL GridColumn::disposing() 233cdf0e10cSrcweir { 234cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 235cdf0e10cSrcweir m_aIdentifier.clear(); 236cdf0e10cSrcweir m_sTitle = m_sHelpText = ::rtl::OUString(); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir 239cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 240cdf0e10cSrcweir ::sal_Int32 SAL_CALL GridColumn::getIndex() throw (RuntimeException) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 243cdf0e10cSrcweir return m_nIndex; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 247cdf0e10cSrcweir void GridColumn::setIndex( sal_Int32 const i_index ) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 250cdf0e10cSrcweir m_nIndex = i_index; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 254cdf0e10cSrcweir ::sal_Int32 SAL_CALL GridColumn::getDataColumnIndex() throw(RuntimeException) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir ::comphelper::ComponentGuard aGuard( *this, rBHelper ); 257cdf0e10cSrcweir return m_nDataColumnIndex; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 261cdf0e10cSrcweir void SAL_CALL GridColumn::setDataColumnIndex( ::sal_Int32 i_dataColumnIndex ) throw(RuntimeException) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir impl_set( m_nDataColumnIndex, i_dataColumnIndex, "DataColumnIndex" ); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 267cdf0e10cSrcweir ::rtl::OUString SAL_CALL GridColumn::getImplementationName( ) throw (RuntimeException) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.toolkit.GridColumn" ) ); 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 273cdf0e10cSrcweir sal_Bool SAL_CALL GridColumn::supportsService( const ::rtl::OUString& i_serviceName ) throw (RuntimeException) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() ); 276cdf0e10cSrcweir for ( sal_Int32 i=0; i<aServiceNames.getLength(); ++i ) 277cdf0e10cSrcweir if ( aServiceNames[i] == i_serviceName ) 278cdf0e10cSrcweir return sal_True; 279cdf0e10cSrcweir return sal_False; 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 283cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL GridColumn::getSupportedServiceNames( ) throw (RuntimeException) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir const ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName_GridColumn ) ); 286cdf0e10cSrcweir const Sequence< ::rtl::OUString > aSeq( &aServiceName, 1 ); 287cdf0e10cSrcweir return aSeq; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 291cdf0e10cSrcweir Reference< XCloneable > SAL_CALL GridColumn::createClone( ) throw (RuntimeException) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir return new GridColumn( *this ); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir 296cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 297cdf0e10cSrcweir sal_Int64 SAL_CALL GridColumn::getSomething( const Sequence< sal_Int8 >& i_identifier ) throw(RuntimeException) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir if ( ( i_identifier.getLength() == 16 ) && ( i_identifier == getUnoTunnelId() ) ) 300cdf0e10cSrcweir return ::sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) ); 301cdf0e10cSrcweir return 0; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 305cdf0e10cSrcweir Sequence< sal_Int8 > GridColumn::getUnoTunnelId() throw() 306cdf0e10cSrcweir { 307cdf0e10cSrcweir static ::cppu::OImplementationId const aId; 308cdf0e10cSrcweir return aId.getImplementationId(); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 312cdf0e10cSrcweir GridColumn* GridColumn::getImplementation( const Reference< XInterface >& i_component ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir Reference< XUnoTunnel > const xTunnel( i_component, UNO_QUERY ); 315cdf0e10cSrcweir if ( xTunnel.is() ) 316cdf0e10cSrcweir return reinterpret_cast< GridColumn* >( ::sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething( getUnoTunnelId() ) ) ); 317cdf0e10cSrcweir return NULL; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL GridColumn_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir return *( new ::toolkit::GridColumn ); 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326