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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
/* -*- 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 <controls/geometrycontrolmodel.hxx>
#include <controls/tabpagecontainer.hxx>
#include <controls/tabpagemodel.hxx>
#include <helper/property.hxx>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <o3tl/safeint.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <vcl/svapp.hxx>
#include <helper/unopropertyarrayhelper.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::view;
using ::com::sun::star::awt::tab::XTabPageModel;
constexpr OUStringLiteral WRONG_TYPE_EXCEPTION = u"Type must be css::awt::tab::XTabPageModel!";
UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference< XComponentContext >& i_factory )
:UnoControlTabPageContainerModel_Base( i_factory )
,maContainerListeners( *this )
{
ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
ImplRegisterProperty( BASEPROPERTY_BORDER );
ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
ImplRegisterProperty( BASEPROPERTY_ENABLED );
ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
ImplRegisterProperty( BASEPROPERTY_HELPURL );
ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
ImplRegisterProperty( BASEPROPERTY_TEXT );
}
OUString UnoControlTabPageContainerModel::getServiceName()
{
return "com.sun.star.awt.tab.UnoControlTabPageContainerModel";
}
uno::Any UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
{
switch(nPropId)
{
case BASEPROPERTY_DEFAULTCONTROL:
return uno::Any( OUString("com.sun.star.awt.tab.UnoControlTabPageContainer") );
case BASEPROPERTY_BORDER:
return uno::Any(sal_Int16(0)); // No Border
default:
return UnoControlModel::ImplGetDefaultValue( nPropId );
}
}
::cppu::IPropertyArrayHelper& UnoControlTabPageContainerModel::getInfoHelper()
{
static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() );
return aHelper;
}
Reference< css::beans::XPropertySetInfo > UnoControlTabPageContainerModel::getPropertySetInfo( )
{
static Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
return xInfo;
}
namespace
{
Reference< XTabPageModel > lcl_createTabPageModel( Reference<XComponentContext> const & i_context,
Sequence< Any > const & i_initArguments, Reference< XPropertySet > const & i_parentModel )
{
try
{
Reference< XPropertySetInfo > const xPSI( i_parentModel->getPropertySetInfo() );
bool const isGeometryControlModel = xPSI.is() && xPSI->hasPropertyByName("PositionX");
Reference< XInterface > xInstance;
if ( isGeometryControlModel )
xInstance = *( new OGeometryControlModel< UnoControlTabPageModel >( i_context ) );
else
xInstance = *( new UnoControlTabPageModel( i_context ) );
Reference< XTabPageModel > const xTabPageModel( xInstance, UNO_QUERY_THROW );
Reference< XInitialization > const xInit( xTabPageModel, UNO_QUERY_THROW );
xInit->initialize( i_initArguments );
return xTabPageModel;
}
catch( const RuntimeException& )
{
throw;
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("toolkit.controls");
}
return nullptr;
}
}
Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID )
{
Sequence< Any > aInitArgs{ Any(i_tabPageID) };
return lcl_createTabPageModel( m_xContext, aInitArgs, this );
}
Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::loadTabPage( ::sal_Int16 i_tabPageID, const OUString& i_resourceURL )
{
Sequence< Any > aInitArgs{ Any(i_tabPageID), Any(i_resourceURL) };
return lcl_createTabPageModel( m_xContext, aInitArgs, this );
}
void SAL_CALL UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex, const css::uno::Any& aElement)
{
SolarMutexGuard aSolarGuard;
uno::Reference < XTabPageModel > xTabPageModel;
if(!(aElement >>= xTabPageModel))
throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, getXWeak(), 2 );
if ( sal_Int32( m_aTabPageVector.size()) ==nIndex )
m_aTabPageVector.push_back( xTabPageModel );
else if ( sal_Int32( m_aTabPageVector.size()) > nIndex )
{
std::vector< uno::Reference< XTabPageModel > >::iterator aIter = m_aTabPageVector.begin();
aIter += nIndex;
m_aTabPageVector.insert( aIter, xTabPageModel );
}
else
throw IndexOutOfBoundsException( OUString(), getXWeak() );
ContainerEvent aEvent;
aEvent.Source = *this;
aEvent.Element = aElement;
aEvent.Accessor <<= OUString::number(nIndex);
maContainerListeners.elementInserted( aEvent );
}
void SAL_CALL UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32 /*Index*/ )
{
}
// XIndexReplace
void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Index*/, const uno::Any& /*Element*/ )
{
}
// XIndexAccess
::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount( )
{
std::unique_lock aGuard( m_aMutex );
return sal_Int32( m_aTabPageVector.size());
}
uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex )
{
std::unique_lock aGuard( m_aMutex );
if ( nIndex < 0 || o3tl::make_unsigned(nIndex) > m_aTabPageVector.size() )
throw lang::IndexOutOfBoundsException();
return uno::Any(m_aTabPageVector[nIndex]);
}
// XElementAccess
uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType( )
{
return cppu::UnoType<css::awt::XControlModel>::get();
}
sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements( )
{
std::unique_lock aGuard( m_aMutex );
return !m_aTabPageVector.empty();
}
// XContainer
void UnoControlTabPageContainerModel::addContainerListener( const Reference< XContainerListener >& l )
{
maContainerListeners.addInterface( l );
}
void UnoControlTabPageContainerModel::removeContainerListener( const Reference< XContainerListener >& l )
{
maContainerListeners.removeInterface( l );
}
UnoControlTabPageContainer::UnoControlTabPageContainer( const uno::Reference< uno::XComponentContext >& rxContext )
:UnoControlTabPageContainer_Base(rxContext)
,m_aTabPageListeners( *this )
{
}
OUString UnoControlTabPageContainer::GetComponentServiceName() const
{
return "TabPageContainer";
}
void SAL_CALL UnoControlTabPageContainer::dispose( )
{
lang::EventObject aEvt;
aEvt.Source = getXWeak();
m_aTabPageListeners.disposeAndClear( aEvt );
UnoControl::dispose();
}
void UnoControlTabPageContainer::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
{
UnoControlBase::createPeer( rxToolkit, rParentPeer );
Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
if ( m_aTabPageListeners.getLength() )
xTPContainer->addTabPageContainerListener(&m_aTabPageListeners);
}
// XTabPageContainer
::sal_Int16 SAL_CALL UnoControlTabPageContainer::getActiveTabPageID()
{
SolarMutexGuard aSolarGuard;
Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
return xTPContainer->getActiveTabPageID();
}
void SAL_CALL UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid )
{
SolarMutexGuard aSolarGuard;
Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
xTPContainer->setActiveTabPageID(_activetabpageid);
}
::sal_Int16 SAL_CALL UnoControlTabPageContainer::getTabPageCount( )
{
SolarMutexGuard aSolarGuard;
Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
return xTPContainer->getTabPageCount();
}
sal_Bool SAL_CALL UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex )
{
SolarMutexGuard aSolarGuard;
Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
return xTPContainer->isTabPageActive(tabPageIndex);
}
Reference< css::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex )
{
SolarMutexGuard aSolarGuard;
Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
return xTPContainer->getTabPage(tabPageIndex);
}
Reference< css::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID )
{
SolarMutexGuard aSolarGuard;
Reference< XTabPageContainer > xTPContainer( getPeer(), UNO_QUERY_THROW );
return xTPContainer->getTabPageByID(tabPageID);
}
void SAL_CALL UnoControlTabPageContainer::addTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
{
m_aTabPageListeners.addInterface( listener );
if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
{
uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
}
}
void SAL_CALL UnoControlTabPageContainer::removeTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
{
if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
{
uno::Reference < awt::tab::XTabPageContainer > xTabPageContainer( getPeer(), uno::UNO_QUERY );
xTabPageContainer->removeTabPageContainerListener( &m_aTabPageListeners );
}
m_aTabPageListeners.removeInterface( listener );
}
void UnoControlTabPageContainer::propertiesChange(const::css::uno::Sequence<PropertyChangeEvent> &aEvent)
{
UnoControlTabPageContainer_Base::propertiesChange(aEvent);
SolarMutexGuard aSolarGuard;
Reference< XPropertiesChangeListener > xPropertiesChangeListener( getPeer(), UNO_QUERY_THROW );
return xPropertiesChangeListener->propertiesChange(aEvent);
}
void UnoControlTabPageContainer::updateFromModel()
{
UnoControlTabPageContainer_Base::updateFromModel();
if (!getPeer().is())
throw RuntimeException("No peer for tabpage container!");
Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
ENSURE_OR_RETURN_VOID( xContainerListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
ContainerEvent aEvent;
aEvent.Source = getModel();
const Sequence< Reference< XControl > > aControls = getControls();
for ( const Reference< XControl >& rCtrl : aControls )
{
aEvent.Element <<= rCtrl;
xContainerListener->elementInserted( aEvent );
}
}
void SAL_CALL UnoControlTabPageContainer::addControl( const OUString& Name, const Reference< css::awt::XControl >& Control )
{
SolarMutexGuard aSolarGuard;
ControlContainerBase::addControl(Name,Control);
if (!getPeer().is())
throw RuntimeException("No peer for tabpage container!");
Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
ContainerEvent aEvent;
aEvent.Source = getModel();
aEvent.Element <<= Control;
xContainerListener->elementInserted( aEvent );
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
stardiv_Toolkit_UnoControlTabPageContainerModel_get_implementation(
css::uno::XComponentContext *context,
css::uno::Sequence<css::uno::Any> const &)
{
return cppu::acquire(new UnoControlTabPageContainerModel(context));
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
stardiv_Toolkit_UnoControlTabPageContainer_get_implementation(
css::uno::XComponentContext *context,
css::uno::Sequence<css::uno::Any> const &)
{
return cppu::acquire(new UnoControlTabPageContainer(context));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|