Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tabwin/tabwindow.hxx>
30 : : #include <properties.h>
31 : :
32 : : #include <threadhelp/resetableguard.hxx>
33 : :
34 : : #include <com/sun/star/util/XURLTransformer.hpp>
35 : : #include <com/sun/star/awt/PosSize.hpp>
36 : : #include <com/sun/star/awt/WindowDescriptor.hpp>
37 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
38 : : #include <com/sun/star/lang/DisposedException.hpp>
39 : :
40 : : #include <rtl/ustrbuf.hxx>
41 : : #include <vcl/svapp.hxx>
42 : : #include <vcl/window.hxx>
43 : : #include <vcl/wrkwin.hxx>
44 : : #include <toolkit/unohlp.hxx>
45 : : #include <comphelper/sequenceashashmap.hxx>
46 : :
47 : : //_________________________________________________________________________________________________________________
48 : : // Defines
49 : : //_________________________________________________________________________________________________________________
50 : :
51 : : using ::rtl::OUString;
52 : : using namespace com::sun::star;
53 : :
54 : : namespace framework
55 : : {
56 : :
57 : : //*****************************************************************************************************************
58 : : // XInterface, XTypeProvider, XServiceInfo
59 : : //*****************************************************************************************************************
60 : 0 : DEFINE_XINTERFACE_11 ( TabWindow ,
61 : : ::cppu::OWeakObject ,
62 : : DIRECT_INTERFACE( css::lang::XTypeProvider ),
63 : : DIRECT_INTERFACE( css::lang::XServiceInfo ),
64 : : DIRECT_INTERFACE( css::lang::XInitialization ),
65 : : DIRECT_INTERFACE( css::lang::XComponent ),
66 : : DIRECT_INTERFACE( css::awt::XWindowListener ),
67 : : DIRECT_INTERFACE( css::awt::XTopWindowListener ),
68 : : DIRECT_INTERFACE( css::awt::XSimpleTabController ),
69 : : DERIVED_INTERFACE( css::lang::XEventListener, css::awt::XWindowListener ),
70 : : DIRECT_INTERFACE( css::beans::XMultiPropertySet ),
71 : : DIRECT_INTERFACE( css::beans::XFastPropertySet ),
72 : : DIRECT_INTERFACE( css::beans::XPropertySet )
73 : : )
74 : :
75 : 0 : DEFINE_XTYPEPROVIDER_11 ( TabWindow ,
76 : : css::lang::XTypeProvider ,
77 : : css::lang::XServiceInfo ,
78 : : css::lang::XInitialization ,
79 : : css::lang::XComponent ,
80 : : css::awt::XWindowListener ,
81 : : css::awt::XTopWindowListener ,
82 : : css::awt::XSimpleTabController ,
83 : : css::lang::XEventListener ,
84 : : css::beans::XMultiPropertySet ,
85 : : css::beans::XFastPropertySet ,
86 : : css::beans::XPropertySet
87 : : )
88 : :
89 : 0 : PRIVATE_DEFINE_XSERVICEINFO_BASE ( TabWindow ,
90 : : ::cppu::OWeakObject ,
91 : : SERVICENAME_TABWINDOW ,
92 : : IMPLEMENTATIONNAME_TABWINDOW
93 : : )
94 : :
95 : 0 : DEFINE_INIT_SERVICE ( TabWindow, {} )
96 : :
97 : 0 : TabWindow::TabWindow( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) :
98 : 0 : ThreadHelpBase( &Application::GetSolarMutex() )
99 : 0 : , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() )
100 : : , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
101 : : , m_bInitialized( sal_False )
102 : : , m_bDisposed( sal_False )
103 : : , m_nNextTabID( 1 )
104 : : , m_aTitlePropName( RTL_CONSTASCII_USTRINGPARAM( "Title" ))
105 : : , m_aPosPropName( RTL_CONSTASCII_USTRINGPARAM( "Position" ))
106 : : , m_xServiceManager( xServiceManager )
107 : 0 : , m_aListenerContainer( m_aLock.getShareableOslMutex() )
108 : : {
109 : 0 : }
110 : :
111 : 0 : TabWindow::~TabWindow()
112 : : {
113 : 0 : }
114 : :
115 : : //---------------------------------------------------------------------------------------------------------
116 : : // Helper
117 : : //---------------------------------------------------------------------------------------------------------
118 : :
119 : 0 : void TabWindow::implts_LayoutWindows() const
120 : : {
121 : 0 : const sal_Int32 nTabControlHeight = 30;
122 : :
123 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
124 : 0 : ResetableGuard aLock( m_aLock );
125 : 0 : css::uno::Reference< css::awt::XDevice > xDevice( m_xTopWindow, css::uno::UNO_QUERY );
126 : 0 : css::uno::Reference< css::awt::XWindow > xWindow( m_xTopWindow, css::uno::UNO_QUERY );
127 : 0 : css::uno::Reference< css::awt::XWindow > xTabControlWindow( m_xTabControlWindow );
128 : 0 : css::uno::Reference< css::awt::XWindow > xContainerWindow( m_xContainerWindow );
129 : 0 : aLock.unlock();
130 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
131 : :
132 : : // Convert relativ size to output size.
133 : 0 : if ( xWindow.is() && xDevice.is() )
134 : : {
135 : 0 : css::awt::Rectangle aRectangle = xWindow->getPosSize();
136 : 0 : css::awt::DeviceInfo aInfo = xDevice->getInfo();
137 : : css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
138 : 0 : aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
139 : :
140 : 0 : css::awt::Size aContainerWindowSize;
141 : 0 : css::awt::Size aTabControlSize;
142 : :
143 : 0 : aContainerWindowSize.Width = aSize.Width;
144 : 0 : aTabControlSize.Width = aSize.Width;
145 : :
146 : 0 : aContainerWindowSize.Height = std::max( sal_Int32( 0 ), aSize.Height - nTabControlHeight );
147 : 0 : aTabControlSize.Height = nTabControlHeight;
148 : :
149 : 0 : xContainerWindow->setPosSize( 0, 0,
150 : : aContainerWindowSize.Width, aContainerWindowSize.Height,
151 : 0 : css::awt::PosSize::POSSIZE );
152 : 0 : xTabControlWindow->setPosSize( 0, std::max( nTabControlHeight, sal_Int32( aSize.Height - nTabControlHeight)),
153 : : aTabControlSize.Width, aTabControlSize.Height,
154 : 0 : css::awt::PosSize::POSSIZE );
155 : 0 : }
156 : 0 : }
157 : :
158 : 0 : TabControl* TabWindow::impl_GetTabControl( const css::uno::Reference< css::awt::XWindow >& rTabControlWindow ) const
159 : : {
160 : 0 : Window* pWindow = VCLUnoHelper::GetWindow( rTabControlWindow );
161 : 0 : if ( pWindow )
162 : 0 : return (TabControl *)pWindow;
163 : : else
164 : 0 : return NULL;
165 : : }
166 : :
167 : 0 : void TabWindow::impl_SetTitle( const ::rtl::OUString& rTitle )
168 : : {
169 : 0 : if ( m_xTopWindow.is() )
170 : : {
171 : : Window* pWindow = VCLUnoHelper::GetWindow(
172 : : css::uno::Reference< css::awt::XWindow >(
173 : 0 : m_xTopWindow, css::uno::UNO_QUERY ));
174 : 0 : if ( pWindow )
175 : 0 : pWindow->SetText( rTitle );
176 : : }
177 : 0 : }
178 : :
179 : 0 : void TabWindow::implts_SendNotification( Notification eNotify, sal_Int32 ID ) const
180 : : {
181 : : ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
182 : 0 : ::getCppuType( ( const css::uno::Reference< css::awt::XTabListener >*) NULL ) );
183 : 0 : if (pContainer!=NULL)
184 : : {
185 : 0 : ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
186 : 0 : while (pIterator.hasMoreElements())
187 : : {
188 : : try
189 : : {
190 : 0 : switch ( eNotify )
191 : : {
192 : : case NOTIFY_INSERTED:
193 : 0 : ((css::awt::XTabListener*)pIterator.next())->inserted( ID );
194 : 0 : break;
195 : : case NOTIFY_REMOVED:
196 : 0 : ((css::awt::XTabListener*)pIterator.next())->removed( ID );
197 : 0 : break;
198 : : case NOTIFY_ACTIVATED:
199 : 0 : ((css::awt::XTabListener*)pIterator.next())->activated( ID );
200 : 0 : break;
201 : : case NOTIFY_DEACTIVATED:
202 : 0 : ((css::awt::XTabListener*)pIterator.next())->deactivated( ID );
203 : 0 : break;
204 : : default:
205 : 0 : break;
206 : : }
207 : : }
208 : 0 : catch( const css::uno::RuntimeException& )
209 : : {
210 : 0 : pIterator.remove();
211 : : }
212 : 0 : }
213 : : }
214 : 0 : }
215 : :
216 : 0 : void TabWindow::implts_SendNotification( Notification eNotify, sal_Int32 ID, const css::uno::Sequence< css::beans::NamedValue >& rSeq ) const
217 : : {
218 : : ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
219 : 0 : ::getCppuType( ( const css::uno::Reference< css::awt::XTabListener >*) NULL ) );
220 : 0 : if (pContainer!=NULL)
221 : : {
222 : 0 : ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
223 : 0 : while (pIterator.hasMoreElements())
224 : : {
225 : : try
226 : : {
227 : 0 : switch ( eNotify )
228 : : {
229 : : case NOTIFY_CHANGED:
230 : 0 : ((css::awt::XTabListener*)pIterator.next())->changed( ID, rSeq );
231 : 0 : break;
232 : : default:
233 : 0 : break;
234 : : }
235 : : }
236 : 0 : catch( const css::uno::RuntimeException& )
237 : : {
238 : 0 : pIterator.remove();
239 : : }
240 : 0 : }
241 : : }
242 : 0 : }
243 : :
244 : : //---------------------------------------------------------------------------------------------------------
245 : : // Links
246 : : //---------------------------------------------------------------------------------------------------------
247 : :
248 : 0 : IMPL_LINK( TabWindow, Activate, TabControl*, pTabControl )
249 : : {
250 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
251 : 0 : ResetableGuard aLock( m_aLock );
252 : :
253 : 0 : sal_Int32 nPageId = pTabControl->GetCurPageId();
254 : :
255 : 0 : rtl::OUString aTitle = pTabControl->GetPageText( sal_uInt16( nPageId ));
256 : 0 : impl_SetTitle( aTitle );
257 : 0 : aLock.unlock();
258 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
259 : :
260 : 0 : implts_SendNotification( NOTIFY_ACTIVATED, nPageId );
261 : :
262 : 0 : return 1;
263 : : }
264 : :
265 : 0 : IMPL_LINK( TabWindow, Deactivate, TabControl*, pTabControl )
266 : : {
267 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
268 : 0 : ResetableGuard aLock( m_aLock );
269 : 0 : sal_Int32 nPageId = pTabControl->GetCurPageId();
270 : 0 : aLock.unlock();
271 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
272 : :
273 : 0 : implts_SendNotification( NOTIFY_DEACTIVATED, nPageId );
274 : :
275 : 0 : return 1;
276 : : }
277 : :
278 : : //---------------------------------------------------------------------------------------------------------
279 : : // XInitilization
280 : : //---------------------------------------------------------------------------------------------------------
281 : :
282 : 0 : void SAL_CALL TabWindow::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
283 : : throw (css::uno::Exception, css::uno::RuntimeException)
284 : : {
285 : 0 : const rtl::OUString aTopWindowArgName( RTL_CONSTASCII_USTRINGPARAM( "TopWindow" ));
286 : 0 : const rtl::OUString aSizeArgName( RTL_CONSTASCII_USTRINGPARAM( "Size" ));
287 : :
288 : 0 : css::awt::Size aDefaultSize( 500, 500 );
289 : 0 : css::awt::Size aSize( aDefaultSize );
290 : :
291 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
292 : 0 : ResetableGuard aLock( m_aLock );
293 : 0 : sal_Bool bInitalized( m_bInitialized );
294 : 0 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( m_xServiceManager );
295 : 0 : aLock.unlock();
296 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
297 : :
298 : 0 : if ( !bInitalized )
299 : : {
300 : 0 : css::beans::PropertyValue aPropValue;
301 : 0 : css::uno::Reference< css::awt::XTopWindow > xTopWindow;
302 : 0 : css::uno::Reference< css::awt::XToolkit > xToolkit;
303 : 0 : css::awt::WindowDescriptor aDescriptor;
304 : :
305 : 0 : if ( xSMGR.is() )
306 : : {
307 : : try
308 : : {
309 : : xToolkit = css::uno::Reference< css::awt::XToolkit >(
310 : 0 : xSMGR->createInstance( SERVICENAME_VCLTOOLKIT ), css::uno::UNO_QUERY );
311 : : }
312 : 0 : catch ( const css::uno::RuntimeException& )
313 : : {
314 : 0 : throw;
315 : : }
316 : 0 : catch ( const css::uno::Exception& )
317 : : {
318 : : }
319 : : }
320 : :
321 : 0 : for ( int i = 0; i < aArguments.getLength(); i++ )
322 : : {
323 : 0 : if ( aArguments[i] >>= aPropValue )
324 : : {
325 : 0 : if ( aPropValue.Name == aTopWindowArgName )
326 : 0 : aPropValue.Value >>= xTopWindow;
327 : 0 : else if ( aPropValue.Name == aSizeArgName )
328 : : {
329 : 0 : aPropValue.Value >>= aSize;
330 : 0 : if ( aSize.Width <= 0 )
331 : 0 : aSize.Width = aDefaultSize.Width;
332 : 0 : if ( aSize.Height <= 0 )
333 : 0 : aSize.Height = aDefaultSize.Height;
334 : : }
335 : : }
336 : : }
337 : :
338 : 0 : if ( xToolkit.is() )
339 : : {
340 : 0 : if ( !xTopWindow.is() )
341 : : {
342 : : // describe top window properties.
343 : 0 : aDescriptor.Type = css::awt::WindowClass_TOP;
344 : 0 : aDescriptor.ParentIndex = -1;
345 : 0 : aDescriptor.Parent = css::uno::Reference< css::awt::XWindowPeer >();
346 : 0 : aDescriptor.Bounds = css::awt::Rectangle( 0, 0, aSize.Width, aSize.Height );
347 : 0 : aDescriptor.WindowAttributes = 0;
348 : :
349 : : try
350 : : {
351 : 0 : xTopWindow = css::uno::Reference< css::awt::XTopWindow >( xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
352 : : }
353 : 0 : catch ( const css::uno::RuntimeException& )
354 : : {
355 : 0 : throw;
356 : : }
357 : 0 : catch ( const css::uno::Exception& )
358 : : {
359 : : }
360 : : }
361 : :
362 : 0 : if ( xTopWindow.is() )
363 : : {
364 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
365 : 0 : aLock.lock();
366 : 0 : m_bInitialized = sal_True;
367 : 0 : aLock.unlock();
368 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
369 : :
370 : 0 : css::uno::Reference< css::awt::XWindow > xWindow( xTopWindow, css::uno::UNO_QUERY );
371 : 0 : xWindow->addWindowListener( css::uno::Reference< css::awt::XWindowListener >(
372 : 0 : static_cast< ::cppu::OWeakObject* >( this ), css::uno::UNO_QUERY_THROW ));
373 : :
374 : 0 : xTopWindow->addTopWindowListener( css::uno::Reference< css::awt::XTopWindowListener >(
375 : 0 : static_cast< ::cppu::OWeakObject* >( this ), css::uno::UNO_QUERY_THROW ));
376 : :
377 : 0 : css::uno::Reference< css::awt::XWindow > xContainerWindow;
378 : 0 : css::uno::Reference< css::awt::XWindow > xTabControl;
379 : :
380 : : // describe container window properties.
381 : 0 : aDescriptor.Type = css::awt::WindowClass_SIMPLE;
382 : 0 : aDescriptor.ParentIndex = -1;
383 : 0 : aDescriptor.Parent = css::uno::Reference< css::awt::XWindowPeer >( xTopWindow, css::uno::UNO_QUERY );
384 : 0 : aDescriptor.Bounds = css::awt::Rectangle(0,0,0,0);
385 : 0 : aDescriptor.WindowAttributes = 0;
386 : :
387 : 0 : xContainerWindow = css::uno::Reference< css::awt::XWindow >( xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
388 : :
389 : : // create a tab control window properties
390 : 0 : aDescriptor.Type = css::awt::WindowClass_SIMPLE;
391 : 0 : aDescriptor.WindowServiceName = DECLARE_ASCII("tabcontrol");
392 : 0 : aDescriptor.ParentIndex = -1;
393 : 0 : aDescriptor.Parent = css::uno::Reference< css::awt::XWindowPeer >( xTopWindow, css::uno::UNO_QUERY );
394 : 0 : aDescriptor.Bounds = css::awt::Rectangle( 0,0,0,0 );
395 : 0 : aDescriptor.WindowAttributes = 0;
396 : :
397 : 0 : xTabControl = css::uno::Reference< css::awt::XWindow >( xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
398 : :
399 : 0 : if ( xContainerWindow.is() && xTabControl.is() )
400 : : {
401 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
402 : 0 : aLock.lock();
403 : 0 : m_xTopWindow = xTopWindow;
404 : 0 : m_xContainerWindow = xContainerWindow;
405 : 0 : m_xTabControlWindow = xTabControl;
406 : 0 : aLock.unlock();
407 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
408 : :
409 : 0 : xWindow->setPosSize( 0, 0, aSize.Width, aSize.Height, css::awt::PosSize::POSSIZE );
410 : :
411 : 0 : SolarMutexGuard aGuard;
412 : 0 : Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
413 : 0 : if( pWindow )
414 : 0 : pWindow->Show( sal_True );
415 : :
416 : 0 : pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
417 : 0 : if ( pWindow )
418 : 0 : pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
419 : :
420 : 0 : pWindow = VCLUnoHelper::GetWindow( xTabControl );
421 : 0 : if ( pWindow )
422 : : {
423 : 0 : pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
424 : 0 : TabControl* pTabControl = (TabControl *)pWindow;
425 : 0 : pTabControl->SetActivatePageHdl( LINK( this, TabWindow, Activate ));
426 : 0 : pTabControl->SetDeactivatePageHdl( LINK( this, TabWindow, Deactivate ));
427 : : }
428 : :
429 : 0 : implts_LayoutWindows();
430 : 0 : }
431 : : }
432 : 0 : }
433 : 0 : }
434 : 0 : }
435 : :
436 : : //---------------------------------------------------------------------------------------------------------
437 : : // XComponent
438 : : //---------------------------------------------------------------------------------------------------------
439 : 0 : void SAL_CALL TabWindow::dispose() throw (css::uno::RuntimeException)
440 : : {
441 : : // Send message to all listener and forget her references.
442 : : css::uno::Reference< css::lang::XComponent > xThis(
443 : 0 : static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
444 : 0 : css::lang::EventObject aEvent( xThis );
445 : :
446 : 0 : m_aListenerContainer.disposeAndClear( aEvent );
447 : :
448 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
449 : 0 : ResetableGuard aLock( m_aLock );
450 : 0 : css::uno::Reference< css::awt::XWindow > xTabControlWindow( m_xTabControlWindow );
451 : 0 : css::uno::Reference< css::awt::XWindow > xContainerWindow( m_xContainerWindow );
452 : 0 : css::uno::Reference< css::awt::XTopWindow > xTopWindow( m_xTopWindow );
453 : 0 : m_xTabControlWindow.clear();
454 : 0 : m_xContainerWindow.clear();
455 : 0 : m_xTopWindow.clear();
456 : 0 : aLock.unlock();
457 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
458 : :
459 : 0 : css::uno::Reference< css::lang::XComponent > xComponent( xTabControlWindow, css::uno::UNO_QUERY );
460 : 0 : if ( xComponent.is() )
461 : 0 : xComponent->dispose();
462 : :
463 : 0 : xComponent = css::uno::Reference< css::lang::XComponent >( xContainerWindow, css::uno::UNO_QUERY );
464 : 0 : if ( xComponent.is() )
465 : 0 : xComponent->dispose();
466 : :
467 : 0 : xComponent = css::uno::Reference< css::lang::XComponent >( xTopWindow, css::uno::UNO_QUERY );
468 : 0 : if ( xComponent.is() )
469 : 0 : xComponent->dispose();
470 : :
471 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
472 : 0 : aLock.lock();
473 : 0 : m_bDisposed = sal_True;
474 : 0 : aLock.unlock();
475 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
476 : 0 : }
477 : :
478 : 0 : void SAL_CALL TabWindow::addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
479 : : throw (css::uno::RuntimeException)
480 : : {
481 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
482 : 0 : ResetableGuard aLock( m_aLock );
483 : 0 : if ( m_bDisposed )
484 : 0 : return;
485 : 0 : aLock.unlock();
486 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
487 : :
488 : 0 : m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
489 : : }
490 : :
491 : 0 : void SAL_CALL TabWindow::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
492 : : throw (css::uno::RuntimeException)
493 : : {
494 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
495 : 0 : ResetableGuard aLock( m_aLock );
496 : 0 : if ( m_bDisposed )
497 : 0 : return;
498 : 0 : aLock.unlock();
499 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
500 : :
501 : 0 : m_aListenerContainer.removeInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
502 : : }
503 : :
504 : : //---------------------------------------------------------------------------------------------------------
505 : : // XEventListener
506 : : //---------------------------------------------------------------------------------------------------------
507 : 0 : void SAL_CALL TabWindow::disposing( const css::lang::EventObject& )
508 : : throw( css::uno::RuntimeException )
509 : : {
510 : 0 : }
511 : :
512 : : //---------------------------------------------------------------------------------------------------------
513 : : // XWindowListener
514 : : //---------------------------------------------------------------------------------------------------------
515 : 0 : void SAL_CALL TabWindow::windowResized( const css::awt::WindowEvent& )
516 : : throw( css::uno::RuntimeException )
517 : : {
518 : 0 : implts_LayoutWindows();
519 : 0 : }
520 : :
521 : 0 : void SAL_CALL TabWindow::windowMoved( const css::awt::WindowEvent& )
522 : : throw( css::uno::RuntimeException )
523 : : {
524 : 0 : }
525 : :
526 : 0 : void SAL_CALL TabWindow::windowShown( const css::lang::EventObject& )
527 : : throw( css::uno::RuntimeException )
528 : : {
529 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
530 : 0 : ResetableGuard aLock( m_aLock );
531 : :
532 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
533 : 0 : if ( pTabControl )
534 : 0 : pTabControl->Show();
535 : :
536 : 0 : if ( m_xContainerWindow.is() )
537 : : {
538 : 0 : Window* pWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
539 : 0 : if ( pWindow )
540 : 0 : pWindow->Show();
541 : 0 : }
542 : 0 : }
543 : :
544 : 0 : void SAL_CALL TabWindow::windowHidden( const css::lang::EventObject& )
545 : : throw( css::uno::RuntimeException )
546 : : {
547 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
548 : 0 : ResetableGuard aLock( m_aLock );
549 : 0 : if ( m_xContainerWindow.is() )
550 : : {
551 : 0 : Window* pWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
552 : 0 : if ( pWindow )
553 : 0 : pWindow->Hide();
554 : : }
555 : :
556 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
557 : 0 : if ( pTabControl )
558 : 0 : pTabControl->Hide();
559 : 0 : }
560 : :
561 : : //---------------------------------------------------------------------------------------------------------
562 : : // XTopWindowListener
563 : : //---------------------------------------------------------------------------------------------------------
564 : 0 : void SAL_CALL TabWindow::windowOpened( const css::lang::EventObject& )
565 : : throw (css::uno::RuntimeException)
566 : : {
567 : 0 : }
568 : :
569 : 0 : void SAL_CALL TabWindow::windowClosing( const css::lang::EventObject& )
570 : : throw (css::uno::RuntimeException)
571 : : {
572 : 0 : css::uno::Reference< css::lang::XComponent > xComponent( (OWeakObject *)this, css::uno::UNO_QUERY );
573 : 0 : if ( xComponent.is() )
574 : 0 : xComponent->dispose();
575 : 0 : }
576 : :
577 : 0 : void SAL_CALL TabWindow::windowClosed( const css::lang::EventObject& )
578 : : throw (css::uno::RuntimeException)
579 : : {
580 : 0 : }
581 : :
582 : 0 : void SAL_CALL TabWindow::windowMinimized( const css::lang::EventObject& )
583 : : throw (css::uno::RuntimeException)
584 : : {
585 : 0 : }
586 : :
587 : 0 : void SAL_CALL TabWindow::windowNormalized( const css::lang::EventObject& )
588 : : throw (css::uno::RuntimeException)
589 : : {
590 : 0 : }
591 : :
592 : 0 : void SAL_CALL TabWindow::windowActivated( const css::lang::EventObject& )
593 : : throw (css::uno::RuntimeException)
594 : : {
595 : 0 : }
596 : :
597 : 0 : void SAL_CALL TabWindow::windowDeactivated( const css::lang::EventObject& )
598 : : throw (css::uno::RuntimeException)
599 : : {
600 : 0 : }
601 : :
602 : : //---------------------------------------------------------------------------------------------------------
603 : : // XSimpleTabController
604 : : //---------------------------------------------------------------------------------------------------------
605 : :
606 : 0 : ::sal_Int32 SAL_CALL TabWindow::insertTab()
607 : : throw (css::uno::RuntimeException)
608 : : {
609 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
610 : 0 : ResetableGuard aLock( m_aLock );
611 : :
612 : 0 : if ( m_bDisposed )
613 : 0 : throw css::lang::DisposedException();
614 : :
615 : 0 : sal_Int32 nNextTabID( m_nNextTabID++ );
616 : :
617 : 0 : rtl::OUString aTitle;
618 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
619 : 0 : if ( pTabControl )
620 : 0 : pTabControl->InsertPage( sal_uInt16( nNextTabID ), aTitle );
621 : 0 : aLock.unlock();
622 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
623 : :
624 : 0 : implts_SendNotification( NOTIFY_INSERTED, nNextTabID );
625 : :
626 : 0 : return nNextTabID;
627 : : }
628 : :
629 : 0 : void SAL_CALL TabWindow::removeTab( ::sal_Int32 ID )
630 : : throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException)
631 : : {
632 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
633 : 0 : ResetableGuard aLock( m_aLock );
634 : :
635 : 0 : if ( m_bDisposed )
636 : 0 : throw css::lang::DisposedException();
637 : :
638 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
639 : 0 : if ( pTabControl )
640 : : {
641 : 0 : sal_uInt16 nCurTabId = pTabControl->GetCurPageId();
642 : 0 : sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
643 : 0 : if ( nPos == TAB_PAGE_NOTFOUND )
644 : 0 : throw css::lang::IndexOutOfBoundsException();
645 : : else
646 : : {
647 : 0 : pTabControl->RemovePage( sal_uInt16( ID ));
648 : 0 : nCurTabId = pTabControl->GetCurPageId();
649 : : }
650 : 0 : aLock.unlock();
651 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
652 : :
653 : 0 : implts_SendNotification( NOTIFY_REMOVED, ID );
654 : :
655 : : // activate new tab if old tab was active!
656 : 0 : nPos = pTabControl->GetPagePos( sal_uInt16( nCurTabId ));
657 : 0 : if ( nPos != TAB_PAGE_NOTFOUND && nCurTabId != ID )
658 : 0 : activateTab( nCurTabId );
659 : 0 : }
660 : 0 : }
661 : :
662 : 0 : void SAL_CALL TabWindow::setTabProps( ::sal_Int32 ID, const css::uno::Sequence< css::beans::NamedValue >& Properties )
663 : : throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException)
664 : : {
665 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
666 : 0 : ResetableGuard aLock( m_aLock );
667 : :
668 : 0 : if ( m_bDisposed )
669 : 0 : throw css::lang::DisposedException();
670 : :
671 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
672 : 0 : if ( pTabControl )
673 : : {
674 : 0 : sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
675 : 0 : if ( nPos == TAB_PAGE_NOTFOUND )
676 : 0 : throw css::lang::IndexOutOfBoundsException();
677 : : else
678 : : {
679 : 0 : comphelper::SequenceAsHashMap aSeqHashMap( Properties );
680 : :
681 : 0 : ::rtl::OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID ));
682 : 0 : sal_Int32 nNewPos = nPos;
683 : :
684 : : aTitle = aSeqHashMap.getUnpackedValueOrDefault< ::rtl::OUString >(
685 : 0 : m_aTitlePropName, aTitle );
686 : 0 : pTabControl->SetPageText( sal_uInt16( ID ), aTitle );
687 : : nNewPos = aSeqHashMap.getUnpackedValueOrDefault< sal_Int32 >(
688 : 0 : m_aPosPropName, nNewPos );
689 : 0 : if ( nNewPos != sal_Int32( nPos ))
690 : : {
691 : 0 : nPos = sal_uInt16( nNewPos );
692 : 0 : if ( nPos >= pTabControl->GetPageCount() )
693 : 0 : nPos = TAB_APPEND;
694 : :
695 : 0 : pTabControl->RemovePage( sal_uInt16( ID ));
696 : 0 : pTabControl->InsertPage( sal_uInt16( ID ), aTitle, nPos );
697 : : }
698 : :
699 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
700 : 0 : aLock.unlock();
701 : :
702 : 0 : css::uno::Sequence< css::beans::NamedValue > aNamedValueSeq = getTabProps( ID );
703 : 0 : implts_SendNotification( NOTIFY_CHANGED, ID, aNamedValueSeq );
704 : : }
705 : 0 : }
706 : 0 : }
707 : :
708 : 0 : css::uno::Sequence< css::beans::NamedValue > SAL_CALL TabWindow::getTabProps( ::sal_Int32 ID )
709 : : throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException)
710 : : {
711 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
712 : 0 : ResetableGuard aLock( m_aLock );
713 : :
714 : 0 : if ( m_bDisposed )
715 : 0 : throw css::lang::DisposedException();
716 : :
717 : 0 : css::uno::Sequence< css::beans::NamedValue > aNamedValueSeq;
718 : :
719 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
720 : 0 : if ( pTabControl )
721 : : {
722 : 0 : sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
723 : 0 : if ( nPos == TAB_PAGE_NOTFOUND )
724 : 0 : throw css::lang::IndexOutOfBoundsException();
725 : : else
726 : : {
727 : 0 : rtl::OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID ));
728 : 0 : nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
729 : :
730 : 0 : css::uno::Sequence< css::beans::NamedValue > aSeq( 2 );
731 : 0 : aSeq[0].Name = m_aTitlePropName;
732 : 0 : aSeq[0].Value = css::uno::makeAny( aTitle );
733 : 0 : aSeq[1].Name = m_aPosPropName;
734 : 0 : aSeq[1].Value = css::uno::makeAny( sal_Int32( nPos ));
735 : 0 : return aSeq;
736 : : }
737 : : }
738 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
739 : :
740 : 0 : return aNamedValueSeq;
741 : : }
742 : :
743 : 0 : void SAL_CALL TabWindow::activateTab( ::sal_Int32 ID )
744 : : throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException)
745 : : {
746 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
747 : 0 : ResetableGuard aLock( m_aLock );
748 : :
749 : 0 : if ( m_bDisposed )
750 : 0 : throw css::lang::DisposedException();
751 : :
752 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
753 : 0 : if ( pTabControl )
754 : : {
755 : 0 : sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
756 : 0 : if ( nPos == TAB_PAGE_NOTFOUND )
757 : 0 : throw css::lang::IndexOutOfBoundsException();
758 : : else
759 : : {
760 : 0 : sal_Int32 nOldID = pTabControl->GetCurPageId();
761 : 0 : rtl::OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID ));
762 : 0 : pTabControl->SetCurPageId( sal_uInt16( ID ));
763 : 0 : pTabControl->SelectTabPage( sal_uInt16( ID ));
764 : 0 : impl_SetTitle( aTitle );
765 : :
766 : 0 : aLock.unlock();
767 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
768 : :
769 : 0 : if ( nOldID != TAB_PAGE_NOTFOUND )
770 : 0 : implts_SendNotification( NOTIFY_DEACTIVATED, nOldID );
771 : 0 : implts_SendNotification( NOTIFY_ACTIVATED, ID );
772 : : }
773 : 0 : }
774 : 0 : }
775 : :
776 : 0 : ::sal_Int32 SAL_CALL TabWindow::getActiveTabID()
777 : : throw (css::uno::RuntimeException)
778 : : {
779 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
780 : 0 : ResetableGuard aLock( m_aLock );
781 : :
782 : 0 : if ( m_bDisposed )
783 : 0 : throw css::lang::DisposedException();
784 : :
785 : 0 : TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
786 : 0 : if ( pTabControl )
787 : : {
788 : 0 : sal_uInt16 nID = pTabControl->GetCurPageId();
789 : 0 : if ( nID == TAB_PAGE_NOTFOUND )
790 : 0 : return -1;
791 : : else
792 : 0 : return sal_Int32( nID );
793 : : }
794 : :
795 : 0 : return -1;
796 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
797 : : }
798 : :
799 : 0 : void SAL_CALL TabWindow::addTabListener(
800 : : const css::uno::Reference< css::awt::XTabListener >& xListener )
801 : : throw (css::uno::RuntimeException)
802 : : {
803 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
804 : 0 : ResetableGuard aLock( m_aLock );
805 : 0 : if ( m_bDisposed )
806 : 0 : return;
807 : 0 : aLock.unlock();
808 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
809 : :
810 : : m_aListenerContainer.addInterface(
811 : 0 : ::getCppuType( ( const css::uno::Reference< css::awt::XTabListener >* ) NULL ), xListener );
812 : : }
813 : :
814 : 0 : void SAL_CALL TabWindow::removeTabListener( const css::uno::Reference< css::awt::XTabListener >& xListener )
815 : : throw (css::uno::RuntimeException)
816 : : {
817 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
818 : 0 : ResetableGuard aLock( m_aLock );
819 : 0 : if ( m_bDisposed )
820 : 0 : return;
821 : 0 : aLock.unlock();
822 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
823 : :
824 : : m_aListenerContainer.removeInterface(
825 : 0 : ::getCppuType( ( const css::uno::Reference< css::awt::XTabListener >* ) NULL ), xListener );
826 : : }
827 : :
828 : : //---------------------------------------------------------------------------------------------------------
829 : : // OPropertySetHelper
830 : : //---------------------------------------------------------------------------------------------------------
831 : :
832 : : // XPropertySet helper
833 : 0 : sal_Bool SAL_CALL TabWindow::convertFastPropertyValue( css::uno::Any& aConvertedValue ,
834 : : css::uno::Any& aOldValue ,
835 : : sal_Int32 nHandle ,
836 : : const css::uno::Any& aValue )
837 : : throw( css::lang::IllegalArgumentException )
838 : : {
839 : : // Initialize state with sal_False !!!
840 : : // (Handle can be invalid)
841 : 0 : sal_Bool bReturn = sal_False;
842 : :
843 : 0 : switch( nHandle )
844 : : {
845 : : case TABWINDOW_PROPHANDLE_PARENTWINDOW :
846 : : bReturn = PropHelper::willPropertyBeChanged(
847 : : com::sun::star::uno::makeAny( m_xContainerWindow ),
848 : : aValue,
849 : : aOldValue,
850 : 0 : aConvertedValue);
851 : 0 : break;
852 : :
853 : : case TABWINDOW_PROPHANDLE_TOPWINDOW :
854 : : bReturn = PropHelper::willPropertyBeChanged(
855 : : com::sun::star::uno::makeAny( m_xTopWindow ),
856 : : aValue,
857 : : aOldValue,
858 : 0 : aConvertedValue);
859 : 0 : break;
860 : : }
861 : :
862 : : // Return state of operation.
863 : 0 : return bReturn ;
864 : : }
865 : :
866 : 0 : void SAL_CALL TabWindow::setFastPropertyValue_NoBroadcast( sal_Int32,
867 : : const css::uno::Any&)
868 : : throw( css::uno::Exception )
869 : : {
870 : 0 : }
871 : :
872 : 0 : void SAL_CALL TabWindow::getFastPropertyValue( css::uno::Any& aValue ,
873 : : sal_Int32 nHandle ) const
874 : : {
875 : 0 : switch( nHandle )
876 : : {
877 : : case TABWINDOW_PROPHANDLE_PARENTWINDOW:
878 : 0 : aValue <<= m_xContainerWindow;
879 : 0 : break;
880 : : case TABWINDOW_PROPHANDLE_TOPWINDOW:
881 : 0 : aValue <<= m_xTopWindow;
882 : 0 : break;
883 : : }
884 : 0 : }
885 : :
886 : 0 : ::cppu::IPropertyArrayHelper& SAL_CALL TabWindow::getInfoHelper()
887 : : {
888 : : // Optimize this method !
889 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
890 : : // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
891 : : static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
892 : :
893 : 0 : if( pInfoHelper == NULL )
894 : : {
895 : : // Ready for multithreading
896 : 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
897 : :
898 : : // Control this pointer again, another instance can be faster then these!
899 : 0 : if( pInfoHelper == NULL )
900 : : {
901 : : // Define static member to give structure of properties to baseclass "OPropertySetHelper".
902 : : // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
903 : : // "sal_True" say: Table is sorted by name.
904 : 0 : static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
905 : 0 : pInfoHelper = &aInfoHelper;
906 : 0 : }
907 : : }
908 : :
909 : 0 : return(*pInfoHelper);
910 : : }
911 : :
912 : 0 : css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL TabWindow::getPropertySetInfo()
913 : : throw ( css::uno::RuntimeException )
914 : : {
915 : : // Optimize this method !
916 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
917 : : // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
918 : : static css::uno::Reference< css::beans::XPropertySetInfo >* pInfo = NULL;
919 : :
920 : 0 : if( pInfo == NULL )
921 : : {
922 : : // Ready for multithreading
923 : 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
924 : : // Control this pointer again, another instance can be faster then these!
925 : 0 : if( pInfo == NULL )
926 : : {
927 : : // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
928 : : // (Use method "getInfoHelper()".)
929 : 0 : static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
930 : 0 : pInfo = &xInfo;
931 : 0 : }
932 : : }
933 : :
934 : 0 : return (*pInfo);
935 : : }
936 : :
937 : 0 : const css::uno::Sequence< css::beans::Property > TabWindow::impl_getStaticPropertyDescriptor()
938 : : {
939 : : // Create property array to initialize sequence!
940 : : // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
941 : : // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
942 : : // It's necessary for methods of OPropertySetHelper.
943 : : // ATTENTION:
944 : : // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
945 : :
946 : : const com::sun::star::beans::Property pProperties[] =
947 : : {
948 : : com::sun::star::beans::Property( TABWINDOW_PROPNAME_PARENTWINDOW,
949 : : TABWINDOW_PROPHANDLE_PARENTWINDOW,
950 : 0 : ::getCppuType((const css::uno::Reference< css::awt::XWindow >*)NULL),
951 : : com::sun::star::beans::PropertyAttribute::READONLY ),
952 : : com::sun::star::beans::Property( TABWINDOW_PROPNAME_TOPWINDOW,
953 : : TABWINDOW_PROPHANDLE_TOPWINDOW,
954 : 0 : ::getCppuType((const css::uno::Reference< css::awt::XWindow >*)NULL),
955 : : com::sun::star::beans::PropertyAttribute::READONLY )
956 : 0 : }; // Use it to initialize sequence!
957 : 0 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, TABWINDOW_PROPCOUNT );
958 : :
959 : : // Return "PropertyDescriptor"
960 : 0 : return lPropertyDescriptor;
961 : : }
962 : :
963 : : }
964 : :
965 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|