fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / toolkit / source / controls / tabpagemodel.cxx
blobf06f7e76699d69240ca839d6282795fd0deab1e2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <vcl/svapp.hxx>
22 #include <vcl/window.hxx>
23 #include <vcl/wall.hxx>
24 #include <toolkit/controls/tabpagemodel.hxx>
25 #include <toolkit/helper/property.hxx>
26 #include <toolkit/helper/unopropertyarrayhelper.hxx>
27 #include <toolkit/controls/stdtabcontroller.hxx>
28 #include <com/sun/star/awt/PosSize.hpp>
29 #include <com/sun/star/awt/WindowAttribute.hpp>
30 #include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
31 #include <com/sun/star/resource/XStringResourceResolver.hpp>
32 #include <com/sun/star/graphic/XGraphicProvider.hpp>
33 #include <cppuhelper/typeprovider.hxx>
34 #include <tools/debug.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <comphelper/sequence.hxx>
37 #include <vcl/outdev.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <unotools/ucbstreamhelper.hxx>
41 #include <vcl/graph.hxx>
42 #include <vcl/image.hxx>
43 #include <toolkit/controls/geometrycontrolmodel.hxx>
45 #include <map>
46 #include <algorithm>
47 #include <functional>
48 #include "osl/file.hxx"
50 #include <com/sun/star/beans/XPropertySet.hpp>
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::awt;
55 using namespace ::com::sun::star::lang;
56 using namespace ::com::sun::star::container;
57 using namespace ::com::sun::star::beans;
58 using namespace ::com::sun::star::util;
60 ////HELPER
61 OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl );
63 // ----------------------------------------------------
64 // class UnoControlTabPageModel
65 // ----------------------------------------------------
66 UnoControlTabPageModel::UnoControlTabPageModel( Reference< XComponentContext > const & i_factory )
67 :ControlModelContainerBase( i_factory )
69 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
70 ImplRegisterProperty( BASEPROPERTY_TITLE );
71 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
72 ImplRegisterProperty( BASEPROPERTY_HELPURL );
73 ImplRegisterProperty( BASEPROPERTY_IMAGEURL );
74 ImplRegisterProperty( BASEPROPERTY_ENABLED );
77 OUString UnoControlTabPageModel::getServiceName( ) throw(RuntimeException)
79 return OUString::createFromAscii( szServiceName_UnoControlTabPageModel );
82 Any UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
84 Any aAny;
86 switch ( nPropId )
88 case BASEPROPERTY_DEFAULTCONTROL:
89 aAny <<= OUString::createFromAscii( szServiceName_UnoControlTabPage );
90 break;
91 default:
92 aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
95 return aAny;
98 ::cppu::IPropertyArrayHelper& UnoControlTabPageModel::getInfoHelper()
100 static UnoPropertyArrayHelper* pHelper = NULL;
101 if ( !pHelper )
103 Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
104 pHelper = new UnoPropertyArrayHelper( aIDs );
106 return *pHelper;
108 // beans::XMultiPropertySet
109 uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo( ) throw(uno::RuntimeException)
111 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
112 return xInfo;
114 ////----- XInitialization -------------------------------------------------------------------
115 void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments)
116 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
118 sal_Int16 nPageId = -1;
119 if ( rArguments.getLength() == 1 )
121 if ( !( rArguments[ 0 ] >>= nPageId ))
122 throw lang::IllegalArgumentException();
123 m_nTabPageId = nPageId;
125 else if ( rArguments.getLength() == 2 )
127 if ( !( rArguments[ 0 ] >>= nPageId ))
128 throw lang::IllegalArgumentException();
129 m_nTabPageId = nPageId;
130 OUString sURL;
131 if ( !( rArguments[ 1 ] >>= sURL ))
132 throw lang::IllegalArgumentException();
133 Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( m_xContext, sURL );
134 if ( xDialogModel.is() )
136 Sequence< OUString> aNames = xDialogModel->getElementNames();
137 const OUString* pIter = aNames.getConstArray();
138 const OUString* pEnd = pIter + aNames.getLength();
139 for(;pIter != pEnd;++pIter)
143 Any aElement(xDialogModel->getByName(*pIter));
144 xDialogModel->removeByName(*pIter);
145 insertByName(*pIter,aElement);
147 catch(const Exception& ex)
149 (void)ex;
152 Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY);
153 if ( xDialogProp.is() )
155 static const OUString s_sResourceResolver("ResourceResolver");
156 Reference<XPropertySet> xThis(*this,UNO_QUERY);
157 xThis->setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
158 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
159 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL)));
160 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
161 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED)));
162 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
166 else
167 m_nTabPageId = -1;
169 //===== Service ===============================================================
170 OUString UnoControlTabPageModel_getImplementationName (void) throw(RuntimeException)
172 return OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
175 Sequence<OUString> SAL_CALL UnoControlTabPageModel_getSupportedServiceNames (void)
176 throw (RuntimeException)
178 const OUString sServiceName("com.sun.star.awt.tab.UnoControlTabPageModel");
179 return Sequence<OUString>(&sServiceName, 1);
181 //=============================================================================
182 // = class UnoControlTabPage
183 // ============================================================================
185 UnoControlTabPage::UnoControlTabPage( const uno::Reference< uno::XComponentContext >& rxContext )
186 :UnoControlTabPage_Base(rxContext)
187 ,m_bWindowListener(false)
189 maComponentInfos.nWidth = 280;
190 maComponentInfos.nHeight = 400;
192 UnoControlTabPage::~UnoControlTabPage()
196 OUString UnoControlTabPage::GetComponentServiceName()
198 return OUString("TabPageModel");
201 void UnoControlTabPage::dispose() throw(RuntimeException)
203 SolarMutexGuard aSolarGuard;
205 EventObject aEvt;
206 aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
207 ControlContainerBase::dispose();
210 void SAL_CALL UnoControlTabPage::disposing( const EventObject& Source )throw(RuntimeException)
212 ControlContainerBase::disposing( Source );
215 void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
217 SolarMutexGuard aSolarGuard;
218 ImplUpdateResourceResolver();
220 UnoControlContainer::createPeer( rxToolkit, rParentPeer );
222 Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY );
223 if ( xTabPage.is() )
225 if ( !m_bWindowListener )
227 Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY );
228 addWindowListener( xWL );
229 m_bWindowListener = true;
234 static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize )
236 ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT );
237 return aTmp;
239 // ::com::sun::star::awt::XWindowListener
240 void SAL_CALL UnoControlTabPage::windowResized( const ::com::sun::star::awt::WindowEvent& e )
241 throw (::com::sun::star::uno::RuntimeException)
243 OutputDevice*pOutDev = Application::GetDefaultDevice();
244 DBG_ASSERT( pOutDev, "Missing Default Device!" );
245 if ( pOutDev && !mbSizeModified )
247 // Currentley we are simply using MAP_APPFONT
248 ::Size aAppFontSize( e.Width, e.Height );
250 Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
251 Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
252 OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
253 if ( xDialogDevice.is() )
255 DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
256 aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
257 aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
260 aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
262 // Remember that changes have been done by listener. No need to
263 // update the position because of property change event.
264 mbSizeModified = true;
265 Sequence< OUString > aProps( 2 );
266 Sequence< Any > aValues( 2 );
267 // Properties in a sequence must be sorted!
268 aProps[0] = OUString( "Height" );
269 aProps[1] = OUString( "Width" );
270 aValues[0] <<= aAppFontSize.Height();
271 aValues[1] <<= aAppFontSize.Width();
273 ImplSetPropertyValues( aProps, aValues, true );
274 mbSizeModified = false;
278 void SAL_CALL UnoControlTabPage::windowMoved( const ::com::sun::star::awt::WindowEvent& e )
279 throw (::com::sun::star::uno::RuntimeException)
281 OutputDevice*pOutDev = Application::GetDefaultDevice();
282 DBG_ASSERT( pOutDev, "Missing Default Device!" );
283 if ( pOutDev && !mbPosModified )
285 // Currentley we are simply using MAP_APPFONT
286 Any aAny;
287 ::Size aTmp( e.X, e.Y );
288 aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
290 // Remember that changes have been done by listener. No need to
291 // update the position because of property change event.
292 mbPosModified = true;
293 Sequence< OUString > aProps( 2 );
294 Sequence< Any > aValues( 2 );
295 aProps[0] = OUString( "PositionX" );
296 aProps[1] = OUString( "PositionY" );
297 aValues[0] <<= aTmp.Width();
298 aValues[1] <<= aTmp.Height();
300 ImplSetPropertyValues( aProps, aValues, true );
301 mbPosModified = false;
305 void SAL_CALL UnoControlTabPage::windowShown( const ::com::sun::star::lang::EventObject& e )
306 throw (::com::sun::star::uno::RuntimeException)
308 (void)e;
311 void SAL_CALL UnoControlTabPage::windowHidden( const ::com::sun::star::lang::EventObject& e )
312 throw (::com::sun::star::uno::RuntimeException)
314 (void)e;
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */