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 <cppuhelper/basemutex.hxx>
32 : #include <cppuhelper/compbase3.hxx>
33 : #include <cppuhelper/implbase1.hxx>
34 :
35 : //......................................................................................................................
36 : namespace toolkit
37 : {
38 : //......................................................................................................................
39 :
40 : class SortableGridDataModel;
41 : typedef InitGuard< SortableGridDataModel > MethodGuard;
42 :
43 : //==================================================================================================================
44 : //= SortableGridDataModel
45 : //==================================================================================================================
46 : typedef ::cppu::WeakComponentImplHelper3 < ::com::sun::star::awt::grid::XSortableMutableGridDataModel
47 : , ::com::sun::star::lang::XServiceInfo
48 : , ::com::sun::star::lang::XInitialization
49 : > SortableGridDataModel_Base;
50 : typedef ::cppu::ImplHelper1 < ::com::sun::star::awt::grid::XGridDataListener
51 : > SortableGridDataModel_PrivateBase;
52 : class SortableGridDataModel :public ::cppu::BaseMutex
53 : ,public SortableGridDataModel_Base
54 : ,public SortableGridDataModel_PrivateBase
55 : {
56 : public:
57 : SortableGridDataModel( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rxContext );
58 : SortableGridDataModel( SortableGridDataModel const & i_copySource );
59 :
60 624 : bool isInitialized() const { return m_isInitialized; }
61 :
62 : #ifdef DBG_UTIL
63 : const char* checkInvariants() const;
64 : #endif
65 :
66 : protected:
67 : ~SortableGridDataModel();
68 :
69 : public:
70 : // XSortableGridData
71 : virtual void SAL_CALL sortByColumn( ::sal_Int32 ColumnIndex, ::sal_Bool SortAscending ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
72 : virtual void SAL_CALL removeColumnSort( ) throw (::com::sun::star::uno::RuntimeException);
73 : virtual ::com::sun::star::beans::Pair< ::sal_Int32, ::sal_Bool > SAL_CALL getCurrentSortOrder( ) throw (::com::sun::star::uno::RuntimeException);
74 :
75 : // XMutableGridDataModel
76 : 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);
77 : 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);
78 : 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);
79 : 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);
80 : virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
81 : virtual void SAL_CALL removeAllRows( ) throw (::com::sun::star::uno::RuntimeException);
82 : 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);
83 : 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);
84 : 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);
85 : 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);
86 : 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);
87 : virtual void SAL_CALL addGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
88 : virtual void SAL_CALL removeGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
89 :
90 : // XGridDataModel
91 : virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException);
92 : virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException);
93 : 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);
94 : 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);
95 : virtual ::com::sun::star::uno::Any SAL_CALL getRowHeading( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
96 : 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);
97 :
98 : // OComponentHelper
99 : virtual void SAL_CALL disposing();
100 :
101 : // XCloneable
102 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone( ) throw (::com::sun::star::uno::RuntimeException);
103 :
104 : // XServiceInfo
105 : virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
106 : virtual ::sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
107 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
108 :
109 : // XInitialization
110 : 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);
111 :
112 : // XGridDataListener
113 : virtual void SAL_CALL rowsInserted( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
114 : virtual void SAL_CALL rowsRemoved( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
115 : virtual void SAL_CALL dataChanged( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
116 : virtual void SAL_CALL rowHeadingChanged( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
117 :
118 : // XEventListener
119 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& i_event ) throw (::com::sun::star::uno::RuntimeException);
120 :
121 : // XInterface
122 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
123 : virtual void SAL_CALL acquire( ) throw ();
124 : virtual void SAL_CALL release( ) throw ();
125 :
126 : // XTypeProvider
127 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
128 : virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException);
129 :
130 : private:
131 : /** translates the given public index into one to be passed to our delegator
132 : @throws ::com::sun::star::lang::IndexOutOfBoundsException
133 : if the given index does not denote a valid row
134 : */
135 : ::sal_Int32 impl_getPrivateRowIndex_throw( ::sal_Int32 const i_publicRowIndex ) const;
136 :
137 : /** translates the given private row index to a public one
138 : */
139 : ::sal_Int32 impl_getPublicRowIndex_nothrow( ::sal_Int32 const i_privateRowIndex ) const;
140 :
141 560 : inline bool impl_isSorted_nothrow() const
142 : {
143 560 : return m_currentSortColumn >= 0;
144 : }
145 :
146 : /** rebuilds the index translation structure.
147 :
148 : Neither <member>m_currentSortColumn</member> nor <member>m_sortAscending</member> are touched by this method.
149 : Also, the given column index is not checked, this is the responsibility of the caller.
150 : */
151 : bool impl_reIndex_nothrow( ::sal_Int32 const i_columnIndex, sal_Bool const i_sortAscending );
152 :
153 : /** translates the given event, obtained from our delegator, to a version which can be broadcasted to our own
154 : clients.
155 : */
156 : ::com::sun::star::awt::grid::GridDataEvent
157 : impl_createPublicEvent( ::com::sun::star::awt::grid::GridDataEvent const & i_originalEvent ) const;
158 :
159 : /** broadcasts the given event to our registered XGridDataListeners
160 : */
161 : void impl_broadcast(
162 : void ( SAL_CALL ::com::sun::star::awt::grid::XGridDataListener::*i_listenerMethod )( const ::com::sun::star::awt::grid::GridDataEvent & ),
163 : ::com::sun::star::awt::grid::GridDataEvent const & i_publicEvent,
164 : MethodGuard& i_instanceLock
165 : );
166 :
167 : /** rebuilds our indexes, notifying row removal and row addition events
168 :
169 : First, a rowsRemoved event is notified to our registered listeners. Then, the index translation tables are
170 : rebuilt, and a rowsInserted event is notified.
171 :
172 : Only to be called when we're sorted.
173 : */
174 : void impl_rebuildIndexesAndNotify( MethodGuard& i_instanceLock );
175 :
176 : /** removes the current sorting, and notifies a change of all data
177 : */
178 : void impl_removeColumnSort( MethodGuard& i_instanceLock );
179 :
180 : /** removes the current sorting, without any broadcast
181 : */
182 : void impl_removeColumnSort_noBroadcast();
183 :
184 : private:
185 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
186 : bool m_isInitialized;
187 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XMutableGridDataModel > m_delegator;
188 : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > m_collator;
189 : ::sal_Int32 m_currentSortColumn;
190 : ::sal_Bool m_sortAscending;
191 : ::std::vector< ::sal_Int32 > m_publicToPrivateRowIndex;
192 : ::std::vector< ::sal_Int32 > m_privateToPublicRowIndex;
193 : };
194 :
195 : //......................................................................................................................
196 : } // namespace toolkit
197 : //......................................................................................................................
198 :
199 : #endif // TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
200 :
201 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|