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