Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 : : *
5 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
6 : : *
7 : : * OpenOffice.org - a multi-platform office productivity suite
8 : : *
9 : : * This file is part of OpenOffice.org.
10 : : *
11 : : * OpenOffice.org is free software: you can redistribute it and/or modify
12 : : * it under the terms of the GNU Lesser General Public License version 3
13 : : * only, as published by the Free Software Foundation.
14 : : *
15 : : * OpenOffice.org is distributed in the hope that it will be useful,
16 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : : * GNU Lesser General Public License version 3 for more details
19 : : * (a copy is included in the LICENSE file that accompanied this code).
20 : : *
21 : : * You should have received a copy of the GNU Lesser General Public License
22 : : * version 3 along with OpenOffice.org. If not, see
23 : : * <http://www.openoffice.org/license.html>
24 : : * for a copy of the LGPLv3 License.
25 : : *
26 : : ************************************************************************/
27 : :
28 : : #ifndef TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
29 : : #define TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
30 : :
31 : : #include "initguard.hxx"
32 : :
33 : : #include <com/sun/star/awt/grid/XSortableMutableGridDataModel.hpp>
34 : : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : : #include <com/sun/star/lang/XInitialization.hpp>
36 : : #include <com/sun/star/i18n/XCollator.hpp>
37 : : #include <com/sun/star/awt/grid/XGridDataListener.hpp>
38 : :
39 : : #include <comphelper/componentcontext.hxx>
40 : : #include <cppuhelper/basemutex.hxx>
41 : : #include <cppuhelper/compbase3.hxx>
42 : : #include <cppuhelper/implbase1.hxx>
43 : :
44 : : //......................................................................................................................
45 : : namespace toolkit
46 : : {
47 : : //......................................................................................................................
48 : :
49 : : class SortableGridDataModel;
50 : : typedef InitGuard< SortableGridDataModel > MethodGuard;
51 : :
52 : : //==================================================================================================================
53 : : //= SortableGridDataModel
54 : : //==================================================================================================================
55 : : typedef ::cppu::WeakComponentImplHelper3 < ::com::sun::star::awt::grid::XSortableMutableGridDataModel
56 : : , ::com::sun::star::lang::XServiceInfo
57 : : , ::com::sun::star::lang::XInitialization
58 : : > SortableGridDataModel_Base;
59 : : typedef ::cppu::ImplHelper1 < ::com::sun::star::awt::grid::XGridDataListener
60 : : > SortableGridDataModel_PrivateBase;
61 : : class SortableGridDataModel :public ::cppu::BaseMutex
62 : : ,public SortableGridDataModel_Base
63 : : ,public SortableGridDataModel_PrivateBase
64 : : {
65 : : public:
66 : : SortableGridDataModel( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > const & i_factory );
67 : : SortableGridDataModel( SortableGridDataModel const & i_copySource );
68 : :
69 : 0 : bool isInitialized() const { return m_isInitialized; }
70 : :
71 : : #ifdef DBG_UTIL
72 : : const char* checkInvariants() const;
73 : : #endif
74 : :
75 : : protected:
76 : : ~SortableGridDataModel();
77 : :
78 : : public:
79 : : // XSortableGridData
80 : : virtual void SAL_CALL sortByColumn( ::sal_Int32 ColumnIndex, ::sal_Bool SortAscending ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
81 : : virtual void SAL_CALL removeColumnSort( ) throw (::com::sun::star::uno::RuntimeException);
82 : : virtual ::com::sun::star::beans::Pair< ::sal_Int32, ::sal_Bool > SAL_CALL getCurrentSortOrder( ) throw (::com::sun::star::uno::RuntimeException);
83 : :
84 : : // XMutableGridDataModel
85 : : 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);
86 : : 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);
87 : : virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
88 : : virtual void SAL_CALL removeAllRows( ) throw (::com::sun::star::uno::RuntimeException);
89 : : 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);
90 : : 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);
91 : : 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);
92 : : 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);
93 : : 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);
94 : : virtual void SAL_CALL addGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
95 : : virtual void SAL_CALL removeGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
96 : :
97 : : // XGridDataModel
98 : : virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException);
99 : : virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException);
100 : : virtual ::com::sun::star::uno::Any SAL_CALL getCellData( ::sal_Int32 Column, ::sal_Int32 Row ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
101 : : virtual ::com::sun::star::uno::Any SAL_CALL getCellToolTip( ::sal_Int32 Column, ::sal_Int32 Row ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
102 : : virtual ::com::sun::star::uno::Any SAL_CALL getRowHeading( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
103 : :
104 : : // OComponentHelper
105 : : virtual void SAL_CALL disposing();
106 : :
107 : : // XCloneable
108 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone( ) throw (::com::sun::star::uno::RuntimeException);
109 : :
110 : : // XServiceInfo
111 : : virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
112 : : virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
113 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
114 : :
115 : : // XInitialization
116 : : 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);
117 : :
118 : : // XGridDataListener
119 : : virtual void SAL_CALL rowsInserted( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
120 : : virtual void SAL_CALL rowsRemoved( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
121 : : virtual void SAL_CALL dataChanged( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
122 : : virtual void SAL_CALL rowHeadingChanged( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
123 : :
124 : : // XEventListener
125 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& i_event ) throw (::com::sun::star::uno::RuntimeException);
126 : :
127 : : // XInterface
128 : : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
129 : : virtual void SAL_CALL acquire( ) throw ();
130 : : virtual void SAL_CALL release( ) throw ();
131 : :
132 : : // XTypeProvider
133 : : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
134 : : virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException);
135 : :
136 : : private:
137 : : /** translates the given public index into one to be passed to our delegator
138 : : @throws ::com::sun::star::lang::IndexOutOfBoundsException
139 : : if the given index does not denote a valid row
140 : : */
141 : : ::sal_Int32 impl_getPrivateRowIndex_throw( ::sal_Int32 const i_publicRowIndex ) const;
142 : :
143 : : /** translates the given private row index to a public one
144 : : */
145 : : ::sal_Int32 impl_getPublicRowIndex_nothrow( ::sal_Int32 const i_privateRowIndex ) const;
146 : :
147 : 0 : inline bool impl_isSorted_nothrow() const
148 : : {
149 : 0 : return m_currentSortColumn >= 0;
150 : : }
151 : :
152 : : /** rebuilds the index translation structure.
153 : :
154 : : Neither <member>m_currentSortColumn</member> nor <member>m_sortAscending</member> are touched by this method.
155 : : Also, the given column index is not checked, this is the responsibility of the caller.
156 : : */
157 : : void impl_reIndex_nothrow( ::sal_Int32 const i_columnIndex, sal_Bool const i_sortAscending );
158 : :
159 : : /** translates the given event, obtained from our delegator, to a version which can be broadcasted to our own
160 : : clients.
161 : : */
162 : : ::com::sun::star::awt::grid::GridDataEvent
163 : : impl_createPublicEvent( ::com::sun::star::awt::grid::GridDataEvent const & i_originalEvent ) const;
164 : :
165 : : /** broadcasts the given event to our registered XGridDataListeners
166 : : */
167 : : void impl_broadcast(
168 : : void ( SAL_CALL ::com::sun::star::awt::grid::XGridDataListener::*i_listenerMethod )( const ::com::sun::star::awt::grid::GridDataEvent & ),
169 : : ::com::sun::star::awt::grid::GridDataEvent const & i_publicEvent,
170 : : MethodGuard& i_instanceLock
171 : : );
172 : :
173 : : /** rebuilds our indexes, notifying row removal and row addition events
174 : :
175 : : First, a rowsRemoved event is notified to our registered listeners. Then, the index translation tables are
176 : : rebuilt, and a rowsInserted event is notified.
177 : :
178 : : Only to be called when we're sorted.
179 : : */
180 : : void impl_rebuildIndexesAndNotify( MethodGuard& i_instanceLock );
181 : :
182 : : private:
183 : : ::comphelper::ComponentContext m_context;
184 : : bool m_isInitialized;
185 : : ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XMutableGridDataModel > m_delegator;
186 : : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > m_collator;
187 : : ::sal_Int32 m_currentSortColumn;
188 : : ::sal_Bool m_sortAscending;
189 : : ::std::vector< ::sal_Int32 > m_publicToPrivateRowIndex;
190 : : ::std::vector< ::sal_Int32 > m_privateToPublicRowIndex;
191 : : };
192 : :
193 : : //......................................................................................................................
194 : : } // namespace toolkit
195 : : //......................................................................................................................
196 : :
197 : : #endif // TOOLKIT_SORTABLEGRIDDATAMODEL_HXX
198 : :
199 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|