1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "unogridcolumnfacade.hxx"
#include "unocontroltablemodel.hxx"
#include <com/sun/star/awt/grid/XGridColumn.hpp>
#include <com/sun/star/awt/grid/XGridColumnListener.hpp>
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
#include <vcl/svapp.hxx>
#include <cppuhelper/implbase.hxx>
namespace svt::table
{
using css::uno::Reference;
using css::awt::grid::XGridColumn;
using css::uno::Exception;
using css::awt::grid::XGridColumnListener;
using css::lang::EventObject;
using css::awt::grid::GridColumnEvent;
using css::style::HorizontalAlignment_LEFT;
using css::style::HorizontalAlignment;
namespace
{
template< class T1, class T2 >
void lcl_set( Reference< XGridColumn > const & i_column, void ( SAL_CALL XGridColumn::*i_setter )( T1 ),
T2 i_value )
{
try
{
(i_column.get()->*i_setter) ( i_value );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svtools.uno");
}
}
template< class ATTRIBUTE_TYPE >
ATTRIBUTE_TYPE lcl_get( Reference< XGridColumn > const & i_column, ATTRIBUTE_TYPE ( SAL_CALL XGridColumn::*i_getter )() )
{
ATTRIBUTE_TYPE value = ATTRIBUTE_TYPE();
try
{
value = (i_column.get()->*i_getter)();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svtools.uno");
}
return value;
}
}
//= ColumnChangeMultiplexer
typedef ::cppu::WeakImplHelper < XGridColumnListener
> ColumnChangeMultiplexer_Base;
class ColumnChangeMultiplexer :public ColumnChangeMultiplexer_Base
{
public:
explicit ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl );
ColumnChangeMultiplexer(const ColumnChangeMultiplexer&) = delete;
ColumnChangeMultiplexer& operator=(const ColumnChangeMultiplexer&) = delete;
void dispose();
protected:
virtual ~ColumnChangeMultiplexer() override;
// XGridColumnListener
virtual void SAL_CALL columnChanged( const GridColumnEvent& i_event ) override;
// XEventListener
virtual void SAL_CALL disposing( const EventObject& i_event ) override;
private:
UnoGridColumnFacade* m_pColumnImplementation;
};
ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl )
:m_pColumnImplementation( &i_colImpl )
{
}
ColumnChangeMultiplexer::~ColumnChangeMultiplexer()
{
}
void ColumnChangeMultiplexer::dispose()
{
DBG_TESTSOLARMUTEX();
m_pColumnImplementation = nullptr;
}
void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event )
{
if ( i_event.AttributeName == "DataColumnIndex" )
{
SolarMutexGuard aGuard;
if ( m_pColumnImplementation != nullptr )
m_pColumnImplementation->dataColumnIndexChanged();
return;
}
ColumnAttributeGroup nChangedAttributes( ColumnAttributeGroup::NONE );
if ( i_event.AttributeName == "HorizontalAlign" )
nChangedAttributes |= ColumnAttributeGroup::APPEARANCE;
if ( i_event.AttributeName == "ColumnWidth"
|| i_event.AttributeName == "MaxWidth"
|| i_event.AttributeName == "MinWidth"
|| i_event.AttributeName == "PreferredWidth"
|| i_event.AttributeName == "Resizeable"
|| i_event.AttributeName == "Flexibility"
)
nChangedAttributes |= ColumnAttributeGroup::WIDTH;
OSL_ENSURE( nChangedAttributes != ColumnAttributeGroup::NONE,
"ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
SolarMutexGuard aGuard;
if ( m_pColumnImplementation != nullptr )
m_pColumnImplementation->columnChanged( nChangedAttributes );
}
void SAL_CALL ColumnChangeMultiplexer::disposing( const EventObject& )
{
}
//= UnoGridColumnFacade
UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel const & i_owner, Reference< XGridColumn > const & i_gridColumn )
:m_pOwner( &i_owner )
,m_nDataColumnIndex( -1 )
,m_xGridColumn( i_gridColumn, css::uno::UNO_SET_THROW )
,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) )
{
m_xGridColumn->addGridColumnListener( m_pChangeMultiplexer );
impl_updateDataColumnIndex_nothrow();
}
UnoGridColumnFacade::~UnoGridColumnFacade()
{
}
void UnoGridColumnFacade::dispose()
{
DBG_TESTSOLARMUTEX();
ENSURE_OR_RETURN_VOID( m_pOwner != nullptr, "UnoGridColumnFacade::dispose: already disposed!" );
m_xGridColumn->removeGridColumnListener( m_pChangeMultiplexer );
m_pChangeMultiplexer->dispose();
m_pChangeMultiplexer.clear();
m_xGridColumn.clear();
m_pOwner = nullptr;
}
void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow()
{
m_nDataColumnIndex = -1;
ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
try
{
m_nDataColumnIndex = m_xGridColumn->getDataColumnIndex();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svtools.uno");
}
}
void UnoGridColumnFacade::dataColumnIndexChanged()
{
DBG_TESTSOLARMUTEX();
impl_updateDataColumnIndex_nothrow();
if ( m_pOwner != nullptr )
m_pOwner->notifyAllDataChanged();
}
void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup const i_attributeGroup )
{
DBG_TESTSOLARMUTEX();
if ( m_pOwner != nullptr )
m_pOwner->notifyColumnChange( m_pOwner->getColumnPos( *this ), i_attributeGroup );
}
OUString UnoGridColumnFacade::getName() const
{
OUString sName;
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sName );
try
{
sName = m_xGridColumn->getTitle();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svtools.uno");
}
return sName;
}
OUString UnoGridColumnFacade::getHelpText() const
{
OUString sHelpText;
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sHelpText );
try
{
sHelpText = m_xGridColumn->getHelpText();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svtools.uno");
}
return sHelpText;
}
bool UnoGridColumnFacade::isResizable() const
{
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", false );
return lcl_get( m_xGridColumn, &XGridColumn::getResizeable );
}
sal_Int32 UnoGridColumnFacade::getFlexibility() const
{
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 1 );
return lcl_get( m_xGridColumn, &XGridColumn::getFlexibility );
}
TableMetrics UnoGridColumnFacade::getWidth() const
{
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth );
}
void UnoGridColumnFacade::setWidth( TableMetrics _nWidth )
{
ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
lcl_set( m_xGridColumn, &XGridColumn::setColumnWidth, _nWidth );
}
TableMetrics UnoGridColumnFacade::getMinWidth() const
{
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth );
}
TableMetrics UnoGridColumnFacade::getMaxWidth() const
{
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth );
}
css::style::HorizontalAlignment UnoGridColumnFacade::getHorizontalAlign()
{
ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT );
return lcl_get( m_xGridColumn, &XGridColumn::getHorizontalAlign );
}
} // svt::table
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|