Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "gridcolumn.hxx"
21 :
22 : #include <comphelper/sequence.hxx>
23 : #include <cppuhelper/typeprovider.hxx>
24 : #include <toolkit/helper/servicenames.hxx>
25 :
26 : namespace toolkit
27 : {
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;
35 :
36 : //==================================================================================================================
37 : //= DefaultGridColumnModel
38 : //==================================================================================================================
39 : //------------------------------------------------------------------------------------------------------------------
40 0 : 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 0 : ,m_eHorizontalAlign( HorizontalAlignment_LEFT )
51 : {
52 0 : }
53 :
54 : //------------------------------------------------------------------------------------------------------------------
55 0 : 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 0 : ,m_eHorizontalAlign( i_copySource.m_eHorizontalAlign )
69 : {
70 0 : }
71 :
72 : //------------------------------------------------------------------------------------------------------------------
73 0 : GridColumn::~GridColumn()
74 : {
75 0 : }
76 :
77 : //------------------------------------------------------------------------------------------------------------------
78 0 : void GridColumn::broadcast_changed( sal_Char const * const i_asciiAttributeName, Any i_oldValue, Any i_newValue,
79 : ::comphelper::ComponentGuard& i_Guard )
80 : {
81 0 : Reference< XInterface > const xSource( static_cast< ::cppu::OWeakObject* >( this ) );
82 : GridColumnEvent const aEvent(
83 : xSource, ::rtl::OUString::createFromAscii( i_asciiAttributeName ),
84 : i_oldValue, i_newValue, m_nIndex
85 0 : );
86 :
87 0 : ::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( XGridColumnListener::static_type() );
88 :
89 0 : i_Guard.clear();
90 0 : if( pIter )
91 0 : pIter->notifyEach( &XGridColumnListener::columnChanged, aEvent );
92 0 : }
93 :
94 : //------------------------------------------------------------------------------------------------------------------
95 0 : ::com::sun::star::uno::Any SAL_CALL GridColumn::getIdentifier() throw (::com::sun::star::uno::RuntimeException)
96 : {
97 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
98 0 : return m_aIdentifier;
99 : }
100 :
101 : //------------------------------------------------------------------------------------------------------------------
102 0 : void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value) throw (::com::sun::star::uno::RuntimeException)
103 : {
104 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
105 0 : m_aIdentifier = value;
106 0 : }
107 :
108 : //------------------------------------------------------------------------------------------------------------------
109 0 : ::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException)
110 : {
111 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
112 0 : return m_nColumnWidth;
113 : }
114 :
115 : //------------------------------------------------------------------------------------------------------------------
116 0 : void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
117 : {
118 0 : impl_set( m_nColumnWidth, value, "ColumnWidth" );
119 0 : }
120 :
121 : //------------------------------------------------------------------------------------------------------------------
122 0 : ::sal_Int32 SAL_CALL GridColumn::getMaxWidth() throw (::com::sun::star::uno::RuntimeException)
123 : {
124 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
125 0 : return m_nMaxWidth;
126 : }
127 :
128 : //------------------------------------------------------------------------------------------------------------------
129 0 : void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
130 : {
131 0 : impl_set( m_nMaxWidth, value, "MaxWidth" );
132 0 : }
133 :
134 : //------------------------------------------------------------------------------------------------------------------
135 0 : ::sal_Int32 SAL_CALL GridColumn::getMinWidth() throw (::com::sun::star::uno::RuntimeException)
136 : {
137 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
138 0 : return m_nMinWidth;
139 : }
140 :
141 : //------------------------------------------------------------------------------------------------------------------
142 0 : void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
143 : {
144 0 : impl_set( m_nMinWidth, value, "MinWidth" );
145 0 : }
146 :
147 : //------------------------------------------------------------------------------------------------------------------
148 0 : ::rtl::OUString SAL_CALL GridColumn::getTitle() throw (::com::sun::star::uno::RuntimeException)
149 : {
150 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
151 0 : return m_sTitle;
152 : }
153 :
154 : //------------------------------------------------------------------------------------------------------------------
155 0 : void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException)
156 : {
157 0 : impl_set( m_sTitle, value, "Title" );
158 0 : }
159 :
160 : //------------------------------------------------------------------------------------------------------------------
161 0 : ::rtl::OUString SAL_CALL GridColumn::getHelpText() throw (RuntimeException)
162 : {
163 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
164 0 : return m_sHelpText;
165 : }
166 :
167 : //------------------------------------------------------------------------------------------------------------------
168 0 : void SAL_CALL GridColumn::setHelpText( const ::rtl::OUString & value ) throw (RuntimeException)
169 : {
170 0 : impl_set( m_sHelpText, value, "HelpText" );
171 0 : }
172 :
173 : //------------------------------------------------------------------------------------------------------------------
174 0 : sal_Bool SAL_CALL GridColumn::getResizeable() throw (::com::sun::star::uno::RuntimeException)
175 : {
176 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
177 0 : return m_bResizeable;
178 : }
179 :
180 : //------------------------------------------------------------------------------------------------------------------
181 0 : void SAL_CALL GridColumn::setResizeable(sal_Bool value) throw (::com::sun::star::uno::RuntimeException)
182 : {
183 0 : impl_set( m_bResizeable, value, "Resizeable" );
184 0 : }
185 :
186 : //------------------------------------------------------------------------------------------------------------------
187 0 : ::sal_Int32 SAL_CALL GridColumn::getFlexibility() throw (RuntimeException)
188 : {
189 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
190 0 : return m_nFlexibility;
191 : }
192 :
193 : //------------------------------------------------------------------------------------------------------------------
194 0 : void SAL_CALL GridColumn::setFlexibility( ::sal_Int32 i_value ) throw (IllegalArgumentException, RuntimeException)
195 : {
196 0 : if ( i_value < 0 )
197 0 : throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
198 0 : impl_set( m_nFlexibility, i_value, "Flexibility" );
199 0 : }
200 :
201 : //------------------------------------------------------------------------------------------------------------------
202 0 : HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException)
203 : {
204 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
205 0 : return m_eHorizontalAlign;
206 : }
207 :
208 : //------------------------------------------------------------------------------------------------------------------
209 0 : void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException)
210 : {
211 0 : impl_set( m_eHorizontalAlign, align, "HorizontalAlign" );
212 0 : }
213 :
214 : //------------------------------------------------------------------------------------------------------------------
215 0 : void SAL_CALL GridColumn::addGridColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException)
216 : {
217 0 : rBHelper.addListener( XGridColumnListener::static_type(), xListener );
218 0 : }
219 :
220 : //------------------------------------------------------------------------------------------------------------------
221 0 : void SAL_CALL GridColumn::removeGridColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException)
222 : {
223 0 : rBHelper.removeListener( XGridColumnListener::static_type(), xListener );
224 0 : }
225 :
226 : //------------------------------------------------------------------------------------------------------------------
227 0 : void SAL_CALL GridColumn::disposing()
228 : {
229 0 : ::osl::MutexGuard aGuard( m_aMutex );
230 0 : m_aIdentifier.clear();
231 0 : m_sTitle = m_sHelpText = ::rtl::OUString();
232 0 : }
233 :
234 : //------------------------------------------------------------------------------------------------------------------
235 0 : ::sal_Int32 SAL_CALL GridColumn::getIndex() throw (RuntimeException)
236 : {
237 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
238 0 : return m_nIndex;
239 : }
240 :
241 : //------------------------------------------------------------------------------------------------------------------
242 0 : void GridColumn::setIndex( sal_Int32 const i_index )
243 : {
244 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
245 0 : m_nIndex = i_index;
246 0 : }
247 :
248 : //------------------------------------------------------------------------------------------------------------------
249 0 : ::sal_Int32 SAL_CALL GridColumn::getDataColumnIndex() throw(RuntimeException)
250 : {
251 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
252 0 : return m_nDataColumnIndex;
253 : }
254 :
255 : //------------------------------------------------------------------------------------------------------------------
256 0 : void SAL_CALL GridColumn::setDataColumnIndex( ::sal_Int32 i_dataColumnIndex ) throw(RuntimeException)
257 : {
258 0 : impl_set( m_nDataColumnIndex, i_dataColumnIndex, "DataColumnIndex" );
259 0 : }
260 :
261 : //------------------------------------------------------------------------------------------------------------------
262 0 : ::rtl::OUString SAL_CALL GridColumn::getImplementationName( ) throw (RuntimeException)
263 : {
264 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.toolkit.GridColumn" ) );
265 : }
266 :
267 : //------------------------------------------------------------------------------------------------------------------
268 0 : sal_Bool SAL_CALL GridColumn::supportsService( const ::rtl::OUString& i_serviceName ) throw (RuntimeException)
269 : {
270 0 : const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() );
271 0 : for ( sal_Int32 i=0; i<aServiceNames.getLength(); ++i )
272 0 : if ( aServiceNames[i] == i_serviceName )
273 0 : return sal_True;
274 0 : return sal_False;
275 : }
276 :
277 : //------------------------------------------------------------------------------------------------------------------
278 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL GridColumn::getSupportedServiceNames( ) throw (RuntimeException)
279 : {
280 0 : const ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName_GridColumn ) );
281 0 : const Sequence< ::rtl::OUString > aSeq( &aServiceName, 1 );
282 0 : return aSeq;
283 : }
284 :
285 : //------------------------------------------------------------------------------------------------------------------
286 0 : Reference< XCloneable > SAL_CALL GridColumn::createClone( ) throw (RuntimeException)
287 : {
288 0 : return new GridColumn( *this );
289 : }
290 :
291 : //------------------------------------------------------------------------------------------------------------------
292 0 : sal_Int64 SAL_CALL GridColumn::getSomething( const Sequence< sal_Int8 >& i_identifier ) throw(RuntimeException)
293 : {
294 0 : if ( ( i_identifier.getLength() == 16 ) && ( i_identifier == getUnoTunnelId() ) )
295 0 : return ::sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) );
296 0 : return 0;
297 : }
298 :
299 : //------------------------------------------------------------------------------------------------------------------
300 0 : Sequence< sal_Int8 > GridColumn::getUnoTunnelId() throw()
301 : {
302 0 : static ::cppu::OImplementationId const aId;
303 0 : return aId.getImplementationId();
304 : }
305 :
306 : //------------------------------------------------------------------------------------------------------------------
307 0 : GridColumn* GridColumn::getImplementation( const Reference< XInterface >& i_component )
308 : {
309 0 : Reference< XUnoTunnel > const xTunnel( i_component, UNO_QUERY );
310 0 : if ( xTunnel.is() )
311 0 : return reinterpret_cast< GridColumn* >( ::sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething( getUnoTunnelId() ) ) );
312 0 : return NULL;
313 : }
314 : }
315 :
316 0 : ::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 >& )
317 : {
318 0 : return *( new ::toolkit::GridColumn );
319 : }
320 :
321 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|