LibreOffice Module toolkit (master) 1
unogridcolumnfacade.cxx
Go to the documentation of this file.
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
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>
28#include <vcl/svapp.hxx>
30
31
32namespace 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 {
52 try
53 {
54 (i_column.get()->*i_setter) ( i_value );
55 }
56 catch( const Exception& )
57 {
58 DBG_UNHANDLED_EXCEPTION("svtools.uno");
59 }
60 }
61
62 template< class ATTRIBUTE_TYPE >
63 ATTRIBUTE_TYPE lcl_get( Reference< XGridColumn > const & i_column, ATTRIBUTE_TYPE ( SAL_CALL XGridColumn::*i_getter )() )
64 {
65 ATTRIBUTE_TYPE value = ATTRIBUTE_TYPE();
66 try
67 {
68 value = (i_column.get()->*i_getter)();
69 }
70 catch( const Exception& )
71 {
72 DBG_UNHANDLED_EXCEPTION("svtools.uno");
73 }
74 return value;
75 }
76 }
77
78
79 //= ColumnChangeMultiplexer
80
81 typedef ::cppu::WeakImplHelper < XGridColumnListener
84 {
85 public:
86 explicit ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl );
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:
103 };
104
105
107 :m_pColumnImplementation( &i_colImpl )
108 {
109 }
110
111
113 {
114 }
115
116
118 {
120 m_pColumnImplementation = nullptr;
121 }
122
123
124 void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event )
125 {
126 if ( i_event.AttributeName == "DataColumnIndex" )
127 {
128 SolarMutexGuard aGuard;
129 if ( m_pColumnImplementation != nullptr )
131 return;
132 }
133
135
136 if ( i_event.AttributeName == "HorizontalAlign" )
137 nChangedAttributes |= ColumnAttributeGroup::APPEARANCE;
138
139 if ( i_event.AttributeName == "ColumnWidth"
140 || i_event.AttributeName == "MaxWidth"
141 || i_event.AttributeName == "MinWidth"
142 || i_event.AttributeName == "PreferredWidth"
143 || i_event.AttributeName == "Resizeable"
144 || i_event.AttributeName == "Flexibility"
145 )
146 nChangedAttributes |= ColumnAttributeGroup::WIDTH;
147
148 OSL_ENSURE( nChangedAttributes != ColumnAttributeGroup::NONE,
149 "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
150
151 SolarMutexGuard aGuard;
152 if ( m_pColumnImplementation != nullptr )
153 m_pColumnImplementation->columnChanged( nChangedAttributes );
154 }
155
156
157 void SAL_CALL ColumnChangeMultiplexer::disposing( const EventObject& )
158 {
159 }
160
161
162 //= UnoGridColumnFacade
163
164
165 UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel const & i_owner, Reference< XGridColumn > const & i_gridColumn )
166 :m_pOwner( &i_owner )
167 ,m_nDataColumnIndex( -1 )
168 ,m_xGridColumn( i_gridColumn, css::uno::UNO_SET_THROW )
169 ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) )
170 {
171 m_xGridColumn->addGridColumnListener( m_pChangeMultiplexer );
172 impl_updateDataColumnIndex_nothrow();
173 }
174
175
177 {
178 }
179
180
182 {
184 ENSURE_OR_RETURN_VOID( m_pOwner != nullptr, "UnoGridColumnFacade::dispose: already disposed!" );
185
186 m_xGridColumn->removeGridColumnListener( m_pChangeMultiplexer );
187 m_pChangeMultiplexer->dispose();
188 m_pChangeMultiplexer.clear();
189 m_xGridColumn.clear();
190 m_pOwner = nullptr;
191 }
192
193
195 {
197 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
198 try
199 {
200 m_nDataColumnIndex = m_xGridColumn->getDataColumnIndex();
201 }
202 catch( const Exception& )
203 {
204 DBG_UNHANDLED_EXCEPTION("svtools.uno");
205 }
206 }
207
208
210 {
213 if ( m_pOwner != nullptr )
215 }
216
217
219 {
221 if ( m_pOwner != nullptr )
222 m_pOwner->notifyColumnChange( m_pOwner->getColumnPos( *this ), i_attributeGroup );
223 }
224
225
227 {
228 OUString sName;
229 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sName );
230 try
231 {
232 sName = m_xGridColumn->getTitle();
233 }
234 catch( const Exception& )
235 {
236 DBG_UNHANDLED_EXCEPTION("svtools.uno");
237 }
238 return sName;
239 }
240
241
243 {
244 OUString sHelpText;
245 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sHelpText );
246 try
247 {
248 sHelpText = m_xGridColumn->getHelpText();
249 }
250 catch( const Exception& )
251 {
252 DBG_UNHANDLED_EXCEPTION("svtools.uno");
253 }
254 return sHelpText;
255 }
256
257
259 {
260 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", false );
261 return lcl_get( m_xGridColumn, &XGridColumn::getResizeable );
262 }
263
264
266 {
267 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 1 );
268 return lcl_get( m_xGridColumn, &XGridColumn::getFlexibility );
269 }
270
271
273 {
274 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
275 return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth );
276 }
277
278
280 {
281 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
282 lcl_set( m_xGridColumn, &XGridColumn::setColumnWidth, _nWidth );
283 }
284
285
287 {
288 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
289 return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth );
290 }
291
292
294 {
295 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
296 return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth );
297 }
298
299
300 css::style::HorizontalAlignment UnoGridColumnFacade::getHorizontalAlign()
301 {
302 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT );
303 return lcl_get( m_xGridColumn, &XGridColumn::getHorizontalAlign );
304 }
305
306
307} // svt::table
308
309
310/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL disposing(const EventObject &i_event) override
ColumnChangeMultiplexer & operator=(const ColumnChangeMultiplexer &)=delete
virtual void SAL_CALL columnChanged(const GridColumnEvent &i_event) override
ColumnChangeMultiplexer(UnoGridColumnFacade &i_colImpl)
ColumnChangeMultiplexer(const ColumnChangeMultiplexer &)=delete
ColPos getColumnPos(UnoGridColumnFacade const &i_column) const
retrieves the index of a column within the model
void notifyAllDataChanged() const
notifies a change in all data represented by the model.
void notifyColumnChange(ColPos const i_columnPos, ColumnAttributeGroup const i_attributeGroup) const
notifies a change in a column belonging to the model
virtual bool isResizable() const override
determines whether the column can be interactively resized
virtual sal_Int32 getFlexibility() const override
denotes the relative flexibility of the column
UnoGridColumnFacade(UnoControlTableModel const &i_owner, css::uno::Reference< css::awt::grid::XGridColumn > const &i_gridColumn)
virtual void setWidth(TableMetrics _nWidth) override
sets a new width for the column
virtual TableMetrics getMaxWidth() const override
returns the maximum width of the column, in app-font units, or 0 if the column does not have a minima...
void dispose()
disposes the column wrapper
virtual OUString getHelpText() const override
retrieves the help text to be displayed for the column.
virtual TableMetrics getMinWidth() const override
returns the minimum width of the column, in app-font units, or 0 if the column does not have a minima...
void columnChanged(ColumnAttributeGroup const i_attributeGroup)
UnoControlTableModel const * m_pOwner
virtual css::style::HorizontalAlignment getHorizontalAlign() override
retrieves the horizontal alignment to be used for content in this cell
virtual OUString getName() const override
returns the name of the column
::rtl::Reference< ColumnChangeMultiplexer > m_pChangeMultiplexer
virtual TableMetrics getWidth() const override
returns the width of the column, in app-font units
css::uno::Reference< css::awt::grid::XGridColumn > m_xGridColumn
Any value
#define DBG_TESTSOLARMUTEX()
#define ENSURE_OR_RETURN(c, m, r)
#define DBG_UNHANDLED_EXCEPTION(...)
#define ENSURE_OR_RETURN_VOID(c, m)
OUString sName
@ Exception
sal_Int32 TableMetrics
Definition: tabletypes.hxx:36
::cppu::WeakImplHelper< XGridColumnListener > ColumnChangeMultiplexer_Base
ContentProvider * m_pOwner
ColumnAttributeGroup
Definition: tablemodel.hxx:42
@ APPEARANCE
denotes column attributes related to the appearance of the column, i.e. those relevant for rendering
@ WIDTH
denotes column attributes related to the width of the column