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 <controls/tabpagemodel.hxx>
22 #include <vcl/svapp.hxx>
23 #include <helper/property.hxx>
24 #include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
25 #include <com/sun/star/awt/tab/XTabPage.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <tools/debug.hxx>
30 #include <vcl/outdev.hxx>
32 #include <controls/controlmodelcontainerbase.hxx>
33 #include <controls/unocontrolcontainer.hxx>
35 #include <helper/unopropertyarrayhelper.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::awt
;
41 UnoControlTabPageModel::UnoControlTabPageModel( Reference
< XComponentContext
> const & i_factory
)
42 :ControlModelContainerBase( i_factory
)
44 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL
);
45 ImplRegisterProperty( BASEPROPERTY_TITLE
);
46 ImplRegisterProperty( BASEPROPERTY_HELPTEXT
);
47 ImplRegisterProperty( BASEPROPERTY_HELPURL
);
48 ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES
);
49 ImplRegisterProperty( BASEPROPERTY_HSCROLL
);
50 ImplRegisterProperty( BASEPROPERTY_VSCROLL
);
51 ImplRegisterProperty( BASEPROPERTY_SCROLLWIDTH
);
52 ImplRegisterProperty( BASEPROPERTY_SCROLLHEIGHT
);
53 ImplRegisterProperty( BASEPROPERTY_SCROLLTOP
);
54 ImplRegisterProperty( BASEPROPERTY_SCROLLLEFT
);
55 ImplRegisterProperty( BASEPROPERTY_IMAGEURL
);
58 OUString SAL_CALL
UnoControlTabPageModel::getImplementationName()
60 return "stardiv.Toolkit.UnoControlTabPageModel";
63 css::uno::Sequence
< OUString
> SAL_CALL
UnoControlTabPageModel::getSupportedServiceNames()
65 css::uno::Sequence
< OUString
> aNames
= ControlModelContainerBase::getSupportedServiceNames( );
66 aNames
.realloc( aNames
.getLength() + 1 );
67 aNames
.getArray()[ aNames
.getLength() - 1 ] = "com.sun.star.awt.tab.UnoControlTabPageModel";
71 OUString
UnoControlTabPageModel::getServiceName( )
73 return "com.sun.star.awt.tab.UnoControlTabPageModel";
76 Any
UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
82 case BASEPROPERTY_DEFAULTCONTROL
:
83 aAny
<<= OUString("com.sun.star.awt.tab.UnoControlTabPage");
85 case BASEPROPERTY_USERFORMCONTAINEES
:
87 // We do not have here any usercontainers (yet?), but let's return empty container back
88 // so normal properties could be set without triggering UnknownPropertyException
89 aAny
<<= uno::Reference
< XNameContainer
>();
93 aAny
= UnoControlModel::ImplGetDefaultValue( nPropId
);
99 ::cppu::IPropertyArrayHelper
& UnoControlTabPageModel::getInfoHelper()
101 static UnoPropertyArrayHelper
aHelper( ImplGetPropertyIds() );
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 const Sequence
< OUString
> aNames
= xDialogModel
->getElementNames();
132 for(const OUString
& rName
: aNames
)
136 Any
aElement(xDialogModel
->getByName(rName
));
137 xDialogModel
->removeByName(rName
);
138 insertByName(rName
,aElement
);
140 catch(const Exception
&) {}
142 Reference
<XPropertySet
> xDialogProp(xDialogModel
,UNO_QUERY
);
143 if ( xDialogProp
.is() )
145 static constexpr OUStringLiteral s_sResourceResolver
= u
"ResourceResolver";
146 setPropertyValue(s_sResourceResolver
,xDialogProp
->getPropertyValue(s_sResourceResolver
));
147 setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
)));
148 setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
)));
149 setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
)));
158 UnoControlTabPage::UnoControlTabPage( const uno::Reference
< uno::XComponentContext
>& rxContext
)
159 :UnoControlTabPage_Base(rxContext
)
160 ,m_bWindowListener(false)
162 maComponentInfos
.nWidth
= 280;
163 maComponentInfos
.nHeight
= 400;
165 UnoControlTabPage::~UnoControlTabPage()
169 OUString
UnoControlTabPage::GetComponentServiceName() const
171 return "TabPageModel";
174 OUString SAL_CALL
UnoControlTabPage::getImplementationName()
176 return "stardiv.Toolkit.UnoControlTabPage";
179 sal_Bool SAL_CALL
UnoControlTabPage::supportsService(OUString
const & ServiceName
)
181 return cppu::supportsService(this, ServiceName
);
184 css::uno::Sequence
<OUString
> SAL_CALL
UnoControlTabPage::getSupportedServiceNames()
186 return { "com.sun.star.awt.tab.UnoControlTabPage" };
189 void UnoControlTabPage::dispose()
191 SolarMutexGuard aSolarGuard
;
193 lang::EventObject aEvt
;
194 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >( this );
195 ControlContainerBase::dispose();
198 void SAL_CALL
UnoControlTabPage::disposing( const lang::EventObject
& Source
)
200 ControlContainerBase::disposing( Source
);
203 void UnoControlTabPage::createPeer( const Reference
< XToolkit
> & rxToolkit
, const Reference
< XWindowPeer
> & rParentPeer
)
205 SolarMutexGuard aSolarGuard
;
206 ImplUpdateResourceResolver();
208 UnoControlContainer::createPeer( rxToolkit
, rParentPeer
);
210 Reference
< tab::XTabPage
> xTabPage( getPeer(), UNO_QUERY
);
213 if ( !m_bWindowListener
)
215 Reference
< XWindowListener
> xWL(this);
216 addWindowListener( xWL
);
217 m_bWindowListener
= true;
222 static ::Size
ImplMapPixelToAppFont( OutputDevice
const * pOutDev
, const ::Size
& aSize
)
224 ::Size aTmp
= pOutDev
->PixelToLogic(aSize
, MapMode(MapUnit::MapAppFont
));
227 // css::awt::XWindowListener
228 void SAL_CALL
UnoControlTabPage::windowResized( const css::awt::WindowEvent
& e
)
230 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
231 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
232 if ( !pOutDev
|| mbSizeModified
)
235 // Currently we are simply using MapUnit::MapAppFont
236 ::Size
aAppFontSize( e
.Width
, e
.Height
);
238 Reference
< XControl
> xDialogControl( *this, UNO_QUERY_THROW
);
239 Reference
< XDevice
> xDialogDevice( xDialogControl
->getPeer(), UNO_QUERY
);
240 OSL_ENSURE( xDialogDevice
.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
241 if ( xDialogDevice
.is() )
243 DeviceInfo
aDeviceInfo( xDialogDevice
->getInfo() );
244 aAppFontSize
.AdjustWidth( -(aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
) );
245 aAppFontSize
.AdjustHeight( -(aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
) );
248 aAppFontSize
= ImplMapPixelToAppFont( pOutDev
, aAppFontSize
);
250 // Remember that changes have been done by listener. No need to
251 // update the position because of property change event.
252 mbSizeModified
= true;
253 // Properties in a sequence must be sorted!
254 Sequence
< OUString
> aProps
{ "Height", "Width" };
255 Sequence
< Any
> aValues
{ Any(aAppFontSize
.Height()), Any(aAppFontSize
.Width()) };
257 ImplSetPropertyValues( aProps
, aValues
, true );
258 mbSizeModified
= false;
262 void SAL_CALL
UnoControlTabPage::windowMoved( const css::awt::WindowEvent
& e
)
264 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
265 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
266 if ( !pOutDev
|| mbPosModified
)
269 // Currently we are simply using MapUnit::MapAppFont
270 ::Size
aTmp( e
.X
, e
.Y
);
271 aTmp
= ImplMapPixelToAppFont( pOutDev
, aTmp
);
273 // Remember that changes have been done by listener. No need to
274 // update the position because of property change event.
275 mbPosModified
= true;
276 Sequence
< OUString
> aProps
{ "PositionX", "PositionY" };
277 Sequence
< Any
> aValues
{ Any(aTmp
.Width()), Any(aTmp
.Height()) };
279 ImplSetPropertyValues( aProps
, aValues
, true );
280 mbPosModified
= false;
284 void SAL_CALL
UnoControlTabPage::windowShown( const css::lang::EventObject
& ) {}
286 void SAL_CALL
UnoControlTabPage::windowHidden( const css::lang::EventObject
& ) {}
288 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
289 stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
290 css::uno::XComponentContext
*context
,
291 css::uno::Sequence
<css::uno::Any
> const &)
293 return cppu::acquire(new UnoControlTabPageModel(context
));
296 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
297 stardiv_Toolkit_UnoControlTabPage_get_implementation(
298 css::uno::XComponentContext
*context
,
299 css::uno::Sequence
<css::uno::Any
> const &)
301 return cppu::acquire(new UnoControlTabPage(context
));
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */