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 : #ifndef TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
21 : #define TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
22 :
23 : #include "initguard.hxx"
24 :
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>
30 :
31 : #include <comphelper/componentcontext.hxx>
32 : #include <cppuhelper/basemutex.hxx>
33 : #include <cppuhelper/compbase3.hxx>
34 : #include <cppuhelper/implbase1.hxx>
35 :
36 : //......................................................................................................................
37 : namespace toolkit
38 : {
39 : //......................................................................................................................
40 :
41 : class SortableGridDataModel;
42 : typedef InitGuard< SortableGridDataModel > MethodGuard;
43 :
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
56 : {
57 : public:
58 : SortableGridDataModel( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rxContext );
59 : SortableGridDataModel( SortableGridDataModel const & i_copySource );
60 :
61 0 : bool isInitialized() const { return m_isInitialized; }
62 :
63 : #ifdef DBG_UTIL
64 : const char* checkInvariants() const;
65 : #endif
66 :
67 : protected:
68 : ~SortableGridDataModel();
69 :
70 : public:
71 : // XSortableGridData
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);
75 :
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);
90 :
91 : // XGridDataModel
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);
98 :
99 : // OComponentHelper
100 : virtual void SAL_CALL disposing();
101 :
102 : // XCloneable
103 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone( ) throw (::com::sun::star::uno::RuntimeException);
104 :
105 : // XServiceInfo
106 : virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
107 : virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
108 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
109 :
110 : // XInitialization
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);
112 :
113 : // XGridDataListener
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);
118 :
119 : // XEventListener
120 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& i_event ) throw (::com::sun::star::uno::RuntimeException);
121 :
122 : // XInterface
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 ();
126 :
127 : // XTypeProvider
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);
130 :
131 : private:
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
135 : */
136 : ::sal_Int32 impl_getPrivateRowIndex_throw( ::sal_Int32 const i_publicRowIndex ) const;
137 :
138 : /** translates the given private row index to a public one
139 : */
140 : ::sal_Int32 impl_getPublicRowIndex_nothrow( ::sal_Int32 const i_privateRowIndex ) const;
141 :
142 0 : inline bool impl_isSorted_nothrow() const
143 : {
144 0 : return m_currentSortColumn >= 0;
145 : }
146 :
147 : /** rebuilds the index translation structure.
148 :
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.
151 : */
152 : bool impl_reIndex_nothrow( ::sal_Int32 const i_columnIndex, sal_Bool const i_sortAscending );
153 :
154 : /** translates the given event, obtained from our delegator, to a version which can be broadcasted to our own
155 : clients.
156 : */
157 : ::com::sun::star::awt::grid::GridDataEvent
158 : impl_createPublicEvent( ::com::sun::star::awt::grid::GridDataEvent const & i_originalEvent ) const;
159 :
160 : /** broadcasts the given event to our registered XGridDataListeners
161 : */
162 : void impl_broadcast(
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
166 : );
167 :
168 : /** rebuilds our indexes, notifying row removal and row addition events
169 :
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.
172 :
173 : Only to be called when we're sorted.
174 : */
175 : void impl_rebuildIndexesAndNotify( MethodGuard& i_instanceLock );
176 :
177 : /** removes the current sorting, and notifies a change of all data
178 : */
179 : void impl_removeColumnSort( MethodGuard& i_instanceLock );
180 :
181 : /** removes the current sorting, without any broadcast
182 : */
183 : void impl_removeColumnSort_noBroadcast();
184 :
185 : private:
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;
194 : };
195 :
196 : //......................................................................................................................
197 : } // namespace toolkit
198 : //......................................................................................................................
199 :
200 : #endif // TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|