1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
21 #define TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
23 #include "initguard.hxx"
25 #include <com/sun/star/awt/grid/XSortableMutableGridDataModel.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/i18n/XCollator.hpp>
29 #include <com/sun/star/awt/grid/XGridDataListener.hpp>
31 #include <comphelper/componentcontext.hxx>
32 #include <cppuhelper/basemutex.hxx>
33 #include <cppuhelper/compbase3.hxx>
34 #include <cppuhelper/implbase1.hxx>
36 //......................................................................................................................
39 //......................................................................................................................
41 class SortableGridDataModel
;
42 typedef InitGuard
< SortableGridDataModel
> MethodGuard
;
44 //==================================================================================================================
45 //= SortableGridDataModel
46 //==================================================================================================================
47 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::awt::grid::XSortableMutableGridDataModel
48 , ::com::sun::star::lang::XServiceInfo
49 , ::com::sun::star::lang::XInitialization
50 > SortableGridDataModel_Base
;
51 typedef ::cppu::ImplHelper1
< ::com::sun::star::awt::grid::XGridDataListener
52 > SortableGridDataModel_PrivateBase
;
53 class SortableGridDataModel
:public ::cppu::BaseMutex
54 ,public SortableGridDataModel_Base
55 ,public SortableGridDataModel_PrivateBase
58 SortableGridDataModel( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> & rxContext
);
59 SortableGridDataModel( SortableGridDataModel
const & i_copySource
);
61 bool isInitialized() const { return m_isInitialized
; }
64 const char* checkInvariants() const;
68 ~SortableGridDataModel();
72 virtual void SAL_CALL
sortByColumn( ::sal_Int32 ColumnIndex
, ::sal_Bool SortAscending
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
73 virtual void SAL_CALL
removeColumnSort( ) throw (::com::sun::star::uno::RuntimeException
);
74 virtual ::com::sun::star::beans::Pair
< ::sal_Int32
, ::sal_Bool
> SAL_CALL
getCurrentSortOrder( ) throw (::com::sun::star::uno::RuntimeException
);
76 // XMutableGridDataModel
77 virtual void SAL_CALL
addRow( const ::com::sun::star::uno::Any
& Heading
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& Data
) throw (::com::sun::star::uno::RuntimeException
);
78 virtual void SAL_CALL
addRows( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& Headings
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> >& Data
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
79 virtual void SAL_CALL
insertRow( ::sal_Int32 i_index
, const ::com::sun::star::uno::Any
& i_heading
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& Data
) throw (::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IndexOutOfBoundsException
);
80 virtual void SAL_CALL
insertRows( ::sal_Int32 i_index
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& Headings
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> >& Data
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
81 virtual void SAL_CALL
removeRow( ::sal_Int32 RowIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
82 virtual void SAL_CALL
removeAllRows( ) throw (::com::sun::star::uno::RuntimeException
);
83 virtual void SAL_CALL
updateCellData( ::sal_Int32 ColumnIndex
, ::sal_Int32 RowIndex
, const ::com::sun::star::uno::Any
& Value
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
84 virtual void SAL_CALL
updateRowData( const ::com::sun::star::uno::Sequence
< ::sal_Int32
>& ColumnIndexes
, ::sal_Int32 RowIndex
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& Values
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
85 virtual void SAL_CALL
updateRowHeading( ::sal_Int32 RowIndex
, const ::com::sun::star::uno::Any
& Heading
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
86 virtual void SAL_CALL
updateCellToolTip( ::sal_Int32 ColumnIndex
, ::sal_Int32 RowIndex
, const ::com::sun::star::uno::Any
& Value
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
87 virtual void SAL_CALL
updateRowToolTip( ::sal_Int32 RowIndex
, const ::com::sun::star::uno::Any
& Value
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
88 virtual void SAL_CALL
addGridDataListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridDataListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
);
89 virtual void SAL_CALL
removeGridDataListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XGridDataListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
);
92 virtual ::sal_Int32 SAL_CALL
getRowCount() throw (::com::sun::star::uno::RuntimeException
);
93 virtual ::sal_Int32 SAL_CALL
getColumnCount() throw (::com::sun::star::uno::RuntimeException
);
94 virtual ::com::sun::star::uno::Any SAL_CALL
getCellData( ::sal_Int32 Column
, ::sal_Int32 RowIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
95 virtual ::com::sun::star::uno::Any SAL_CALL
getCellToolTip( ::sal_Int32 Column
, ::sal_Int32 RowIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
96 virtual ::com::sun::star::uno::Any SAL_CALL
getRowHeading( ::sal_Int32 RowIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
97 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> SAL_CALL
getRowData( ::sal_Int32 RowIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
100 virtual void SAL_CALL
disposing();
103 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
> SAL_CALL
createClone( ) throw (::com::sun::star::uno::RuntimeException
);
106 virtual OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
);
107 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
);
108 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
111 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
) throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
114 virtual void SAL_CALL
rowsInserted( const ::com::sun::star::awt::grid::GridDataEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
);
115 virtual void SAL_CALL
rowsRemoved( const ::com::sun::star::awt::grid::GridDataEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
);
116 virtual void SAL_CALL
dataChanged( const ::com::sun::star::awt::grid::GridDataEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
);
117 virtual void SAL_CALL
rowHeadingChanged( const ::com::sun::star::awt::grid::GridDataEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
);
120 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& i_event
) throw (::com::sun::star::uno::RuntimeException
);
123 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& aType
) throw (::com::sun::star::uno::RuntimeException
);
124 virtual void SAL_CALL
acquire( ) throw ();
125 virtual void SAL_CALL
release( ) throw ();
128 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw (::com::sun::star::uno::RuntimeException
);
129 virtual ::com::sun::star::uno::Sequence
< ::sal_Int8
> SAL_CALL
getImplementationId( ) throw (::com::sun::star::uno::RuntimeException
);
132 /** translates the given public index into one to be passed to our delegator
133 @throws ::com::sun::star::lang::IndexOutOfBoundsException
134 if the given index does not denote a valid row
136 ::sal_Int32
impl_getPrivateRowIndex_throw( ::sal_Int32
const i_publicRowIndex
) const;
138 /** translates the given private row index to a public one
140 ::sal_Int32
impl_getPublicRowIndex_nothrow( ::sal_Int32
const i_privateRowIndex
) const;
142 inline bool impl_isSorted_nothrow() const
144 return m_currentSortColumn
>= 0;
147 /** rebuilds the index translation structure.
149 Neither <member>m_currentSortColumn</member> nor <member>m_sortAscending</member> are touched by this method.
150 Also, the given column index is not checked, this is the responsibility of the caller.
152 bool impl_reIndex_nothrow( ::sal_Int32
const i_columnIndex
, sal_Bool
const i_sortAscending
);
154 /** translates the given event, obtained from our delegator, to a version which can be broadcasted to our own
157 ::com::sun::star::awt::grid::GridDataEvent
158 impl_createPublicEvent( ::com::sun::star::awt::grid::GridDataEvent
const & i_originalEvent
) const;
160 /** broadcasts the given event to our registered XGridDataListeners
163 void ( SAL_CALL ::com::sun::star::awt::grid::XGridDataListener::*i_listenerMethod
)( const ::com::sun::star::awt::grid::GridDataEvent
& ),
164 ::com::sun::star::awt::grid::GridDataEvent
const & i_publicEvent
,
165 MethodGuard
& i_instanceLock
168 /** rebuilds our indexes, notifying row removal and row addition events
170 First, a rowsRemoved event is notified to our registered listeners. Then, the index translation tables are
171 rebuilt, and a rowsInserted event is notified.
173 Only to be called when we're sorted.
175 void impl_rebuildIndexesAndNotify( MethodGuard
& i_instanceLock
);
177 /** removes the current sorting, and notifies a change of all data
179 void impl_removeColumnSort( MethodGuard
& i_instanceLock
);
181 /** removes the current sorting, without any broadcast
183 void impl_removeColumnSort_noBroadcast();
186 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
187 bool m_isInitialized
;
188 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::grid::XMutableGridDataModel
> m_delegator
;
189 ::com::sun::star::uno::Reference
< ::com::sun::star::i18n::XCollator
> m_collator
;
190 ::sal_Int32 m_currentSortColumn
;
191 ::sal_Bool m_sortAscending
;
192 ::std::vector
< ::sal_Int32
> m_publicToPrivateRowIndex
;
193 ::std::vector
< ::sal_Int32
> m_privateToPublicRowIndex
;
196 //......................................................................................................................
197 } // namespace toolkit
198 //......................................................................................................................
200 #endif // TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */