/src/libreoffice/toolkit/source/controls/unogridcolumnfacade.cxx
Line | Count | Source |
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 | | #include "unogridcolumnfacade.hxx" |
21 | | #include "unocontroltablemodel.hxx" |
22 | | |
23 | | #include <com/sun/star/awt/grid/XGridColumn.hpp> |
24 | | #include <com/sun/star/awt/grid/XGridColumnListener.hpp> |
25 | | |
26 | | #include <tools/debug.hxx> |
27 | | #include <comphelper/diagnose_ex.hxx> |
28 | | #include <vcl/svapp.hxx> |
29 | | #include <cppuhelper/implbase.hxx> |
30 | | |
31 | | |
32 | | namespace svt::table |
33 | | { |
34 | | |
35 | | |
36 | | using css::uno::Reference; |
37 | | using css::awt::grid::XGridColumn; |
38 | | using css::uno::Exception; |
39 | | using css::awt::grid::XGridColumnListener; |
40 | | using css::lang::EventObject; |
41 | | using css::awt::grid::GridColumnEvent; |
42 | | using css::style::HorizontalAlignment_LEFT; |
43 | | using css::style::HorizontalAlignment; |
44 | | |
45 | | |
46 | | namespace |
47 | | { |
48 | | template< class T1, class T2 > |
49 | | void lcl_set( Reference< XGridColumn > const & i_column, void ( SAL_CALL XGridColumn::*i_setter )( T1 ), |
50 | | T2 i_value ) |
51 | 0 | { |
52 | 0 | try |
53 | 0 | { |
54 | 0 | (i_column.get()->*i_setter) ( i_value ); |
55 | 0 | } |
56 | 0 | catch( const Exception& ) |
57 | 0 | { |
58 | 0 | DBG_UNHANDLED_EXCEPTION("svtools.uno"); |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | | template< class ATTRIBUTE_TYPE > |
63 | | ATTRIBUTE_TYPE lcl_get( Reference< XGridColumn > const & i_column, ATTRIBUTE_TYPE ( SAL_CALL XGridColumn::*i_getter )() ) |
64 | 0 | { |
65 | 0 | ATTRIBUTE_TYPE value = ATTRIBUTE_TYPE(); |
66 | 0 | try |
67 | 0 | { |
68 | 0 | value = (i_column.get()->*i_getter)(); |
69 | 0 | } |
70 | 0 | catch( const Exception& ) |
71 | 0 | { |
72 | 0 | DBG_UNHANDLED_EXCEPTION("svtools.uno"); |
73 | 0 | } |
74 | 0 | return value; |
75 | 0 | } Unexecuted instantiation: unogridcolumnfacade.cxx:unsigned char svt::table::(anonymous namespace)::lcl_get<unsigned char>(com::sun::star::uno::Reference<com::sun::star::awt::grid::XGridColumn> const&, unsigned char (com::sun::star::awt::grid::XGridColumn::*)()) Unexecuted instantiation: unogridcolumnfacade.cxx:int svt::table::(anonymous namespace)::lcl_get<int>(com::sun::star::uno::Reference<com::sun::star::awt::grid::XGridColumn> const&, int (com::sun::star::awt::grid::XGridColumn::*)()) Unexecuted instantiation: unogridcolumnfacade.cxx:com::sun::star::style::HorizontalAlignment svt::table::(anonymous namespace)::lcl_get<com::sun::star::style::HorizontalAlignment>(com::sun::star::uno::Reference<com::sun::star::awt::grid::XGridColumn> const&, com::sun::star::style::HorizontalAlignment (com::sun::star::awt::grid::XGridColumn::*)()) |
76 | | } |
77 | | |
78 | | |
79 | | //= ColumnChangeMultiplexer |
80 | | |
81 | | typedef ::cppu::WeakImplHelper < XGridColumnListener |
82 | | > ColumnChangeMultiplexer_Base; |
83 | | class ColumnChangeMultiplexer :public ColumnChangeMultiplexer_Base |
84 | | { |
85 | | public: |
86 | | explicit ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl ); |
87 | | ColumnChangeMultiplexer(const ColumnChangeMultiplexer&) = delete; |
88 | | ColumnChangeMultiplexer& operator=(const ColumnChangeMultiplexer&) = delete; |
89 | | |
90 | | void dispose(); |
91 | | |
92 | | protected: |
93 | | virtual ~ColumnChangeMultiplexer() override; |
94 | | |
95 | | // XGridColumnListener |
96 | | virtual void SAL_CALL columnChanged( const GridColumnEvent& i_event ) override; |
97 | | |
98 | | // XEventListener |
99 | | virtual void SAL_CALL disposing( const EventObject& i_event ) override; |
100 | | |
101 | | private: |
102 | | UnoGridColumnFacade* m_pColumnImplementation; |
103 | | }; |
104 | | |
105 | | |
106 | | ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl ) |
107 | 0 | :m_pColumnImplementation( &i_colImpl ) |
108 | 0 | { |
109 | 0 | } |
110 | | |
111 | | |
112 | | ColumnChangeMultiplexer::~ColumnChangeMultiplexer() |
113 | 0 | { |
114 | 0 | } |
115 | | |
116 | | |
117 | | void ColumnChangeMultiplexer::dispose() |
118 | 0 | { |
119 | 0 | DBG_TESTSOLARMUTEX(); |
120 | 0 | m_pColumnImplementation = nullptr; |
121 | 0 | } |
122 | | |
123 | | |
124 | | void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event ) |
125 | 0 | { |
126 | 0 | if ( i_event.AttributeName == "DataColumnIndex" ) |
127 | 0 | { |
128 | 0 | SolarMutexGuard aGuard; |
129 | 0 | if ( m_pColumnImplementation != nullptr ) |
130 | 0 | m_pColumnImplementation->dataColumnIndexChanged(); |
131 | 0 | return; |
132 | 0 | } |
133 | | |
134 | 0 | ColumnAttributeGroup nChangedAttributes( ColumnAttributeGroup::NONE ); |
135 | |
|
136 | 0 | if ( i_event.AttributeName == "HorizontalAlign" ) |
137 | 0 | nChangedAttributes |= ColumnAttributeGroup::APPEARANCE; |
138 | |
|
139 | 0 | if ( i_event.AttributeName == "ColumnWidth" |
140 | 0 | || i_event.AttributeName == "MaxWidth" |
141 | 0 | || i_event.AttributeName == "MinWidth" |
142 | 0 | || i_event.AttributeName == "PreferredWidth" |
143 | 0 | || i_event.AttributeName == "Resizeable" |
144 | 0 | || i_event.AttributeName == "Flexibility" |
145 | 0 | ) |
146 | 0 | nChangedAttributes |= ColumnAttributeGroup::WIDTH; |
147 | |
|
148 | 0 | OSL_ENSURE( nChangedAttributes != ColumnAttributeGroup::NONE, |
149 | 0 | "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" ); |
150 | |
|
151 | 0 | SolarMutexGuard aGuard; |
152 | 0 | if ( m_pColumnImplementation != nullptr ) |
153 | 0 | m_pColumnImplementation->columnChanged( nChangedAttributes ); |
154 | 0 | } |
155 | | |
156 | | |
157 | | void SAL_CALL ColumnChangeMultiplexer::disposing( const EventObject& ) |
158 | 0 | { |
159 | 0 | } |
160 | | |
161 | | |
162 | | //= UnoGridColumnFacade |
163 | | |
164 | | |
165 | | UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel const & i_owner, Reference< XGridColumn > const & i_gridColumn ) |
166 | 0 | :m_pOwner( &i_owner ) |
167 | 0 | ,m_nDataColumnIndex( -1 ) |
168 | 0 | ,m_xGridColumn( i_gridColumn, css::uno::UNO_SET_THROW ) |
169 | 0 | ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) ) |
170 | 0 | { |
171 | 0 | m_xGridColumn->addGridColumnListener( m_pChangeMultiplexer ); |
172 | 0 | impl_updateDataColumnIndex_nothrow(); |
173 | 0 | } |
174 | | |
175 | | |
176 | | UnoGridColumnFacade::~UnoGridColumnFacade() |
177 | 0 | { |
178 | 0 | } |
179 | | |
180 | | |
181 | | void UnoGridColumnFacade::dispose() |
182 | 0 | { |
183 | 0 | DBG_TESTSOLARMUTEX(); |
184 | 0 | ENSURE_OR_RETURN_VOID( m_pOwner != nullptr, "UnoGridColumnFacade::dispose: already disposed!" ); |
185 | |
|
186 | 0 | m_xGridColumn->removeGridColumnListener( m_pChangeMultiplexer ); |
187 | 0 | m_pChangeMultiplexer->dispose(); |
188 | 0 | m_pChangeMultiplexer.clear(); |
189 | 0 | m_xGridColumn.clear(); |
190 | 0 | m_pOwner = nullptr; |
191 | 0 | } |
192 | | |
193 | | |
194 | | void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow() |
195 | 0 | { |
196 | 0 | m_nDataColumnIndex = -1; |
197 | 0 | ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" ); |
198 | 0 | try |
199 | 0 | { |
200 | 0 | m_nDataColumnIndex = m_xGridColumn->getDataColumnIndex(); |
201 | 0 | } |
202 | 0 | catch( const Exception& ) |
203 | 0 | { |
204 | 0 | DBG_UNHANDLED_EXCEPTION("svtools.uno"); |
205 | 0 | } |
206 | 0 | } |
207 | | |
208 | | |
209 | | void UnoGridColumnFacade::dataColumnIndexChanged() |
210 | 0 | { |
211 | 0 | DBG_TESTSOLARMUTEX(); |
212 | 0 | impl_updateDataColumnIndex_nothrow(); |
213 | 0 | if ( m_pOwner != nullptr ) |
214 | 0 | m_pOwner->notifyAllDataChanged(); |
215 | 0 | } |
216 | | |
217 | | |
218 | | void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup const i_attributeGroup ) |
219 | 0 | { |
220 | 0 | DBG_TESTSOLARMUTEX(); |
221 | 0 | if ( m_pOwner != nullptr ) |
222 | 0 | m_pOwner->notifyColumnChange( m_pOwner->getColumnPos( *this ), i_attributeGroup ); |
223 | 0 | } |
224 | | |
225 | | |
226 | | OUString UnoGridColumnFacade::getName() const |
227 | 0 | { |
228 | 0 | OUString sName; |
229 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sName ); |
230 | 0 | try |
231 | 0 | { |
232 | 0 | sName = m_xGridColumn->getTitle(); |
233 | 0 | } |
234 | 0 | catch( const Exception& ) |
235 | 0 | { |
236 | 0 | DBG_UNHANDLED_EXCEPTION("svtools.uno"); |
237 | 0 | } |
238 | 0 | return sName; |
239 | 0 | } |
240 | | |
241 | | |
242 | | OUString UnoGridColumnFacade::getHelpText() const |
243 | 0 | { |
244 | 0 | OUString sHelpText; |
245 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sHelpText ); |
246 | 0 | try |
247 | 0 | { |
248 | 0 | sHelpText = m_xGridColumn->getHelpText(); |
249 | 0 | } |
250 | 0 | catch( const Exception& ) |
251 | 0 | { |
252 | 0 | DBG_UNHANDLED_EXCEPTION("svtools.uno"); |
253 | 0 | } |
254 | 0 | return sHelpText; |
255 | 0 | } |
256 | | |
257 | | |
258 | | bool UnoGridColumnFacade::isResizable() const |
259 | 0 | { |
260 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", false ); |
261 | 0 | return lcl_get( m_xGridColumn, &XGridColumn::getResizeable ); |
262 | 0 | } |
263 | | |
264 | | |
265 | | sal_Int32 UnoGridColumnFacade::getFlexibility() const |
266 | 0 | { |
267 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 1 ); |
268 | 0 | return lcl_get( m_xGridColumn, &XGridColumn::getFlexibility ); |
269 | 0 | } |
270 | | |
271 | | |
272 | | TableMetrics UnoGridColumnFacade::getWidth() const |
273 | 0 | { |
274 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 ); |
275 | 0 | return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth ); |
276 | 0 | } |
277 | | |
278 | | |
279 | | void UnoGridColumnFacade::setWidth( TableMetrics _nWidth ) |
280 | 0 | { |
281 | 0 | ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" ); |
282 | 0 | lcl_set( m_xGridColumn, &XGridColumn::setColumnWidth, _nWidth ); |
283 | 0 | } |
284 | | |
285 | | |
286 | | TableMetrics UnoGridColumnFacade::getMinWidth() const |
287 | 0 | { |
288 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 ); |
289 | 0 | return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth ); |
290 | 0 | } |
291 | | |
292 | | |
293 | | TableMetrics UnoGridColumnFacade::getMaxWidth() const |
294 | 0 | { |
295 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 ); |
296 | 0 | return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth ); |
297 | 0 | } |
298 | | |
299 | | |
300 | | css::style::HorizontalAlignment UnoGridColumnFacade::getHorizontalAlign() |
301 | 0 | { |
302 | 0 | ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT ); |
303 | 0 | return lcl_get( m_xGridColumn, &XGridColumn::getHorizontalAlign ); |
304 | 0 | } |
305 | | |
306 | | |
307 | | } // svt::table |
308 | | |
309 | | |
310 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |