Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
25 :
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>
31 :
32 :
33 : // class VCLXContainer
34 :
35 :
36 0 : void VCLXContainer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
37 : {
38 0 : VCLXWindow::ImplGetPropertyIds( rIds );
39 0 : }
40 :
41 26214 : VCLXContainer::VCLXContainer()
42 : {
43 26214 : }
44 :
45 35258 : VCLXContainer::~VCLXContainer()
46 : {
47 35258 : }
48 :
49 : // ::com::sun::star::uno::XInterface
50 1038786 : ::com::sun::star::uno::Any VCLXContainer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception)
51 : {
52 : ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
53 : (static_cast< ::com::sun::star::awt::XVclContainer* >(this)),
54 1038786 : (static_cast< ::com::sun::star::awt::XVclContainerPeer* >(this)) );
55 1038786 : return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
56 : }
57 :
58 : // ::com::sun::star::lang::XTypeProvider
59 0 : IMPL_XTYPEPROVIDER_START( VCLXContainer )
60 0 : cppu::UnoType<com::sun::star::awt::XVclContainer>::get(),
61 0 : cppu::UnoType<com::sun::star::awt::XVclContainerPeer>::get(),
62 : VCLXWindow::getTypes()
63 0 : IMPL_XTYPEPROVIDER_END
64 :
65 :
66 : // ::com::sun::star::awt::XVclContainer
67 0 : void VCLXContainer::addVclContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException, std::exception)
68 : {
69 0 : SolarMutexGuard aGuard;
70 :
71 0 : GetContainerListeners().addInterface( rxListener );
72 0 : }
73 :
74 0 : void VCLXContainer::removeVclContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException, std::exception)
75 : {
76 0 : SolarMutexGuard aGuard;
77 :
78 0 : GetContainerListeners().removeInterface( rxListener );
79 0 : }
80 :
81 0 : ::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)
82 : {
83 0 : SolarMutexGuard aGuard;
84 :
85 : // Request container interface from all children
86 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > > aSeq;
87 0 : vcl::Window* pWindow = GetWindow();
88 0 : if ( pWindow )
89 : {
90 0 : sal_uInt16 nChildren = pWindow->GetChildCount();
91 0 : if ( nChildren )
92 : {
93 0 : aSeq = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > >( nChildren );
94 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pChildRefs = aSeq.getArray();
95 0 : for ( sal_uInt16 n = 0; n < nChildren; n++ )
96 : {
97 0 : vcl::Window* pChild = pWindow->GetChild( n );
98 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xWP = pChild->GetComponentInterface( true );
99 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xW( xWP, ::com::sun::star::uno::UNO_QUERY );
100 0 : pChildRefs[n] = xW;
101 0 : }
102 : }
103 : }
104 0 : return aSeq;
105 : }
106 :
107 :
108 : // ::com::sun::star::awt::XVclContainerPeer
109 8 : void VCLXContainer::enableDialogControl( sal_Bool bEnable ) throw(::com::sun::star::uno::RuntimeException, std::exception)
110 : {
111 8 : SolarMutexGuard aGuard;
112 :
113 8 : vcl::Window* pWindow = GetWindow();
114 8 : if ( pWindow )
115 : {
116 8 : WinBits nStyle = pWindow->GetStyle();
117 8 : if ( bEnable )
118 8 : nStyle |= WB_DIALOGCONTROL;
119 : else
120 0 : nStyle &= (~WB_DIALOGCONTROL);
121 8 : pWindow->SetStyle( nStyle );
122 8 : }
123 8 : }
124 :
125 234 : 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)
126 : {
127 234 : SolarMutexGuard aGuard;
128 :
129 234 : sal_uInt32 nCount = Components.getLength();
130 : DBG_ASSERT( nCount == (sal_uInt32)Tabs.getLength(), "setTabOrder: TabCount != ComponentCount" );
131 234 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pComps = Components.getConstArray();
132 234 : const ::com::sun::star::uno::Any* pTabs = Tabs.getConstArray();
133 :
134 234 : vcl::Window* pPrevWin = NULL;
135 368 : for ( sal_uInt32 n = 0; n < nCount; n++ )
136 : {
137 : // ::com::sun::star::style::TabStop
138 134 : vcl::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 134 : if ( pWin )
141 : {
142 : // Order windows before manipulating their style, because elements such as the
143 : // RadioButton considers the PREV-window in StateChanged.
144 134 : if ( pPrevWin )
145 48 : pWin->SetZOrder( pPrevWin, WINDOW_ZORDER_BEHIND );
146 :
147 134 : WinBits nStyle = pWin->GetStyle();
148 134 : nStyle &= ~(WB_TABSTOP|WB_NOTABSTOP|WB_GROUP);
149 134 : if ( pTabs[n].getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN )
150 : {
151 12 : bool bTab = false;
152 12 : pTabs[n] >>= bTab;
153 12 : nStyle |= ( bTab ? WB_TABSTOP : WB_NOTABSTOP );
154 : }
155 134 : pWin->SetStyle( nStyle );
156 :
157 134 : if ( bGroupControl )
158 : {
159 16 : if ( n == 0 )
160 8 : pWin->SetDialogControlStart( true );
161 : else
162 8 : pWin->SetDialogControlStart( false );
163 : }
164 :
165 134 : pPrevWin = pWin;
166 : }
167 234 : }
168 234 : }
169 :
170 24 : 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)
171 : {
172 24 : SolarMutexGuard aGuard;
173 :
174 24 : sal_uInt32 nCount = Components.getLength();
175 24 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pComps = Components.getConstArray();
176 :
177 24 : vcl::Window* pPrevWin = NULL;
178 24 : vcl::Window* pPrevRadio = NULL;
179 48 : for ( sal_uInt32 n = 0; n < nCount; n++ )
180 : {
181 24 : vcl::Window* pWin = VCLUnoHelper::GetWindow( pComps[n] );
182 24 : if ( pWin )
183 : {
184 24 : vcl::Window* pSortBehind = pPrevWin;
185 : // #57096# Sort all radios consecutively
186 24 : bool bNewPrevWin = true;
187 24 : if ( pWin->GetType() == WINDOW_RADIOBUTTON )
188 : {
189 8 : if ( pPrevRadio )
190 : {
191 : // This RadioButton was sorted before PrevWin
192 0 : bNewPrevWin = ( pPrevWin == pPrevRadio );
193 0 : pSortBehind = pPrevRadio;
194 : }
195 8 : pPrevRadio = pWin;
196 : }
197 :
198 : // Z-Order
199 24 : if ( pSortBehind )
200 12 : pWin->SetZOrder( pSortBehind, WINDOW_ZORDER_BEHIND );
201 :
202 24 : WinBits nStyle = pWin->GetStyle();
203 24 : if ( n == 0 )
204 12 : nStyle |= WB_GROUP;
205 : else
206 12 : nStyle &= (~WB_GROUP);
207 24 : pWin->SetStyle( nStyle );
208 :
209 : // Add WB_GROUP after the last group
210 24 : if ( n == ( nCount - 1 ) )
211 : {
212 12 : vcl::Window* pBehindLast = pWin->GetWindow( WINDOW_NEXT );
213 12 : if ( pBehindLast )
214 : {
215 6 : WinBits nLastStyle = pBehindLast->GetStyle();
216 6 : nLastStyle |= WB_GROUP;
217 6 : pBehindLast->SetStyle( nLastStyle );
218 : }
219 : }
220 :
221 24 : if ( bNewPrevWin )
222 24 : pPrevWin = pWin;
223 : }
224 24 : }
225 24 : }
226 :
227 416 : void SAL_CALL VCLXContainer::setProperty(
228 : const OUString& PropertyName,
229 : const ::com::sun::star::uno::Any& Value )
230 : throw(::com::sun::star::uno::RuntimeException, std::exception)
231 : {
232 416 : SolarMutexGuard aGuard;
233 :
234 416 : sal_uInt16 nPropType = GetPropertyId( PropertyName );
235 416 : switch ( nPropType )
236 : {
237 : case BASEPROPERTY_SCROLLHEIGHT:
238 : case BASEPROPERTY_SCROLLWIDTH:
239 : case BASEPROPERTY_SCROLLTOP:
240 : case BASEPROPERTY_SCROLLLEFT:
241 : {
242 48 : sal_Int32 nVal =0;
243 48 : Value >>= nVal;
244 48 : Size aSize( nVal, nVal );
245 48 : vcl::Window* pWindow = GetWindow();
246 48 : MapMode aMode( MAP_APPFONT );
247 48 : toolkit::ScrollableInterface* pScrollable = dynamic_cast< toolkit::ScrollableInterface* >( pWindow );
248 48 : if ( pWindow && pScrollable )
249 : {
250 48 : OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
251 48 : if ( !pDev )
252 48 : pDev = pWindow->GetParent();
253 : // shouldn't happen but it appears pDev can be NULL
254 : // #FIXME ( find out how/why )
255 48 : if ( !pDev )
256 24 : break;
257 :
258 24 : aSize = pDev->LogicToPixel( aSize, aMode );
259 24 : switch ( nPropType )
260 : {
261 : case BASEPROPERTY_SCROLLHEIGHT:
262 4 : pScrollable->SetScrollHeight( aSize.Height() );
263 4 : break;
264 : case BASEPROPERTY_SCROLLWIDTH:
265 4 : pScrollable->SetScrollWidth( aSize.Width() );
266 4 : break;
267 : case BASEPROPERTY_SCROLLTOP:
268 8 : pScrollable->SetScrollTop( aSize.Height() );
269 8 : break;
270 : case BASEPROPERTY_SCROLLLEFT:
271 8 : pScrollable->SetScrollLeft( aSize.Width() );
272 8 : break;
273 : default:
274 0 : break;
275 : }
276 24 : break;
277 : }
278 0 : break;
279 : }
280 :
281 : default:
282 : {
283 368 : VCLXWindow::setProperty( PropertyName, Value );
284 : }
285 416 : }
286 1643 : }
287 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|