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/awt/vclxcontainer.hxx>
21 #include <toolkit/helper/macros.hxx>
22 #include <toolkit/helper/vclunohelper.hxx>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <cppuhelper/queryinterface.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/window.hxx>
29 #include <tools/debug.hxx>
30 #include "toolkit/awt/scrollabledialog.hxx"
31 #include <toolkit/helper/property.hxx>
34 // class VCLXContainer
37 void VCLXContainer::ImplGetPropertyIds( std::list
< sal_uInt16
> &rIds
)
39 VCLXWindow::ImplGetPropertyIds( rIds
);
42 VCLXContainer::VCLXContainer()
46 VCLXContainer::~VCLXContainer()
50 // ::com::sun::star::uno::XInterface
51 ::com::sun::star::uno::Any
VCLXContainer::queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
53 ::com::sun::star::uno::Any aRet
= ::cppu::queryInterface( rType
,
54 (static_cast< ::com::sun::star::awt::XVclContainer
* >(this)),
55 (static_cast< ::com::sun::star::awt::XVclContainerPeer
* >(this)) );
56 return (aRet
.hasValue() ? aRet
: VCLXWindow::queryInterface( rType
));
59 // ::com::sun::star::lang::XTypeProvider
60 IMPL_XTYPEPROVIDER_START( VCLXContainer
)
61 cppu::UnoType
<com::sun::star::awt::XVclContainer
>::get(),
62 cppu::UnoType
<com::sun::star::awt::XVclContainerPeer
>::get(),
63 VCLXWindow::getTypes()
64 IMPL_XTYPEPROVIDER_END
67 // ::com::sun::star::awt::XVclContainer
68 void VCLXContainer::addVclContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XVclContainerListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
70 SolarMutexGuard aGuard
;
72 GetContainerListeners().addInterface( rxListener
);
75 void VCLXContainer::removeVclContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XVclContainerListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
77 SolarMutexGuard aGuard
;
79 GetContainerListeners().removeInterface( rxListener
);
82 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> > VCLXContainer::getWindows( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
84 SolarMutexGuard aGuard
;
86 // Request container interface from all children
87 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> > aSeq
;
88 vcl::Window
* pWindow
= GetWindow();
91 sal_uInt16 nChildren
= pWindow
->GetChildCount();
94 aSeq
= ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> >( nChildren
);
95 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> * pChildRefs
= aSeq
.getArray();
96 for ( sal_uInt16 n
= 0; n
< nChildren
; n
++ )
98 vcl::Window
* pChild
= pWindow
->GetChild( n
);
99 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xWP
= pChild
->GetComponentInterface( true );
100 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> xW( xWP
, ::com::sun::star::uno::UNO_QUERY
);
109 // ::com::sun::star::awt::XVclContainerPeer
110 void VCLXContainer::enableDialogControl( sal_Bool bEnable
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
112 SolarMutexGuard aGuard
;
114 vcl::Window
* pWindow
= GetWindow();
117 WinBits nStyle
= pWindow
->GetStyle();
119 nStyle
|= WB_DIALOGCONTROL
;
121 nStyle
&= (~WB_DIALOGCONTROL
);
122 pWindow
->SetStyle( nStyle
);
126 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
, std::exception
)
128 SolarMutexGuard aGuard
;
130 sal_uInt32 nCount
= Components
.getLength();
131 DBG_ASSERT( nCount
== (sal_uInt32
)Tabs
.getLength(), "setTabOrder: TabCount != ComponentCount" );
132 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> * pComps
= Components
.getConstArray();
133 const ::com::sun::star::uno::Any
* pTabs
= Tabs
.getConstArray();
135 vcl::Window
* pPrevWin
= NULL
;
136 for ( sal_uInt32 n
= 0; n
< nCount
; n
++ )
138 // ::com::sun::star::style::TabStop
139 vcl::Window
* pWin
= VCLUnoHelper::GetWindow( pComps
[n
] );
140 // May be NULL if a ::com::sun::star::uno::Sequence is originated from TabController and is missing a peer!
143 // Order windows before manipulating their style, because elements such as the
144 // RadioButton considers the PREV-window in StateChanged.
146 pWin
->SetZOrder( pPrevWin
, WINDOW_ZORDER_BEHIND
);
148 WinBits nStyle
= pWin
->GetStyle();
149 nStyle
&= ~(WB_TABSTOP
|WB_NOTABSTOP
|WB_GROUP
);
150 if ( pTabs
[n
].getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN
)
154 nStyle
|= ( bTab
? WB_TABSTOP
: WB_NOTABSTOP
);
156 pWin
->SetStyle( nStyle
);
161 pWin
->SetDialogControlStart( true );
163 pWin
->SetDialogControlStart( false );
171 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
, std::exception
)
173 SolarMutexGuard aGuard
;
175 sal_uInt32 nCount
= Components
.getLength();
176 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> * pComps
= Components
.getConstArray();
178 vcl::Window
* pPrevWin
= NULL
;
179 vcl::Window
* pPrevRadio
= NULL
;
180 for ( sal_uInt32 n
= 0; n
< nCount
; n
++ )
182 vcl::Window
* pWin
= VCLUnoHelper::GetWindow( pComps
[n
] );
185 vcl::Window
* pSortBehind
= pPrevWin
;
186 // #57096# Sort all radios consecutively
187 bool bNewPrevWin
= true;
188 if ( pWin
->GetType() == WINDOW_RADIOBUTTON
)
192 // This RadioButton was sorted before PrevWin
193 bNewPrevWin
= ( pPrevWin
== pPrevRadio
);
194 pSortBehind
= pPrevRadio
;
201 pWin
->SetZOrder( pSortBehind
, WINDOW_ZORDER_BEHIND
);
203 WinBits nStyle
= pWin
->GetStyle();
207 nStyle
&= (~WB_GROUP
);
208 pWin
->SetStyle( nStyle
);
210 // Add WB_GROUP after the last group
211 if ( n
== ( nCount
- 1 ) )
213 vcl::Window
* pBehindLast
= pWin
->GetWindow( GetWindowType::Next
);
216 WinBits nLastStyle
= pBehindLast
->GetStyle();
217 nLastStyle
|= WB_GROUP
;
218 pBehindLast
->SetStyle( nLastStyle
);
228 void SAL_CALL
VCLXContainer::setProperty(
229 const OUString
& PropertyName
,
230 const ::com::sun::star::uno::Any
& Value
)
231 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
233 SolarMutexGuard aGuard
;
235 sal_uInt16 nPropType
= GetPropertyId( PropertyName
);
238 case BASEPROPERTY_SCROLLHEIGHT
:
239 case BASEPROPERTY_SCROLLWIDTH
:
240 case BASEPROPERTY_SCROLLTOP
:
241 case BASEPROPERTY_SCROLLLEFT
:
245 Size
aSize( nVal
, nVal
);
246 vcl::Window
* pWindow
= GetWindow();
247 MapMode
aMode( MAP_APPFONT
);
248 toolkit::ScrollableInterface
* pScrollable
= dynamic_cast< toolkit::ScrollableInterface
* >( pWindow
);
249 if ( pWindow
&& pScrollable
)
251 OutputDevice
* pDev
= VCLUnoHelper::GetOutputDevice( getGraphics() );
253 pDev
= pWindow
->GetParent();
254 // shouldn't happen but it appears pDev can be NULL
255 // #FIXME ( find out how/why )
259 aSize
= pDev
->LogicToPixel( aSize
, aMode
);
262 case BASEPROPERTY_SCROLLHEIGHT
:
263 pScrollable
->SetScrollHeight( aSize
.Height() );
265 case BASEPROPERTY_SCROLLWIDTH
:
266 pScrollable
->SetScrollWidth( aSize
.Width() );
268 case BASEPROPERTY_SCROLLTOP
:
269 pScrollable
->SetScrollTop( aSize
.Height() );
271 case BASEPROPERTY_SCROLLLEFT
:
272 pScrollable
->SetScrollLeft( aSize
.Width() );
284 VCLXWindow::setProperty( PropertyName
, Value
);
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */