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>
46 #include <cppuhelper/implbase2.hxx>
48 #include "helper/unopropertyarrayhelper.hxx"
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::awt
;
54 UnoControlTabPageModel::UnoControlTabPageModel( Reference
< XComponentContext
> const & i_factory
)
55 :ControlModelContainerBase( i_factory
)
57 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL
);
58 ImplRegisterProperty( BASEPROPERTY_TITLE
);
59 ImplRegisterProperty( BASEPROPERTY_HELPTEXT
);
60 ImplRegisterProperty( BASEPROPERTY_HELPURL
);
63 OUString SAL_CALL
UnoControlTabPageModel::getImplementationName() throw(css::uno::RuntimeException
, std::exception
)
65 return OUString("stardiv.Toolkit.UnoControlTabPageModel");
68 css::uno::Sequence
< OUString
> SAL_CALL
UnoControlTabPageModel::getSupportedServiceNames() throw(css::uno::RuntimeException
, std::exception
)
70 css::uno::Sequence
< OUString
> aNames
= ControlModelContainerBase::getSupportedServiceNames( );
71 aNames
.realloc( aNames
.getLength() + 1 );
72 aNames
[ aNames
.getLength() - 1 ] = "com.sun.star.awt.tab.UnoControlTabPageModel";
76 OUString
UnoControlTabPageModel::getServiceName( ) throw(RuntimeException
, std::exception
)
78 return OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
81 Any
UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
87 case BASEPROPERTY_DEFAULTCONTROL
:
88 aAny
<<= OUString("com.sun.star.awt.tab.UnoControlTabPage");
91 aAny
= UnoControlModel::ImplGetDefaultValue( nPropId
);
97 ::cppu::IPropertyArrayHelper
& UnoControlTabPageModel::getInfoHelper()
99 static UnoPropertyArrayHelper
* pHelper
= NULL
;
102 Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
103 pHelper
= new UnoPropertyArrayHelper( aIDs
);
107 // beans::XMultiPropertySet
108 uno::Reference
< beans::XPropertySetInfo
> UnoControlTabPageModel::getPropertySetInfo( ) throw(uno::RuntimeException
, std::exception
)
110 static uno::Reference
< beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
113 ////----- XInitialization -------------------------------------------------------------------
114 void SAL_CALL
UnoControlTabPageModel::initialize (const Sequence
<Any
>& rArguments
)
115 throw (com::sun::star::uno::Exception
, com::sun::star::uno::RuntimeException
, std::exception
)
117 sal_Int16 nPageId
= -1;
118 if ( rArguments
.getLength() == 1 )
120 if ( !( rArguments
[ 0 ] >>= nPageId
))
121 throw lang::IllegalArgumentException();
122 m_nTabPageId
= nPageId
;
124 else if ( rArguments
.getLength() == 2 )
126 if ( !( rArguments
[ 0 ] >>= nPageId
))
127 throw lang::IllegalArgumentException();
128 m_nTabPageId
= nPageId
;
130 if ( !( rArguments
[ 1 ] >>= sURL
))
131 throw lang::IllegalArgumentException();
132 Reference
<container::XNameContainer
> xDialogModel
= awt::UnoControlDialogModelProvider::create( m_xContext
, sURL
);
133 if ( xDialogModel
.is() )
135 Sequence
< OUString
> aNames
= xDialogModel
->getElementNames();
136 const OUString
* pIter
= aNames
.getConstArray();
137 const OUString
* pEnd
= pIter
+ aNames
.getLength();
138 for(;pIter
!= pEnd
;++pIter
)
142 Any
aElement(xDialogModel
->getByName(*pIter
));
143 xDialogModel
->removeByName(*pIter
);
144 insertByName(*pIter
,aElement
);
146 catch(const Exception
& ex
)
151 Reference
<XPropertySet
> xDialogProp(xDialogModel
,UNO_QUERY
);
152 if ( xDialogProp
.is() )
154 static const char s_sResourceResolver
[] = "ResourceResolver";
155 Reference
<XPropertySet
> xThis(*this,UNO_QUERY
);
156 xThis
->setPropertyValue(s_sResourceResolver
,xDialogProp
->getPropertyValue(s_sResourceResolver
));
157 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE
)));
158 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT
)));
159 xThis
->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
),xDialogProp
->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL
)));
168 UnoControlTabPage::UnoControlTabPage( const uno::Reference
< uno::XComponentContext
>& rxContext
)
169 :UnoControlTabPage_Base(rxContext
)
170 ,m_bWindowListener(false)
172 maComponentInfos
.nWidth
= 280;
173 maComponentInfos
.nHeight
= 400;
175 UnoControlTabPage::~UnoControlTabPage()
179 OUString
UnoControlTabPage::GetComponentServiceName()
181 return OUString("TabPageModel");
184 OUString SAL_CALL
UnoControlTabPage::getImplementationName()
185 throw (css::uno::RuntimeException
, std::exception
)
187 return OUString("stardiv.Toolkit.UnoControlTabPage");
190 sal_Bool SAL_CALL
UnoControlTabPage::supportsService(OUString
const & ServiceName
)
191 throw (css::uno::RuntimeException
, std::exception
)
193 return cppu::supportsService(this, ServiceName
);
196 css::uno::Sequence
<OUString
> SAL_CALL
UnoControlTabPage::getSupportedServiceNames()
197 throw (css::uno::RuntimeException
, std::exception
)
199 css::uno::Sequence
< OUString
> aSeq(1);
200 aSeq
[0] = "com.sun.star.awt.tab.UnoControlTabPage";
204 void UnoControlTabPage::dispose() throw(RuntimeException
, std::exception
)
206 SolarMutexGuard aSolarGuard
;
208 lang::EventObject aEvt
;
209 aEvt
.Source
= static_cast< ::cppu::OWeakObject
* >( this );
210 ControlContainerBase::dispose();
213 void SAL_CALL
UnoControlTabPage::disposing( const lang::EventObject
& Source
)throw(RuntimeException
, std::exception
)
215 ControlContainerBase::disposing( Source
);
218 void UnoControlTabPage::createPeer( const Reference
< XToolkit
> & rxToolkit
, const Reference
< XWindowPeer
> & rParentPeer
) throw(RuntimeException
, std::exception
)
220 SolarMutexGuard aSolarGuard
;
221 ImplUpdateResourceResolver();
223 UnoControlContainer::createPeer( rxToolkit
, rParentPeer
);
225 Reference
< tab::XTabPage
> xTabPage( getPeer(), UNO_QUERY
);
228 if ( !m_bWindowListener
)
230 Reference
< XWindowListener
> xWL( static_cast< cppu::OWeakObject
*>( this ), UNO_QUERY
);
231 addWindowListener( xWL
);
232 m_bWindowListener
= true;
237 static ::Size
ImplMapPixelToAppFont( OutputDevice
* pOutDev
, const ::Size
& aSize
)
239 ::Size aTmp
= pOutDev
->PixelToLogic( aSize
, MAP_APPFONT
);
242 // ::com::sun::star::awt::XWindowListener
243 void SAL_CALL
UnoControlTabPage::windowResized( const ::com::sun::star::awt::WindowEvent
& e
)
244 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
246 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
247 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
248 if ( pOutDev
&& !mbSizeModified
)
250 // Currentley we are simply using MAP_APPFONT
251 ::Size
aAppFontSize( e
.Width
, e
.Height
);
253 Reference
< XControl
> xDialogControl( *this, UNO_QUERY_THROW
);
254 Reference
< XDevice
> xDialogDevice( xDialogControl
->getPeer(), UNO_QUERY
);
255 OSL_ENSURE( xDialogDevice
.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
256 if ( xDialogDevice
.is() )
258 DeviceInfo
aDeviceInfo( xDialogDevice
->getInfo() );
259 aAppFontSize
.Width() -= aDeviceInfo
.LeftInset
+ aDeviceInfo
.RightInset
;
260 aAppFontSize
.Height() -= aDeviceInfo
.TopInset
+ aDeviceInfo
.BottomInset
;
263 aAppFontSize
= ImplMapPixelToAppFont( pOutDev
, aAppFontSize
);
265 // Remember that changes have been done by listener. No need to
266 // update the position because of property change event.
267 mbSizeModified
= true;
268 Sequence
< OUString
> aProps( 2 );
269 Sequence
< Any
> aValues( 2 );
270 // Properties in a sequence must be sorted!
271 aProps
[0] = "Height";
273 aValues
[0] <<= aAppFontSize
.Height();
274 aValues
[1] <<= aAppFontSize
.Width();
276 ImplSetPropertyValues( aProps
, aValues
, true );
277 mbSizeModified
= false;
281 void SAL_CALL
UnoControlTabPage::windowMoved( const ::com::sun::star::awt::WindowEvent
& e
)
282 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
284 OutputDevice
*pOutDev
= Application::GetDefaultDevice();
285 DBG_ASSERT( pOutDev
, "Missing Default Device!" );
286 if ( pOutDev
&& !mbPosModified
)
288 // Currentley we are simply using MAP_APPFONT
289 ::Size
aTmp( e
.X
, e
.Y
);
290 aTmp
= ImplMapPixelToAppFont( pOutDev
, aTmp
);
292 // Remember that changes have been done by listener. No need to
293 // update the position because of property change event.
294 mbPosModified
= true;
295 Sequence
< OUString
> aProps( 2 );
296 Sequence
< Any
> aValues( 2 );
297 aProps
[0] = "PositionX";
298 aProps
[1] = "PositionY";
299 aValues
[0] <<= aTmp
.Width();
300 aValues
[1] <<= aTmp
.Height();
302 ImplSetPropertyValues( aProps
, aValues
, true );
303 mbPosModified
= false;
307 void SAL_CALL
UnoControlTabPage::windowShown( const ::com::sun::star::lang::EventObject
& e
)
308 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
313 void SAL_CALL
UnoControlTabPage::windowHidden( const ::com::sun::star::lang::EventObject
& e
)
314 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
319 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
320 stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
321 css::uno::XComponentContext
*context
,
322 css::uno::Sequence
<css::uno::Any
> const &)
324 return cppu::acquire(new UnoControlTabPageModel(context
));
327 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
328 stardiv_Toolkit_UnoControlTabPage_get_implementation(
329 css::uno::XComponentContext
*context
,
330 css::uno::Sequence
<css::uno::Any
> const &)
332 return cppu::acquire(new UnoControlTabPage(context
));
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */