Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / toolkit / source / awt / vclxcontainer.cxx
blobde7518d418c9e0765f45e06dea061bc37d2924c3
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 <awt/vclxcontainer.hxx>
21 #include <toolkit/helper/vclunohelper.hxx>
22 #include <toolkit/helper/listenermultiplexer.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/tabpage.hxx>
27 #include <tools/debug.hxx>
28 #include <helper/scrollabledialog.hxx>
29 #include <helper/property.hxx>
31 void VCLXContainer::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
33 VCLXWindow::ImplGetPropertyIds( rIds );
36 VCLXContainer::VCLXContainer()
40 VCLXContainer::~VCLXContainer()
45 // css::awt::XVclContainer
46 void VCLXContainer::addVclContainerListener( const css::uno::Reference< css::awt::XVclContainerListener >& rxListener )
48 SolarMutexGuard aGuard;
50 if (!IsDisposed())
51 GetContainerListeners().addInterface( rxListener );
54 void VCLXContainer::removeVclContainerListener( const css::uno::Reference< css::awt::XVclContainerListener >& rxListener )
56 SolarMutexGuard aGuard;
58 if (!IsDisposed())
59 GetContainerListeners().removeInterface( rxListener );
62 css::uno::Sequence< css::uno::Reference< css::awt::XWindow > > VCLXContainer::getWindows( )
64 SolarMutexGuard aGuard;
66 // Request container interface from all children
67 css::uno::Sequence< css::uno::Reference< css::awt::XWindow > > aSeq;
68 VclPtr<vcl::Window> pWindow = GetWindow();
69 if ( pWindow )
71 sal_uInt16 nChildren = pWindow->GetChildCount();
72 if ( nChildren )
74 aSeq = css::uno::Sequence< css::uno::Reference< css::awt::XWindow > >( nChildren );
75 css::uno::Reference< css::awt::XWindow > * pChildRefs = aSeq.getArray();
76 for ( sal_uInt16 n = 0; n < nChildren; n++ )
78 vcl::Window* pChild = pWindow->GetChild( n );
79 css::uno::Reference< css::awt::XWindowPeer > xWP = pChild->GetComponentInterface();
80 css::uno::Reference< css::awt::XWindow > xW( xWP, css::uno::UNO_QUERY );
81 pChildRefs[n] = xW;
85 return aSeq;
89 // css::awt::XVclContainerPeer
90 void VCLXContainer::enableDialogControl( sal_Bool bEnable )
92 SolarMutexGuard aGuard;
94 VclPtr<vcl::Window> pWindow = GetWindow();
95 if ( pWindow )
97 WinBits nStyle = pWindow->GetStyle();
98 if ( bEnable )
99 nStyle |= WB_DIALOGCONTROL;
100 else
101 nStyle &= (~WB_DIALOGCONTROL);
102 pWindow->SetStyle( nStyle );
106 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 )
108 SolarMutexGuard aGuard;
110 sal_uInt32 nCount = Components.getLength();
111 DBG_ASSERT( nCount == static_cast<sal_uInt32>(Tabs.getLength()), "setTabOrder: TabCount != ComponentCount" );
112 const css::uno::Reference< css::awt::XWindow > * pComps = Components.getConstArray();
113 const css::uno::Any* pTabs = Tabs.getConstArray();
115 vcl::Window* pPrevWin = nullptr;
116 for ( sal_uInt32 n = 0; n < nCount; n++ )
118 // css::style::TabStop
119 VclPtr<vcl::Window> pWin = VCLUnoHelper::GetWindow( pComps[n] );
120 // May be NULL if a css::uno::Sequence is originated from TabController and is missing a peer!
121 if ( pWin )
123 // Order windows before manipulating their style, because elements such as the
124 // RadioButton considers the PREV-window in StateChanged.
125 if ( pPrevWin )
126 pWin->SetZOrder( pPrevWin, ZOrderFlags::Behind );
128 WinBits nStyle = pWin->GetStyle();
129 nStyle &= ~(WB_TABSTOP|WB_NOTABSTOP|WB_GROUP);
130 if ( pTabs[n].getValueType().getTypeClass() == css::uno::TypeClass_BOOLEAN )
132 bool bTab = false;
133 pTabs[n] >>= bTab;
134 nStyle |= ( bTab ? WB_TABSTOP : WB_NOTABSTOP );
136 pWin->SetStyle( nStyle );
138 if ( bGroupControl )
140 if ( n == 0 )
141 pWin->SetDialogControlStart( true );
142 else
143 pWin->SetDialogControlStart( false );
146 pPrevWin = pWin;
151 void VCLXContainer::setGroup( const css::uno::Sequence< css::uno::Reference< css::awt::XWindow > >& Components )
153 SolarMutexGuard aGuard;
155 sal_uInt32 nCount = Components.getLength();
156 const css::uno::Reference< css::awt::XWindow > * pComps = Components.getConstArray();
158 vcl::Window* pPrevWin = nullptr;
159 vcl::Window* pPrevRadio = nullptr;
160 for ( sal_uInt32 n = 0; n < nCount; n++ )
162 VclPtr<vcl::Window> pWin = VCLUnoHelper::GetWindow( pComps[n] );
163 if ( pWin )
165 vcl::Window* pSortBehind = pPrevWin;
166 // #57096# Sort all radios consecutively
167 bool bNewPrevWin = true;
168 if ( pWin->GetType() == WindowType::RADIOBUTTON )
170 if ( pPrevRadio )
172 // This RadioButton was sorted before PrevWin
173 bNewPrevWin = ( pPrevWin == pPrevRadio );
174 pSortBehind = pPrevRadio;
176 pPrevRadio = pWin;
179 // Z-Order
180 if ( pSortBehind )
181 pWin->SetZOrder( pSortBehind, ZOrderFlags::Behind );
183 WinBits nStyle = pWin->GetStyle();
184 if ( n == 0 )
185 nStyle |= WB_GROUP;
186 else
187 nStyle &= (~WB_GROUP);
188 pWin->SetStyle( nStyle );
190 // Add WB_GROUP after the last group
191 if ( n == ( nCount - 1 ) )
193 vcl::Window* pBehindLast = pWin->GetWindow( GetWindowType::Next );
194 if ( pBehindLast )
196 WinBits nLastStyle = pBehindLast->GetStyle();
197 nLastStyle |= WB_GROUP;
198 pBehindLast->SetStyle( nLastStyle );
202 if ( bNewPrevWin )
203 pPrevWin = pWin;
208 void SAL_CALL VCLXContainer::setProperty(
209 const OUString& PropertyName,
210 const css::uno::Any& Value )
212 SolarMutexGuard aGuard;
214 sal_uInt16 nPropType = GetPropertyId( PropertyName );
215 switch ( nPropType )
217 case BASEPROPERTY_SCROLLHEIGHT:
218 case BASEPROPERTY_SCROLLWIDTH:
219 case BASEPROPERTY_SCROLLTOP:
220 case BASEPROPERTY_SCROLLLEFT:
222 sal_Int32 nVal =0;
223 Value >>= nVal;
224 Size aSize( nVal, nVal );
225 VclPtr<vcl::Window> pWindow = GetWindow();
226 MapMode aMode( MapUnit::MapAppFont );
227 toolkit::ScrollableDialog* pScrollable = dynamic_cast< toolkit::ScrollableDialog* >( pWindow.get() );
228 TabPage* pScrollTabPage = dynamic_cast< TabPage* >( pWindow.get() );
229 if ( pWindow && (pScrollable || pScrollTabPage) )
231 aSize = pWindow->LogicToPixel( aSize, aMode );
232 switch ( nPropType )
234 case BASEPROPERTY_SCROLLHEIGHT:
235 pScrollable ? pScrollable->SetScrollHeight( aSize.Height() ) : (void)0;
236 pScrollTabPage ? pScrollTabPage->SetScrollHeight( aSize.Height() ) : (void)0;
237 break;
238 case BASEPROPERTY_SCROLLWIDTH:
239 pScrollable ? pScrollable->SetScrollWidth( aSize.Width() ) : (void)0;
240 pScrollTabPage ? pScrollTabPage->SetScrollWidth( aSize.Width() ) : (void)0;
241 break;
242 case BASEPROPERTY_SCROLLTOP:
243 pScrollable ? pScrollable->SetScrollTop( aSize.Height() ) : (void)0;
244 pScrollTabPage ? pScrollTabPage->SetScrollTop( aSize.Height() ) : (void)0;
245 break;
246 case BASEPROPERTY_SCROLLLEFT:
247 pScrollable ? pScrollable->SetScrollLeft( aSize.Width() ) : (void)0;
248 pScrollTabPage ? pScrollTabPage->SetScrollLeft( aSize.Width() ) : (void)0;
249 break;
250 default:
251 break;
253 break;
255 break;
258 default:
260 VCLXWindow::setProperty( PropertyName, Value );
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */