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 <toolkit/helper/vclunohelper.hxx>
39 #include <unotools/ucbstreamhelper.hxx>
40 #include <vcl/graph.hxx>
41 #include <vcl/image.hxx>
42 #include <toolkit/controls/geometrycontrolmodel.hxx>
43 #include <toolkit/controls/controlmodelcontainerbase.hxx>
44 #include <toolkit/controls/unocontrolcontainer.hxx>
45 #include <cppuhelper/basemutex.hxx>
47 #include "helper/unopropertyarrayhelper.hxx"
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::awt
;
53 UnoControlTabPageModel::UnoControlTabPageModel( Reference
< XComponentContext
> const & i_factory
)
54 :ControlModelContainerBase( i_factory
)
56 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL
);
57 ImplRegisterProperty( BASEPROPERTY_TITLE
);
58 ImplRegisterProperty( BASEPROPERTY_HELPTEXT
);
59 ImplRegisterProperty( BASEPROPERTY_HELPURL
);
62 OUString SAL_CALL
UnoControlTabPageModel::getImplementationName()
64 return OUString("stardiv.Toolkit.UnoControlTabPageModel");
67 css::uno::Sequence
< OUString
> SAL_CALL
UnoControlTabPageModel::getSupportedServiceNames()
69 css::uno::Sequence
< OUString
> aNames
= ControlModelContainerBase::getSupportedServiceNames( );
70 aNames
.realloc( aNames
.getLength() + 1 );
71 aNames
[ aNames
.getLength() - 1 ] = "com.sun.star.awt.tab.UnoControlTabPageModel";
75 OUString
UnoControlTabPageModel::getServiceName( )
77 return OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
80 Any
UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
86 case BASEPROPERTY_DEFAULTCONTROL
:
87 aAny
<<= OUString("com.sun.star.awt.tab.UnoControlTabPage");
90 aAny
= UnoControlModel::ImplGetDefaultValue( nPropId
);
96 ::cppu::IPropertyArrayHelper
& UnoControlTabPageModel::getInfoHelper()
98 static UnoPropertyArrayHelper
* pHelper
= nullptr;
101 Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
102 pHelper
= new UnoPropertyArrayHelper( aIDs
);
106 // beans::XMultiPropertySet
107 uno::Reference
< beans::XPropertySetInfo
> UnoControlTabPageModel::getPropertySetInfo( )
109 static uno::Reference
< beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
112 ////----- XInitialization -------------------------------------------------------------------
113 void SAL_CALL
UnoControlTabPageModel::initialize (const Sequence
<Any
>& rArguments
)
115 sal_Int16 nPageId
= -1;
116 if ( rArguments
.getLength() == 1 )
118 if ( !( rArguments
[ 0 ] >>= nPageId
))
119 throw lang::IllegalArgumentException();
120 m_nTabPageId
= nPageId
;
122 else if ( rArguments
.getLength() == 2 )
124 if ( !( rArguments
[ 0 ] >>= nPageId
))
125 throw lang::IllegalArgumentException();
126 m_nTabPageId
= nPageId
;
128 if ( !( rArguments
[ 1 ] >>= sURL
))
129 throw lang::IllegalArgumentException();
130 Reference
<container::XNameContainer
> xDialogModel
= awt::UnoControlDialogModelProvider::create( m_xContext
, sURL
);
131 if ( xDialogModel
.is() )
133 Sequence
< OUString
> aNames
= xDialogModel
->getElementNames();
134 const OUString
* pIter
= aNames
.getConstArray();
135 const OUString
* pEnd
= pIter
+ aNames
.getLength();
136 for(;pIter
!= pEnd
;++pIter
)
140 Any
aElement(xDialogModel
->getByName(*pIter
));
141 xDialogModel
->removeByName(*pIter
);
142 insertByName(*pIter
,aElement
);
144 catch(const Exception
& ex
)
149 Reference
<XPropertySet
> xDialogProp(xDialogModel
,UNO_QUERY
);
150 if ( xDialogProp
.is() )
152 static const char s_sResourceResolver
[] = "ResourceResolver";
153 Reference
<XPropertySet
> xThis(*this,UNO_QUERY
);
154 xThis
->setPropertyValue(s_sResourceResolver
,xDialogProp
->getPropertyValue(s_sResourceResolver
));
155 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
)));
156 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
)));
157 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
)));
166 UnoControlTabPage::UnoControlTabPage( const uno::Reference
< uno::XComponentContext
>& rxContext
)
167 :UnoControlTabPage_Base(rxContext
)
168 ,m_bWindowListener(false)
170 maComponentInfos
.nWidth
= 280;
171 maComponentInfos
.nHeight
= 400;
173 UnoControlTabPage::~UnoControlTabPage()
177 OUString
UnoControlTabPage::GetComponentServiceName()
179 return OUString("TabPageModel");
182 OUString SAL_CALL
UnoControlTabPage::getImplementationName()
184 return OUString("stardiv.Toolkit.UnoControlTabPage");
187 sal_Bool SAL_CALL
UnoControlTabPage::supportsService(OUString
const & ServiceName
)
189 return cppu::supportsService(this, ServiceName
);
192 css::uno::Sequence
<OUString
> SAL_CALL
UnoControlTabPage::getSupportedServiceNames()
194 css::uno::Sequence
< OUString
> aSeq
{ "com.sun.star.awt.tab.UnoControlTabPage" };
198 void UnoControlTabPage::dispose()
200 SolarMutexGuard aSolarGuard
;
202 lang::EventObject aEvt
;
203 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >( this );
204 ControlContainerBase::dispose();
207 void SAL_CALL
UnoControlTabPage::disposing( const lang::EventObject
& Source
)
209 ControlContainerBase::disposing( Source
);
212 void UnoControlTabPage::createPeer( const Reference
< XToolkit
> & rxToolkit
, const Reference
< XWindowPeer
> & rParentPeer
)
214 SolarMutexGuard aSolarGuard
;
215 ImplUpdateResourceResolver();
217 UnoControlContainer::createPeer( rxToolkit
, rParentPeer
);
219 Reference
< tab::XTabPage
> xTabPage( getPeer(), UNO_QUERY
);
222 if ( !m_bWindowListener
)
224 Reference
< XWindowListener
> xWL( static_cast< cppu::OWeakObject
*>( this ), UNO_QUERY
);
225 addWindowListener( xWL
);
226 m_bWindowListener
= true;
231 static ::Size
ImplMapPixelToAppFont( OutputDevice
* pOutDev
, const ::Size
& aSize
)
233 ::Size aTmp
= pOutDev
->PixelToLogic( aSize
, MapUnit::MapAppFont
);
236 // css::awt::XWindowListener
237 void SAL_CALL
UnoControlTabPage::windowResized( const css::awt::WindowEvent
& e
)
239 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
240 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
241 if ( pOutDev
&& !mbSizeModified
)
243 // Currentley we are simply using MapUnit::MapAppFont
244 ::Size
aAppFontSize( e
.Width
, e
.Height
);
246 Reference
< XControl
> xDialogControl( *this, UNO_QUERY_THROW
);
247 Reference
< XDevice
> xDialogDevice( xDialogControl
->getPeer(), UNO_QUERY
);
248 OSL_ENSURE( xDialogDevice
.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
249 if ( xDialogDevice
.is() )
251 DeviceInfo
aDeviceInfo( xDialogDevice
->getInfo() );
252 aAppFontSize
.Width() -= aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
;
253 aAppFontSize
.Height() -= aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
;
256 aAppFontSize
= ImplMapPixelToAppFont( pOutDev
, aAppFontSize
);
258 // Remember that changes have been done by listener. No need to
259 // update the position because of property change event.
260 mbSizeModified
= true;
261 Sequence
< OUString
> aProps( 2 );
262 Sequence
< Any
> aValues( 2 );
263 // Properties in a sequence must be sorted!
264 aProps
[0] = "Height";
266 aValues
[0] <<= aAppFontSize
.Height();
267 aValues
[1] <<= aAppFontSize
.Width();
269 ImplSetPropertyValues( aProps
, aValues
, true );
270 mbSizeModified
= false;
274 void SAL_CALL
UnoControlTabPage::windowMoved( const css::awt::WindowEvent
& e
)
276 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
277 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
278 if ( pOutDev
&& !mbPosModified
)
280 // Currentley we are simply using MapUnit::MapAppFont
281 ::Size
aTmp( e
.X
, e
.Y
);
282 aTmp
= ImplMapPixelToAppFont( pOutDev
, aTmp
);
284 // Remember that changes have been done by listener. No need to
285 // update the position because of property change event.
286 mbPosModified
= true;
287 Sequence
< OUString
> aProps( 2 );
288 Sequence
< Any
> aValues( 2 );
289 aProps
[0] = "PositionX";
290 aProps
[1] = "PositionY";
291 aValues
[0] <<= aTmp
.Width();
292 aValues
[1] <<= aTmp
.Height();
294 ImplSetPropertyValues( aProps
, aValues
, true );
295 mbPosModified
= false;
299 void SAL_CALL
UnoControlTabPage::windowShown( const css::lang::EventObject
& e
)
304 void SAL_CALL
UnoControlTabPage::windowHidden( const css::lang::EventObject
& e
)
309 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
310 stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
311 css::uno::XComponentContext
*context
,
312 css::uno::Sequence
<css::uno::Any
> const &)
314 return cppu::acquire(new UnoControlTabPageModel(context
));
317 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
318 stardiv_Toolkit_UnoControlTabPage_get_implementation(
319 css::uno::XComponentContext
*context
,
320 css::uno::Sequence
<css::uno::Any
> const &)
322 return cppu::acquire(new UnoControlTabPage(context
));
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */