Avoid potential negative array index access to cached text.
[LibreOffice.git] / toolkit / source / controls / grid / gridcolumn.cxx
blob92d28ce9c822b40826e3509cf24408c021adb3a2
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 <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <comphelper/servicehelper.hxx>
25 #include <cppuhelper/supportsservice.hxx>
27 namespace toolkit
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::awt;
32 using namespace ::com::sun::star::awt::grid;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::util;
35 using namespace ::com::sun::star::style;
38 //= DefaultGridColumnModel
41 GridColumn::GridColumn()
42 :m_nIndex(-1)
43 ,m_nDataColumnIndex(-1)
44 ,m_nColumnWidth(4)
45 ,m_nMaxWidth(0)
46 ,m_nMinWidth(0)
47 ,m_nFlexibility(1)
48 ,m_bResizeable(true)
49 ,m_eHorizontalAlign( HorizontalAlignment_LEFT )
54 GridColumn::GridColumn( GridColumn const & i_copySource )
55 :m_aIdentifier( i_copySource.m_aIdentifier )
56 ,m_nIndex( -1 )
57 ,m_nDataColumnIndex( i_copySource.m_nDataColumnIndex )
58 ,m_nColumnWidth( i_copySource.m_nColumnWidth )
59 ,m_nMaxWidth( i_copySource.m_nMaxWidth )
60 ,m_nMinWidth( i_copySource.m_nMinWidth )
61 ,m_nFlexibility( i_copySource.m_nFlexibility )
62 ,m_bResizeable( i_copySource.m_bResizeable )
63 ,m_sTitle( i_copySource.m_sTitle )
64 ,m_sHelpText( i_copySource.m_sHelpText )
65 ,m_eHorizontalAlign( i_copySource.m_eHorizontalAlign )
70 GridColumn::~GridColumn()
75 void GridColumn::broadcast_changed( char const * const i_asciiAttributeName, const Any& i_oldValue, const Any& i_newValue,
76 std::unique_lock<std::mutex>& i_Guard )
78 Reference< XInterface > const xSource( getXWeak() );
79 GridColumnEvent const aEvent(
80 xSource, OUString::createFromAscii( i_asciiAttributeName ),
81 i_oldValue, i_newValue, m_nIndex
84 maGridColumnListeners.notifyEach( i_Guard, &XGridColumnListener::columnChanged, aEvent );
88 css::uno::Any SAL_CALL GridColumn::getIdentifier()
90 std::unique_lock aGuard( m_aMutex );
91 return m_aIdentifier;
95 void SAL_CALL GridColumn::setIdentifier(const css::uno::Any & value)
97 std::unique_lock aGuard( m_aMutex );
98 m_aIdentifier = value;
102 ::sal_Int32 SAL_CALL GridColumn::getColumnWidth()
104 std::unique_lock aGuard( m_aMutex );
105 return m_nColumnWidth;
109 void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value)
111 impl_set( m_nColumnWidth, value, "ColumnWidth" );
115 ::sal_Int32 SAL_CALL GridColumn::getMaxWidth()
117 std::unique_lock aGuard( m_aMutex );
118 return m_nMaxWidth;
122 void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value)
124 impl_set( m_nMaxWidth, value, "MaxWidth" );
128 ::sal_Int32 SAL_CALL GridColumn::getMinWidth()
130 std::unique_lock aGuard( m_aMutex );
131 return m_nMinWidth;
135 void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value)
137 impl_set( m_nMinWidth, value, "MinWidth" );
141 OUString SAL_CALL GridColumn::getTitle()
143 std::unique_lock aGuard( m_aMutex );
144 return m_sTitle;
148 void SAL_CALL GridColumn::setTitle(const OUString & value)
150 impl_set( m_sTitle, value, "Title" );
154 OUString SAL_CALL GridColumn::getHelpText()
156 std::unique_lock aGuard( m_aMutex );
157 return m_sHelpText;
161 void SAL_CALL GridColumn::setHelpText( const OUString & value )
163 impl_set( m_sHelpText, value, "HelpText" );
167 sal_Bool SAL_CALL GridColumn::getResizeable()
169 std::unique_lock aGuard( m_aMutex );
170 return m_bResizeable;
174 void SAL_CALL GridColumn::setResizeable(sal_Bool value)
176 impl_set( m_bResizeable, bool(value), "Resizeable" );
180 ::sal_Int32 SAL_CALL GridColumn::getFlexibility()
182 std::unique_lock aGuard( m_aMutex );
183 return m_nFlexibility;
187 void SAL_CALL GridColumn::setFlexibility( ::sal_Int32 i_value )
189 if ( i_value < 0 )
190 throw IllegalArgumentException( OUString(), *this, 1 );
191 impl_set( m_nFlexibility, i_value, "Flexibility" );
195 HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign()
197 std::unique_lock aGuard( m_aMutex );
198 return m_eHorizontalAlign;
202 void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align)
204 impl_set( m_eHorizontalAlign, align, "HorizontalAlign" );
208 void SAL_CALL GridColumn::addGridColumnListener( const Reference< XGridColumnListener >& xListener )
210 std::unique_lock aGuard( m_aMutex );
211 maGridColumnListeners.addInterface( aGuard, xListener );
215 void SAL_CALL GridColumn::removeGridColumnListener( const Reference< XGridColumnListener >& xListener )
217 std::unique_lock aGuard( m_aMutex );
218 maGridColumnListeners.removeInterface( aGuard, xListener );
222 void GridColumn::disposing(std::unique_lock<std::mutex>&)
224 m_aIdentifier.clear();
225 m_sTitle.clear();
226 m_sHelpText.clear();
230 ::sal_Int32 SAL_CALL GridColumn::getIndex()
232 std::unique_lock aGuard( m_aMutex );
233 return m_nIndex;
237 void GridColumn::setIndex( sal_Int32 const i_index )
239 std::unique_lock aGuard( m_aMutex );
240 m_nIndex = i_index;
244 ::sal_Int32 SAL_CALL GridColumn::getDataColumnIndex()
246 std::unique_lock aGuard( m_aMutex );
247 return m_nDataColumnIndex;
251 void SAL_CALL GridColumn::setDataColumnIndex( ::sal_Int32 i_dataColumnIndex )
253 impl_set( m_nDataColumnIndex, i_dataColumnIndex, "DataColumnIndex" );
257 OUString SAL_CALL GridColumn::getImplementationName( )
259 return "org.openoffice.comp.toolkit.GridColumn";
262 sal_Bool SAL_CALL GridColumn::supportsService( const OUString& i_serviceName )
264 return cppu::supportsService(this, i_serviceName);
267 css::uno::Sequence< OUString > SAL_CALL GridColumn::getSupportedServiceNames( )
269 return { "com.sun.star.awt.grid.GridColumn" };
273 Reference< XCloneable > SAL_CALL GridColumn::createClone( )
275 return new GridColumn( *this );
279 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
280 org_openoffice_comp_toolkit_GridColumn_get_implementation(
281 css::uno::XComponentContext *,
282 css::uno::Sequence<css::uno::Any> const &)
284 return cppu::acquire(new toolkit::GridColumn());
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */