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>
25 #include <comphelper/interfacecontainer2.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/window.hxx>
30 #include <tools/debug.hxx>
31 #include <helper/scrollabledialog.hxx>
32 #include <toolkit/helper/property.hxx>
35 // class VCLXContainer
38 void VCLXContainer::ImplGetPropertyIds( std::vector
< sal_uInt16
> &rIds
)
40 VCLXWindow::ImplGetPropertyIds( rIds
);
43 VCLXContainer::VCLXContainer()
47 VCLXContainer::~VCLXContainer()
51 // css::uno::XInterface
52 css::uno::Any
VCLXContainer::queryInterface( const css::uno::Type
& rType
)
54 css::uno::Any aRet
= ::cppu::queryInterface( rType
,
55 static_cast< css::awt::XVclContainer
* >(this),
56 static_cast< css::awt::XVclContainerPeer
* >(this) );
57 return (aRet
.hasValue() ? aRet
: VCLXWindow::queryInterface( rType
));
60 IMPL_IMPLEMENTATION_ID( VCLXContainer
)
62 // css::lang::XTypeProvider
63 css::uno::Sequence
< css::uno::Type
> VCLXContainer::getTypes()
65 static const ::cppu::OTypeCollection
aTypeList(
66 cppu::UnoType
<css::lang::XTypeProvider
>::get(),
67 cppu::UnoType
<css::awt::XVclContainer
>::get(),
68 cppu::UnoType
<css::awt::XVclContainerPeer
>::get(),
69 VCLXWindow::getTypes()
71 return aTypeList
.getTypes();
75 // css::awt::XVclContainer
76 void VCLXContainer::addVclContainerListener( const css::uno::Reference
< css::awt::XVclContainerListener
>& rxListener
)
78 SolarMutexGuard aGuard
;
80 GetContainerListeners().addInterface( rxListener
);
83 void VCLXContainer::removeVclContainerListener( const css::uno::Reference
< css::awt::XVclContainerListener
>& rxListener
)
85 SolarMutexGuard aGuard
;
87 GetContainerListeners().removeInterface( rxListener
);
90 css::uno::Sequence
< css::uno::Reference
< css::awt::XWindow
> > VCLXContainer::getWindows( )
92 SolarMutexGuard aGuard
;
94 // Request container interface from all children
95 css::uno::Sequence
< css::uno::Reference
< css::awt::XWindow
> > aSeq
;
96 VclPtr
<vcl::Window
> pWindow
= GetWindow();
99 sal_uInt16 nChildren
= pWindow
->GetChildCount();
102 aSeq
= css::uno::Sequence
< css::uno::Reference
< css::awt::XWindow
> >( nChildren
);
103 css::uno::Reference
< css::awt::XWindow
> * pChildRefs
= aSeq
.getArray();
104 for ( sal_uInt16 n
= 0; n
< nChildren
; n
++ )
106 vcl::Window
* pChild
= pWindow
->GetChild( n
);
107 css::uno::Reference
< css::awt::XWindowPeer
> xWP
= pChild
->GetComponentInterface();
108 css::uno::Reference
< css::awt::XWindow
> xW( xWP
, css::uno::UNO_QUERY
);
117 // css::awt::XVclContainerPeer
118 void VCLXContainer::enableDialogControl( sal_Bool bEnable
)
120 SolarMutexGuard aGuard
;
122 VclPtr
<vcl::Window
> pWindow
= GetWindow();
125 WinBits nStyle
= pWindow
->GetStyle();
127 nStyle
|= WB_DIALOGCONTROL
;
129 nStyle
&= (~WB_DIALOGCONTROL
);
130 pWindow
->SetStyle( nStyle
);
134 void VCLXContainer::setTabOrder( const css::uno::Sequence
< css::uno::Reference
< css::awt::XWindow
> >& Components
, const css::uno::Sequence
< css::uno::Any
>& Tabs
, sal_Bool bGroupControl
)
136 SolarMutexGuard aGuard
;
138 sal_uInt32 nCount
= Components
.getLength();
139 DBG_ASSERT( nCount
== static_cast<sal_uInt32
>(Tabs
.getLength()), "setTabOrder: TabCount != ComponentCount" );
140 const css::uno::Reference
< css::awt::XWindow
> * pComps
= Components
.getConstArray();
141 const css::uno::Any
* pTabs
= Tabs
.getConstArray();
143 vcl::Window
* pPrevWin
= nullptr;
144 for ( sal_uInt32 n
= 0; n
< nCount
; n
++ )
146 // css::style::TabStop
147 VclPtr
<vcl::Window
> pWin
= VCLUnoHelper::GetWindow( pComps
[n
] );
148 // May be NULL if a css::uno::Sequence is originated from TabController and is missing a peer!
151 // Order windows before manipulating their style, because elements such as the
152 // RadioButton considers the PREV-window in StateChanged.
154 pWin
->SetZOrder( pPrevWin
, ZOrderFlags::Behind
);
156 WinBits nStyle
= pWin
->GetStyle();
157 nStyle
&= ~(WB_TABSTOP
|WB_NOTABSTOP
|WB_GROUP
);
158 if ( pTabs
[n
].getValueType().getTypeClass() == css::uno::TypeClass_BOOLEAN
)
162 nStyle
|= ( bTab
? WB_TABSTOP
: WB_NOTABSTOP
);
164 pWin
->SetStyle( nStyle
);
169 pWin
->SetDialogControlStart( true );
171 pWin
->SetDialogControlStart( false );
179 void VCLXContainer::setGroup( const css::uno::Sequence
< css::uno::Reference
< css::awt::XWindow
> >& Components
)
181 SolarMutexGuard aGuard
;
183 sal_uInt32 nCount
= Components
.getLength();
184 const css::uno::Reference
< css::awt::XWindow
> * pComps
= Components
.getConstArray();
186 vcl::Window
* pPrevWin
= nullptr;
187 vcl::Window
* pPrevRadio
= nullptr;
188 for ( sal_uInt32 n
= 0; n
< nCount
; n
++ )
190 VclPtr
<vcl::Window
> pWin
= VCLUnoHelper::GetWindow( pComps
[n
] );
193 vcl::Window
* pSortBehind
= pPrevWin
;
194 // #57096# Sort all radios consecutively
195 bool bNewPrevWin
= true;
196 if ( pWin
->GetType() == WindowType::RADIOBUTTON
)
200 // This RadioButton was sorted before PrevWin
201 bNewPrevWin
= ( pPrevWin
== pPrevRadio
);
202 pSortBehind
= pPrevRadio
;
209 pWin
->SetZOrder( pSortBehind
, ZOrderFlags::Behind
);
211 WinBits nStyle
= pWin
->GetStyle();
215 nStyle
&= (~WB_GROUP
);
216 pWin
->SetStyle( nStyle
);
218 // Add WB_GROUP after the last group
219 if ( n
== ( nCount
- 1 ) )
221 vcl::Window
* pBehindLast
= pWin
->GetWindow( GetWindowType::Next
);
224 WinBits nLastStyle
= pBehindLast
->GetStyle();
225 nLastStyle
|= WB_GROUP
;
226 pBehindLast
->SetStyle( nLastStyle
);
236 void SAL_CALL
VCLXContainer::setProperty(
237 const OUString
& PropertyName
,
238 const css::uno::Any
& Value
)
240 SolarMutexGuard aGuard
;
242 sal_uInt16 nPropType
= GetPropertyId( PropertyName
);
245 case BASEPROPERTY_SCROLLHEIGHT
:
246 case BASEPROPERTY_SCROLLWIDTH
:
247 case BASEPROPERTY_SCROLLTOP
:
248 case BASEPROPERTY_SCROLLLEFT
:
252 Size
aSize( nVal
, nVal
);
253 VclPtr
<vcl::Window
> pWindow
= GetWindow();
254 MapMode
aMode( MapUnit::MapAppFont
);
255 toolkit::ScrollableDialog
* pScrollable
= dynamic_cast< toolkit::ScrollableDialog
* >( pWindow
.get() );
256 if ( pWindow
&& pScrollable
)
258 OutputDevice
* pDev
= VCLUnoHelper::GetOutputDevice( getGraphics() );
260 pDev
= pWindow
->GetParent();
261 // shouldn't happen but it appears pDev can be NULL
262 // #FIXME ( find out how/why )
266 aSize
= pDev
->LogicToPixel( aSize
, aMode
);
269 case BASEPROPERTY_SCROLLHEIGHT
:
270 pScrollable
->SetScrollHeight( aSize
.Height() );
272 case BASEPROPERTY_SCROLLWIDTH
:
273 pScrollable
->SetScrollWidth( aSize
.Width() );
275 case BASEPROPERTY_SCROLLTOP
:
276 pScrollable
->SetScrollTop( aSize
.Height() );
278 case BASEPROPERTY_SCROLLLEFT
:
279 pScrollable
->SetScrollLeft( aSize
.Width() );
291 VCLXWindow::setProperty( PropertyName
, Value
);
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */