Updated core
[LibreOffice.git] / toolkit / source / controls / grid / gridcolumn.cxx
blob10c796b5f49564070ad34a9a39e9bc56cafcddc2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "gridcolumn.hxx"
22 #include <comphelper/sequence.hxx>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <toolkit/helper/servicenames.hxx>
26 namespace toolkit
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::awt;
31 using namespace ::com::sun::star::awt::grid;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::util;
34 using namespace ::com::sun::star::style;
36 //==================================================================================================================
37 //= DefaultGridColumnModel
38 //==================================================================================================================
39 //------------------------------------------------------------------------------------------------------------------
40 GridColumn::GridColumn()
41 :GridColumn_Base( m_aMutex )
42 ,m_aIdentifier()
43 ,m_nIndex(-1)
44 ,m_nDataColumnIndex(-1)
45 ,m_nColumnWidth(4)
46 ,m_nMaxWidth(0)
47 ,m_nMinWidth(0)
48 ,m_nFlexibility(1)
49 ,m_bResizeable(true)
50 ,m_eHorizontalAlign( HorizontalAlignment_LEFT )
54 //------------------------------------------------------------------------------------------------------------------
55 GridColumn::GridColumn( GridColumn const & i_copySource )
56 :cppu::BaseMutex()
57 ,GridColumn_Base( m_aMutex )
58 ,m_aIdentifier( i_copySource.m_aIdentifier )
59 ,m_nIndex( -1 )
60 ,m_nDataColumnIndex( i_copySource.m_nDataColumnIndex )
61 ,m_nColumnWidth( i_copySource.m_nColumnWidth )
62 ,m_nMaxWidth( i_copySource.m_nMaxWidth )
63 ,m_nMinWidth( i_copySource.m_nMinWidth )
64 ,m_nFlexibility( i_copySource.m_nFlexibility )
65 ,m_bResizeable( i_copySource.m_bResizeable )
66 ,m_sTitle( i_copySource.m_sTitle )
67 ,m_sHelpText( i_copySource.m_sHelpText )
68 ,m_eHorizontalAlign( i_copySource.m_eHorizontalAlign )
72 //------------------------------------------------------------------------------------------------------------------
73 GridColumn::~GridColumn()
77 //------------------------------------------------------------------------------------------------------------------
78 void GridColumn::broadcast_changed( sal_Char const * const i_asciiAttributeName, Any i_oldValue, Any i_newValue,
79 ::comphelper::ComponentGuard& i_Guard )
81 Reference< XInterface > const xSource( static_cast< ::cppu::OWeakObject* >( this ) );
82 GridColumnEvent const aEvent(
83 xSource, OUString::createFromAscii( i_asciiAttributeName ),
84 i_oldValue, i_newValue, m_nIndex
87 ::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( XGridColumnListener::static_type() );
89 i_Guard.clear();
90 if( pIter )
91 pIter->notifyEach( &XGridColumnListener::columnChanged, aEvent );
94 //------------------------------------------------------------------------------------------------------------------
95 ::com::sun::star::uno::Any SAL_CALL GridColumn::getIdentifier() throw (::com::sun::star::uno::RuntimeException)
97 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
98 return m_aIdentifier;
101 //------------------------------------------------------------------------------------------------------------------
102 void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value) throw (::com::sun::star::uno::RuntimeException)
104 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
105 m_aIdentifier = value;
108 //------------------------------------------------------------------------------------------------------------------
109 ::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException)
111 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
112 return m_nColumnWidth;
115 //------------------------------------------------------------------------------------------------------------------
116 void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
118 impl_set( m_nColumnWidth, value, "ColumnWidth" );
121 //------------------------------------------------------------------------------------------------------------------
122 ::sal_Int32 SAL_CALL GridColumn::getMaxWidth() throw (::com::sun::star::uno::RuntimeException)
124 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
125 return m_nMaxWidth;
128 //------------------------------------------------------------------------------------------------------------------
129 void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
131 impl_set( m_nMaxWidth, value, "MaxWidth" );
134 //------------------------------------------------------------------------------------------------------------------
135 ::sal_Int32 SAL_CALL GridColumn::getMinWidth() throw (::com::sun::star::uno::RuntimeException)
137 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
138 return m_nMinWidth;
141 //------------------------------------------------------------------------------------------------------------------
142 void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
144 impl_set( m_nMinWidth, value, "MinWidth" );
147 //------------------------------------------------------------------------------------------------------------------
148 OUString SAL_CALL GridColumn::getTitle() throw (::com::sun::star::uno::RuntimeException)
150 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
151 return m_sTitle;
154 //------------------------------------------------------------------------------------------------------------------
155 void SAL_CALL GridColumn::setTitle(const OUString & value) throw (::com::sun::star::uno::RuntimeException)
157 impl_set( m_sTitle, value, "Title" );
160 //------------------------------------------------------------------------------------------------------------------
161 OUString SAL_CALL GridColumn::getHelpText() throw (RuntimeException)
163 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
164 return m_sHelpText;
167 //------------------------------------------------------------------------------------------------------------------
168 void SAL_CALL GridColumn::setHelpText( const OUString & value ) throw (RuntimeException)
170 impl_set( m_sHelpText, value, "HelpText" );
173 //------------------------------------------------------------------------------------------------------------------
174 sal_Bool SAL_CALL GridColumn::getResizeable() throw (::com::sun::star::uno::RuntimeException)
176 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
177 return m_bResizeable;
180 //------------------------------------------------------------------------------------------------------------------
181 void SAL_CALL GridColumn::setResizeable(sal_Bool value) throw (::com::sun::star::uno::RuntimeException)
183 impl_set( m_bResizeable, value, "Resizeable" );
186 //------------------------------------------------------------------------------------------------------------------
187 ::sal_Int32 SAL_CALL GridColumn::getFlexibility() throw (RuntimeException)
189 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
190 return m_nFlexibility;
193 //------------------------------------------------------------------------------------------------------------------
194 void SAL_CALL GridColumn::setFlexibility( ::sal_Int32 i_value ) throw (IllegalArgumentException, RuntimeException)
196 if ( i_value < 0 )
197 throw IllegalArgumentException( OUString(), *this, 1 );
198 impl_set( m_nFlexibility, i_value, "Flexibility" );
201 //------------------------------------------------------------------------------------------------------------------
202 HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException)
204 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
205 return m_eHorizontalAlign;
208 //------------------------------------------------------------------------------------------------------------------
209 void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException)
211 impl_set( m_eHorizontalAlign, align, "HorizontalAlign" );
214 //------------------------------------------------------------------------------------------------------------------
215 void SAL_CALL GridColumn::addGridColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException)
217 rBHelper.addListener( XGridColumnListener::static_type(), xListener );
220 //------------------------------------------------------------------------------------------------------------------
221 void SAL_CALL GridColumn::removeGridColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException)
223 rBHelper.removeListener( XGridColumnListener::static_type(), xListener );
226 //------------------------------------------------------------------------------------------------------------------
227 void SAL_CALL GridColumn::disposing()
229 ::osl::MutexGuard aGuard( m_aMutex );
230 m_aIdentifier.clear();
231 m_sTitle = m_sHelpText = OUString();
234 //------------------------------------------------------------------------------------------------------------------
235 ::sal_Int32 SAL_CALL GridColumn::getIndex() throw (RuntimeException)
237 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
238 return m_nIndex;
241 //------------------------------------------------------------------------------------------------------------------
242 void GridColumn::setIndex( sal_Int32 const i_index )
244 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
245 m_nIndex = i_index;
248 //------------------------------------------------------------------------------------------------------------------
249 ::sal_Int32 SAL_CALL GridColumn::getDataColumnIndex() throw(RuntimeException)
251 ::comphelper::ComponentGuard aGuard( *this, rBHelper );
252 return m_nDataColumnIndex;
255 //------------------------------------------------------------------------------------------------------------------
256 void SAL_CALL GridColumn::setDataColumnIndex( ::sal_Int32 i_dataColumnIndex ) throw(RuntimeException)
258 impl_set( m_nDataColumnIndex, i_dataColumnIndex, "DataColumnIndex" );
261 //------------------------------------------------------------------------------------------------------------------
262 OUString SAL_CALL GridColumn::getImplementationName( ) throw (RuntimeException)
264 return OUString( "org.openoffice.comp.toolkit.GridColumn" );
267 //------------------------------------------------------------------------------------------------------------------
268 sal_Bool SAL_CALL GridColumn::supportsService( const OUString& i_serviceName ) throw (RuntimeException)
270 const Sequence< OUString > aServiceNames( getSupportedServiceNames() );
271 for ( sal_Int32 i=0; i<aServiceNames.getLength(); ++i )
272 if ( aServiceNames[i] == i_serviceName )
273 return sal_True;
274 return sal_False;
277 //------------------------------------------------------------------------------------------------------------------
278 ::com::sun::star::uno::Sequence< OUString > SAL_CALL GridColumn::getSupportedServiceNames( ) throw (RuntimeException)
280 const OUString aServiceName( OUString::createFromAscii( szServiceName_GridColumn ) );
281 const Sequence< OUString > aSeq( &aServiceName, 1 );
282 return aSeq;
285 //------------------------------------------------------------------------------------------------------------------
286 Reference< XCloneable > SAL_CALL GridColumn::createClone( ) throw (RuntimeException)
288 return new GridColumn( *this );
291 //------------------------------------------------------------------------------------------------------------------
292 sal_Int64 SAL_CALL GridColumn::getSomething( const Sequence< sal_Int8 >& i_identifier ) throw(RuntimeException)
294 if ( ( i_identifier.getLength() == 16 ) && ( i_identifier == getUnoTunnelId() ) )
295 return ::sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) );
296 return 0;
299 //------------------------------------------------------------------------------------------------------------------
300 Sequence< sal_Int8 > GridColumn::getUnoTunnelId() throw()
302 static ::cppu::OImplementationId const aId;
303 return aId.getImplementationId();
306 //------------------------------------------------------------------------------------------------------------------
307 GridColumn* GridColumn::getImplementation( const Reference< XInterface >& i_component )
309 Reference< XUnoTunnel > const xTunnel( i_component, UNO_QUERY );
310 if ( xTunnel.is() )
311 return reinterpret_cast< GridColumn* >( ::sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething( getUnoTunnelId() ) ) );
312 return NULL;
316 ::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 >& )
318 return *( new ::toolkit::GridColumn );
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */