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 OUString s_sResourceResolver
= u
"ResourceResolver"_ustr
;
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 SAL_CALL
UnoControlTabPage::disposing( const lang::EventObject
& Source
)
191 ControlContainerBase::disposing( Source
);
194 void UnoControlTabPage::createPeer( const Reference
< XToolkit
> & rxToolkit
, const Reference
< XWindowPeer
> & rParentPeer
)
196 SolarMutexGuard aSolarGuard
;
197 ImplUpdateResourceResolver();
199 UnoControlContainer::createPeer( rxToolkit
, rParentPeer
);
201 Reference
< tab::XTabPage
> xTabPage( getPeer(), UNO_QUERY
);
204 if ( !m_bWindowListener
)
206 Reference
< XWindowListener
> xWL(this);
207 addWindowListener( xWL
);
208 m_bWindowListener
= true;
213 static ::Size
ImplMapPixelToAppFont( OutputDevice
const * pOutDev
, const ::Size
& aSize
)
215 ::Size aTmp
= pOutDev
->PixelToLogic(aSize
, MapMode(MapUnit::MapAppFont
));
218 // css::awt::XWindowListener
219 void SAL_CALL
UnoControlTabPage::windowResized( const css::awt::WindowEvent
& e
)
221 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
222 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
223 if ( !pOutDev
|| mbSizeModified
)
226 // Currently we are simply using MapUnit::MapAppFont
227 ::Size
aAppFontSize( e
.Width
, e
.Height
);
229 Reference
< XControl
> xDialogControl( *this, UNO_QUERY_THROW
);
230 Reference
< XDevice
> xDialogDevice( xDialogControl
->getPeer(), UNO_QUERY
);
231 OSL_ENSURE( xDialogDevice
.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
232 if ( xDialogDevice
.is() )
234 DeviceInfo
aDeviceInfo( xDialogDevice
->getInfo() );
235 aAppFontSize
.AdjustWidth( -(aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
) );
236 aAppFontSize
.AdjustHeight( -(aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
) );
239 aAppFontSize
= ImplMapPixelToAppFont( pOutDev
, aAppFontSize
);
241 // Remember that changes have been done by listener. No need to
242 // update the position because of property change event.
243 mbSizeModified
= true;
244 // Properties in a sequence must be sorted!
245 Sequence
< OUString
> aProps
{ "Height", "Width" };
246 Sequence
< Any
> aValues
{ Any(aAppFontSize
.Height()), Any(aAppFontSize
.Width()) };
248 ImplSetPropertyValues( aProps
, aValues
, true );
249 mbSizeModified
= false;
253 void SAL_CALL
UnoControlTabPage::windowMoved( const css::awt::WindowEvent
& e
)
255 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
256 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
257 if ( !pOutDev
|| mbPosModified
)
260 // Currently we are simply using MapUnit::MapAppFont
261 ::Size
aTmp( e
.X
, e
.Y
);
262 aTmp
= ImplMapPixelToAppFont( pOutDev
, aTmp
);
264 // Remember that changes have been done by listener. No need to
265 // update the position because of property change event.
266 mbPosModified
= true;
267 Sequence
< OUString
> aProps
{ "PositionX", "PositionY" };
268 Sequence
< Any
> aValues
{ Any(aTmp
.Width()), Any(aTmp
.Height()) };
270 ImplSetPropertyValues( aProps
, aValues
, true );
271 mbPosModified
= false;
275 void SAL_CALL
UnoControlTabPage::windowShown( const css::lang::EventObject
& ) {}
277 void SAL_CALL
UnoControlTabPage::windowHidden( const css::lang::EventObject
& ) {}
279 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
280 stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
281 css::uno::XComponentContext
*context
,
282 css::uno::Sequence
<css::uno::Any
> const &)
284 return cppu::acquire(new UnoControlTabPageModel(context
));
287 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
288 stardiv_Toolkit_UnoControlTabPage_get_implementation(
289 css::uno::XComponentContext
*context
,
290 css::uno::Sequence
<css::uno::Any
> const &)
292 return cppu::acquire(new UnoControlTabPage(context
));
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */