1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <toolkit/controls/tabpagemodel.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/window.hxx>
24 #include <vcl/wall.hxx>
25 #include <toolkit/helper/property.hxx>
26 #include <toolkit/controls/stdtabcontroller.hxx>
27 #include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
28 #include <com/sun/star/awt/tab/XTabPage.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <tools/debug.hxx>
34 #include <tools/diagnose_ex.h>
35 #include <comphelper/sequence.hxx>
36 #include <vcl/outdev.hxx>
38 #include <vcl/graph.hxx>
39 #include <vcl/image.hxx>
40 #include <toolkit/controls/geometrycontrolmodel.hxx>
41 #include <toolkit/controls/controlmodelcontainerbase.hxx>
42 #include <toolkit/controls/unocontrolcontainer.hxx>
43 #include <cppuhelper/basemutex.hxx>
45 #include <helper/unopropertyarrayhelper.hxx>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::awt
;
51 UnoControlTabPageModel::UnoControlTabPageModel( Reference
< XComponentContext
> const & i_factory
)
52 :ControlModelContainerBase( i_factory
)
54 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL
);
55 ImplRegisterProperty( BASEPROPERTY_TITLE
);
56 ImplRegisterProperty( BASEPROPERTY_HELPTEXT
);
57 ImplRegisterProperty( BASEPROPERTY_HELPURL
);
60 OUString SAL_CALL
UnoControlTabPageModel::getImplementationName()
62 return OUString("stardiv.Toolkit.UnoControlTabPageModel");
65 css::uno::Sequence
< OUString
> SAL_CALL
UnoControlTabPageModel::getSupportedServiceNames()
67 css::uno::Sequence
< OUString
> aNames
= ControlModelContainerBase::getSupportedServiceNames( );
68 aNames
.realloc( aNames
.getLength() + 1 );
69 aNames
[ aNames
.getLength() - 1 ] = "com.sun.star.awt.tab.UnoControlTabPageModel";
73 OUString
UnoControlTabPageModel::getServiceName( )
75 return OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
78 Any
UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
84 case BASEPROPERTY_DEFAULTCONTROL
:
85 aAny
<<= OUString("com.sun.star.awt.tab.UnoControlTabPage");
88 aAny
= UnoControlModel::ImplGetDefaultValue( nPropId
);
94 ::cppu::IPropertyArrayHelper
& UnoControlTabPageModel::getInfoHelper()
96 static UnoPropertyArrayHelper
* pHelper
= nullptr;
99 Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
100 pHelper
= new UnoPropertyArrayHelper( aIDs
);
104 // beans::XMultiPropertySet
105 uno::Reference
< beans::XPropertySetInfo
> UnoControlTabPageModel::getPropertySetInfo( )
107 static uno::Reference
< beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
110 ////----- XInitialization -------------------------------------------------------------------
111 void SAL_CALL
UnoControlTabPageModel::initialize (const Sequence
<Any
>& rArguments
)
113 sal_Int16 nPageId
= -1;
114 if ( rArguments
.getLength() == 1 )
116 if ( !( rArguments
[ 0 ] >>= nPageId
))
117 throw lang::IllegalArgumentException();
118 m_nTabPageId
= nPageId
;
120 else if ( rArguments
.getLength() == 2 )
122 if ( !( rArguments
[ 0 ] >>= nPageId
))
123 throw lang::IllegalArgumentException();
124 m_nTabPageId
= nPageId
;
126 if ( !( rArguments
[ 1 ] >>= sURL
))
127 throw lang::IllegalArgumentException();
128 Reference
<container::XNameContainer
> xDialogModel
= awt::UnoControlDialogModelProvider::create( m_xContext
, sURL
);
129 if ( xDialogModel
.is() )
131 Sequence
< OUString
> aNames
= xDialogModel
->getElementNames();
132 const OUString
* pIter
= aNames
.getConstArray();
133 const OUString
* pEnd
= pIter
+ aNames
.getLength();
134 for(;pIter
!= pEnd
;++pIter
)
138 Any
aElement(xDialogModel
->getByName(*pIter
));
139 xDialogModel
->removeByName(*pIter
);
140 insertByName(*pIter
,aElement
);
142 catch(const Exception
&) {}
144 Reference
<XPropertySet
> xDialogProp(xDialogModel
,UNO_QUERY
);
145 if ( xDialogProp
.is() )
147 static const char s_sResourceResolver
[] = "ResourceResolver";
148 Reference
<XPropertySet
> xThis(*this,UNO_QUERY
);
149 xThis
->setPropertyValue(s_sResourceResolver
,xDialogProp
->getPropertyValue(s_sResourceResolver
));
150 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
)));
151 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
)));
152 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
)));
161 UnoControlTabPage::UnoControlTabPage( const uno::Reference
< uno::XComponentContext
>& rxContext
)
162 :UnoControlTabPage_Base(rxContext
)
163 ,m_bWindowListener(false)
165 maComponentInfos
.nWidth
= 280;
166 maComponentInfos
.nHeight
= 400;
168 UnoControlTabPage::~UnoControlTabPage()
172 OUString
UnoControlTabPage::GetComponentServiceName()
174 return OUString("TabPageModel");
177 OUString SAL_CALL
UnoControlTabPage::getImplementationName()
179 return OUString("stardiv.Toolkit.UnoControlTabPage");
182 sal_Bool SAL_CALL
UnoControlTabPage::supportsService(OUString
const & ServiceName
)
184 return cppu::supportsService(this, ServiceName
);
187 css::uno::Sequence
<OUString
> SAL_CALL
UnoControlTabPage::getSupportedServiceNames()
189 css::uno::Sequence
< OUString
> aSeq
{ "com.sun.star.awt.tab.UnoControlTabPage" };
193 void UnoControlTabPage::dispose()
195 SolarMutexGuard aSolarGuard
;
197 lang::EventObject aEvt
;
198 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >( this );
199 ControlContainerBase::dispose();
202 void SAL_CALL
UnoControlTabPage::disposing( const lang::EventObject
& Source
)
204 ControlContainerBase::disposing( Source
);
207 void UnoControlTabPage::createPeer( const Reference
< XToolkit
> & rxToolkit
, const Reference
< XWindowPeer
> & rParentPeer
)
209 SolarMutexGuard aSolarGuard
;
210 ImplUpdateResourceResolver();
212 UnoControlContainer::createPeer( rxToolkit
, rParentPeer
);
214 Reference
< tab::XTabPage
> xTabPage( getPeer(), UNO_QUERY
);
217 if ( !m_bWindowListener
)
219 Reference
< XWindowListener
> xWL( static_cast< cppu::OWeakObject
*>( this ), UNO_QUERY
);
220 addWindowListener( xWL
);
221 m_bWindowListener
= true;
226 static ::Size
ImplMapPixelToAppFont( OutputDevice
const * pOutDev
, const ::Size
& aSize
)
228 ::Size aTmp
= pOutDev
->PixelToLogic(aSize
, MapMode(MapUnit::MapAppFont
));
231 // css::awt::XWindowListener
232 void SAL_CALL
UnoControlTabPage::windowResized( const css::awt::WindowEvent
& e
)
234 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
235 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
236 if ( !pOutDev
|| mbSizeModified
)
239 // Currentley we are simply using MapUnit::MapAppFont
240 ::Size
aAppFontSize( e
.Width
, e
.Height
);
242 Reference
< XControl
> xDialogControl( *this, UNO_QUERY_THROW
);
243 Reference
< XDevice
> xDialogDevice( xDialogControl
->getPeer(), UNO_QUERY
);
244 OSL_ENSURE( xDialogDevice
.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
245 if ( xDialogDevice
.is() )
247 DeviceInfo
aDeviceInfo( xDialogDevice
->getInfo() );
248 aAppFontSize
.AdjustWidth( -(aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
) );
249 aAppFontSize
.AdjustHeight( -(aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
) );
252 aAppFontSize
= ImplMapPixelToAppFont( pOutDev
, aAppFontSize
);
254 // Remember that changes have been done by listener. No need to
255 // update the position because of property change event.
256 mbSizeModified
= true;
257 Sequence
< OUString
> aProps( 2 );
258 Sequence
< Any
> aValues( 2 );
259 // Properties in a sequence must be sorted!
260 aProps
[0] = "Height";
262 aValues
[0] <<= aAppFontSize
.Height();
263 aValues
[1] <<= aAppFontSize
.Width();
265 ImplSetPropertyValues( aProps
, aValues
, true );
266 mbSizeModified
= false;
270 void SAL_CALL
UnoControlTabPage::windowMoved( const css::awt::WindowEvent
& e
)
272 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
273 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
274 if ( !pOutDev
|| mbPosModified
)
277 // Currentley we are simply using MapUnit::MapAppFont
278 ::Size
aTmp( e
.X
, e
.Y
);
279 aTmp
= ImplMapPixelToAppFont( pOutDev
, aTmp
);
281 // Remember that changes have been done by listener. No need to
282 // update the position because of property change event.
283 mbPosModified
= true;
284 Sequence
< OUString
> aProps( 2 );
285 Sequence
< Any
> aValues( 2 );
286 aProps
[0] = "PositionX";
287 aProps
[1] = "PositionY";
288 aValues
[0] <<= aTmp
.Width();
289 aValues
[1] <<= aTmp
.Height();
291 ImplSetPropertyValues( aProps
, aValues
, true );
292 mbPosModified
= false;
296 void SAL_CALL
UnoControlTabPage::windowShown( const css::lang::EventObject
& ) {}
298 void SAL_CALL
UnoControlTabPage::windowHidden( const css::lang::EventObject
& ) {}
300 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
301 stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
302 css::uno::XComponentContext
*context
,
303 css::uno::Sequence
<css::uno::Any
> const &)
305 return cppu::acquire(new UnoControlTabPageModel(context
));
308 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
309 stardiv_Toolkit_UnoControlTabPage_get_implementation(
310 css::uno::XComponentContext
*context
,
311 css::uno::Sequence
<css::uno::Any
> const &)
313 return cppu::acquire(new UnoControlTabPage(context
));
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */