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>
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();
90 sal_uInt16 nChildren
= pWindow
->GetChildCount();
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
);
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();
116 WinBits nStyle
= pWindow
->GetStyle();
118 nStyle
|= WB_DIALOGCONTROL
;
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!
142 // Order windows before manipulating their style, because elements such as the
143 // RadioButton considers the PREV-window in StateChanged.
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;
153 nStyle
|= ( bTab
? WB_TABSTOP
: WB_NOTABSTOP
);
155 pWin
->SetStyle( nStyle
);
160 pWin
->SetDialogControlStart( sal_True
);
162 pWin
->SetDialogControlStart( sal_False
);
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
] );
184 Window
* pSortBehind
= pPrevWin
;
185 // #57096# Sort all radios consecutively
186 sal_Bool bNewPrevWin
= sal_True
;
187 if ( pWin
->GetType() == WINDOW_RADIOBUTTON
)
191 // This RadioButton was sorted before PrevWin
192 bNewPrevWin
= ( pPrevWin
== pPrevRadio
);
193 pSortBehind
= pPrevRadio
;
200 pWin
->SetZOrder( pSortBehind
, WINDOW_ZORDER_BEHIND
);
202 WinBits nStyle
= pWin
->GetStyle();
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
);
215 WinBits nLastStyle
= pBehindLast
->GetStyle();
216 nLastStyle
|= WB_GROUP
;
217 pBehindLast
->SetStyle( nLastStyle
);
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
);
237 case BASEPROPERTY_SCROLLHEIGHT
:
238 case BASEPROPERTY_SCROLLWIDTH
:
239 case BASEPROPERTY_SCROLLTOP
:
240 case BASEPROPERTY_SCROLLLEFT
:
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() );
252 pDev
= pWindow
->GetParent();
253 // shouldn't happen but it appears pDev can be NULL
254 // #FIXME ( find out how/why )
258 aSize
= pDev
->LogicToPixel( aSize
, aMode
);
261 case BASEPROPERTY_SCROLLHEIGHT
:
262 pScrollable
->SetScrollHeight( aSize
.Height() );
264 case BASEPROPERTY_SCROLLWIDTH
:
265 pScrollable
->SetScrollWidth( aSize
.Width() );
267 case BASEPROPERTY_SCROLLTOP
:
268 pScrollable
->SetScrollTop( aSize
.Height() );
270 case BASEPROPERTY_SCROLLLEFT
:
271 pScrollable
->SetScrollLeft( aSize
.Width() );
283 VCLXWindow::setProperty( PropertyName
, Value
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */