Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / toolkit / source / awt / vclxcontainer.cxx
blobead5d86025943050ea515e11f384311c13c29973
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 .
20 #include <toolkit/awt/vclxcontainer.hxx>
21 #include <toolkit/helper/macros.hxx>
22 #include <toolkit/helper/vclunohelper.hxx>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <rtl/uuid.h>
26 #include <vcl/svapp.hxx>
27 #include <vcl/window.hxx>
28 #include <tools/debug.hxx>
29 #include "toolkit/awt/scrollabledialog.hxx"
30 #include <toolkit/helper/property.hxx>
32 // ----------------------------------------------------
33 // class VCLXContainer
34 // ----------------------------------------------------
36 void VCLXContainer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
38 VCLXWindow::ImplGetPropertyIds( rIds );
41 VCLXContainer::VCLXContainer()
45 VCLXContainer::~VCLXContainer()
49 // ::com::sun::star::uno::XInterface
50 ::com::sun::star::uno::Any VCLXContainer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
52 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
53 (static_cast< ::com::sun::star::awt::XVclContainer* >(this)),
54 (static_cast< ::com::sun::star::awt::XVclContainerPeer* >(this)) );
55 return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
58 // ::com::sun::star::lang::XTypeProvider
59 IMPL_XTYPEPROVIDER_START( VCLXContainer )
60 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainer>* ) NULL ),
61 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerPeer>* ) NULL ),
62 VCLXWindow::getTypes()
63 IMPL_XTYPEPROVIDER_END
66 // ::com::sun::star::awt::XVclContainer
67 void VCLXContainer::addVclContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
69 SolarMutexGuard aGuard;
71 GetContainerListeners().addInterface( rxListener );
74 void VCLXContainer::removeVclContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
76 SolarMutexGuard aGuard;
78 GetContainerListeners().removeInterface( rxListener );
81 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > > VCLXContainer::getWindows( ) throw(::com::sun::star::uno::RuntimeException)
83 SolarMutexGuard aGuard;
85 // Request container interface from all children
86 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > > aSeq;
87 Window* pWindow = GetWindow();
88 if ( pWindow )
90 sal_uInt16 nChildren = pWindow->GetChildCount();
91 if ( nChildren )
93 aSeq = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > >( nChildren );
94 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pChildRefs = aSeq.getArray();
95 for ( sal_uInt16 n = 0; n < nChildren; n++ )
97 Window* pChild = pWindow->GetChild( n );
98 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xWP = pChild->GetComponentInterface( sal_True );
99 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xW( xWP, ::com::sun::star::uno::UNO_QUERY );
100 pChildRefs[n] = xW;
104 return aSeq;
108 // ::com::sun::star::awt::XVclContainerPeer
109 void VCLXContainer::enableDialogControl( sal_Bool bEnable ) throw(::com::sun::star::uno::RuntimeException)
111 SolarMutexGuard aGuard;
113 Window* pWindow = GetWindow();
114 if ( pWindow )
116 WinBits nStyle = pWindow->GetStyle();
117 if ( bEnable )
118 nStyle |= WB_DIALOGCONTROL;
119 else
120 nStyle &= (~WB_DIALOGCONTROL);
121 pWindow->SetStyle( nStyle );
125 void VCLXContainer::setTabOrder( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > >& Components, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Tabs, sal_Bool bGroupControl ) throw(::com::sun::star::uno::RuntimeException)
127 SolarMutexGuard aGuard;
129 sal_uInt32 nCount = Components.getLength();
130 DBG_ASSERT( nCount == (sal_uInt32)Tabs.getLength(), "setTabOrder: TabCount != ComponentCount" );
131 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pComps = Components.getConstArray();
132 const ::com::sun::star::uno::Any* pTabs = Tabs.getConstArray();
134 Window* pPrevWin = NULL;
135 for ( sal_uInt32 n = 0; n < nCount; n++ )
137 // ::com::sun::star::style::TabStop
138 Window* pWin = VCLUnoHelper::GetWindow( pComps[n] );
139 // May be NULL if a ::com::sun::star::uno::Sequence is originated from TabController and is missing a peer!
140 if ( pWin )
142 // Order windows before manipulating their style, because elements such as the
143 // RadioButton considers the PREV-window in StateChanged.
144 if ( pPrevWin )
145 pWin->SetZOrder( pPrevWin, WINDOW_ZORDER_BEHIND );
147 WinBits nStyle = pWin->GetStyle();
148 nStyle &= ~(WB_TABSTOP|WB_NOTABSTOP|WB_GROUP);
149 if ( pTabs[n].getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN )
151 sal_Bool bTab = false;
152 pTabs[n] >>= bTab;
153 nStyle |= ( bTab ? WB_TABSTOP : WB_NOTABSTOP );
155 pWin->SetStyle( nStyle );
157 if ( bGroupControl )
159 if ( n == 0 )
160 pWin->SetDialogControlStart( sal_True );
161 else
162 pWin->SetDialogControlStart( sal_False );
165 pPrevWin = pWin;
170 void VCLXContainer::setGroup( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > >& Components ) throw(::com::sun::star::uno::RuntimeException)
172 SolarMutexGuard aGuard;
174 sal_uInt32 nCount = Components.getLength();
175 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pComps = Components.getConstArray();
177 Window* pPrevWin = NULL;
178 Window* pPrevRadio = NULL;
179 for ( sal_uInt32 n = 0; n < nCount; n++ )
181 Window* pWin = VCLUnoHelper::GetWindow( pComps[n] );
182 if ( pWin )
184 Window* pSortBehind = pPrevWin;
185 // #57096# Sort all radios consecutively
186 sal_Bool bNewPrevWin = sal_True;
187 if ( pWin->GetType() == WINDOW_RADIOBUTTON )
189 if ( pPrevRadio )
191 // This RadioButton was sorted before PrevWin
192 bNewPrevWin = ( pPrevWin == pPrevRadio );
193 pSortBehind = pPrevRadio;
195 pPrevRadio = pWin;
198 // Z-Order
199 if ( pSortBehind )
200 pWin->SetZOrder( pSortBehind, WINDOW_ZORDER_BEHIND );
202 WinBits nStyle = pWin->GetStyle();
203 if ( n == 0 )
204 nStyle |= WB_GROUP;
205 else
206 nStyle &= (~WB_GROUP);
207 pWin->SetStyle( nStyle );
209 // Add WB_GROUP after the last group
210 if ( n == ( nCount - 1 ) )
212 Window* pBehindLast = pWin->GetWindow( WINDOW_NEXT );
213 if ( pBehindLast )
215 WinBits nLastStyle = pBehindLast->GetStyle();
216 nLastStyle |= WB_GROUP;
217 pBehindLast->SetStyle( nLastStyle );
221 if ( bNewPrevWin )
222 pPrevWin = pWin;
227 void SAL_CALL VCLXContainer::setProperty(
228 const ::rtl::OUString& PropertyName,
229 const ::com::sun::star::uno::Any& Value )
230 throw(::com::sun::star::uno::RuntimeException)
232 SolarMutexGuard aGuard;
234 sal_uInt16 nPropType = GetPropertyId( PropertyName );
235 switch ( nPropType )
237 case BASEPROPERTY_SCROLLHEIGHT:
238 case BASEPROPERTY_SCROLLWIDTH:
239 case BASEPROPERTY_SCROLLTOP:
240 case BASEPROPERTY_SCROLLLEFT:
242 sal_Int32 nVal =0;
243 Value >>= nVal;
244 Size aSize( nVal, nVal );
245 Window* pWindow = GetWindow();
246 MapMode aMode( MAP_APPFONT );
247 toolkit::ScrollableInterface* pScrollable = dynamic_cast< toolkit::ScrollableInterface* >( pWindow );
248 if ( pWindow && pScrollable )
250 OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
251 if ( !pDev )
252 pDev = pWindow->GetParent();
253 // shouldn't happen but it appears pDev can be NULL
254 // #FIXME ( find out how/why )
255 if ( !pDev )
256 break;
258 aSize = pDev->LogicToPixel( aSize, aMode );
259 switch ( nPropType )
261 case BASEPROPERTY_SCROLLHEIGHT:
262 pScrollable->SetScrollHeight( aSize.Height() );
263 break;
264 case BASEPROPERTY_SCROLLWIDTH:
265 pScrollable->SetScrollWidth( aSize.Width() );
266 break;
267 case BASEPROPERTY_SCROLLTOP:
268 pScrollable->SetScrollTop( aSize.Height() );
269 break;
270 case BASEPROPERTY_SCROLLLEFT:
271 pScrollable->SetScrollLeft( aSize.Width() );
272 break;
273 default:
274 break;
276 break;
278 break;
281 default:
283 VCLXWindow::setProperty( PropertyName, Value );
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */