fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / tabwin / tabwindow.cxx
blob44c87bb48300e7fa997fe5880f2117fd3f3127f6
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 <tabwin/tabwindow.hxx>
21 #include <properties.h>
23 #include <com/sun/star/util/XURLTransformer.hpp>
24 #include <com/sun/star/awt/Toolkit.hpp>
25 #include <com/sun/star/awt/PosSize.hpp>
26 #include <com/sun/star/awt/WindowDescriptor.hpp>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/lang/DisposedException.hpp>
30 #include <rtl/ustrbuf.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/window.hxx>
33 #include <vcl/wrkwin.hxx>
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <comphelper/sequenceashashmap.hxx>
37 // Defines
39 using namespace com::sun::star;
41 namespace framework
44 // XInterface, XTypeProvider, XServiceInfo
46 DEFINE_XINTERFACE_11 ( TabWindow ,
47 ::cppu::OWeakObject ,
48 DIRECT_INTERFACE( css::lang::XTypeProvider ),
49 DIRECT_INTERFACE( css::lang::XServiceInfo ),
50 DIRECT_INTERFACE( css::lang::XInitialization ),
51 DIRECT_INTERFACE( css::lang::XComponent ),
52 DIRECT_INTERFACE( css::awt::XWindowListener ),
53 DIRECT_INTERFACE( css::awt::XTopWindowListener ),
54 DIRECT_INTERFACE( css::awt::XSimpleTabController ),
55 DERIVED_INTERFACE( css::lang::XEventListener, css::awt::XWindowListener ),
56 DIRECT_INTERFACE( css::beans::XMultiPropertySet ),
57 DIRECT_INTERFACE( css::beans::XFastPropertySet ),
58 DIRECT_INTERFACE( css::beans::XPropertySet )
61 DEFINE_XTYPEPROVIDER_11 ( TabWindow ,
62 css::lang::XTypeProvider ,
63 css::lang::XServiceInfo ,
64 css::lang::XInitialization ,
65 css::lang::XComponent ,
66 css::awt::XWindowListener ,
67 css::awt::XTopWindowListener ,
68 css::awt::XSimpleTabController ,
69 css::lang::XEventListener ,
70 css::beans::XMultiPropertySet ,
71 css::beans::XFastPropertySet ,
72 css::beans::XPropertySet
75 PRIVATE_DEFINE_XSERVICEINFO_BASE ( TabWindow ,
76 ::cppu::OWeakObject ,
77 SERVICENAME_TABWINDOW ,
78 IMPLEMENTATIONNAME_TABWINDOW
81 DEFINE_INIT_SERVICE ( TabWindow, {} )
83 TabWindow::TabWindow( const css::uno::Reference< css::uno::XComponentContext >& xContext )
84 : ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aMutex )
85 , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
86 , m_bInitialized( false )
87 , m_bDisposed( false )
88 , m_nNextTabID( 1 )
89 , m_aTitlePropName( "Title" )
90 , m_aPosPropName( "Position" )
91 , m_xContext( xContext )
92 , m_aListenerContainer( m_aMutex )
96 TabWindow::~TabWindow()
100 // Helper
102 void TabWindow::implts_LayoutWindows() const
104 const sal_Int32 nTabControlHeight = 30;
106 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
107 SolarMutexClearableGuard aLock;
108 css::uno::Reference< css::awt::XDevice > xDevice( m_xTopWindow, css::uno::UNO_QUERY );
109 css::uno::Reference< css::awt::XWindow > xWindow( m_xTopWindow, css::uno::UNO_QUERY );
110 css::uno::Reference< css::awt::XWindow > xTabControlWindow( m_xTabControlWindow );
111 css::uno::Reference< css::awt::XWindow > xContainerWindow( m_xContainerWindow );
112 aLock.clear();
113 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
115 // Convert relativ size to output size.
116 if ( xWindow.is() && xDevice.is() )
118 css::awt::Rectangle aRectangle = xWindow->getPosSize();
119 css::awt::DeviceInfo aInfo = xDevice->getInfo();
120 css::awt::Size aSize ( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
121 aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
123 css::awt::Size aContainerWindowSize;
124 css::awt::Size aTabControlSize;
126 aContainerWindowSize.Width = aSize.Width;
127 aTabControlSize.Width = aSize.Width;
129 aContainerWindowSize.Height = std::max( sal_Int32( 0 ), aSize.Height - nTabControlHeight );
130 aTabControlSize.Height = nTabControlHeight;
132 xContainerWindow->setPosSize( 0, 0,
133 aContainerWindowSize.Width, aContainerWindowSize.Height,
134 css::awt::PosSize::POSSIZE );
135 xTabControlWindow->setPosSize( 0, std::max( nTabControlHeight, sal_Int32( aSize.Height - nTabControlHeight)),
136 aTabControlSize.Width, aTabControlSize.Height,
137 css::awt::PosSize::POSSIZE );
141 TabControl* TabWindow::impl_GetTabControl( const css::uno::Reference< css::awt::XWindow >& rTabControlWindow ) const
143 vcl::Window* pWindow = VCLUnoHelper::GetWindow( rTabControlWindow );
144 if ( pWindow )
145 return static_cast<TabControl *>(pWindow);
146 else
147 return NULL;
150 void TabWindow::impl_SetTitle( const OUString& rTitle )
152 if ( m_xTopWindow.is() )
154 vcl::Window* pWindow = VCLUnoHelper::GetWindow(
155 css::uno::Reference< css::awt::XWindow >(
156 m_xTopWindow, css::uno::UNO_QUERY ));
157 if ( pWindow )
158 pWindow->SetText( rTitle );
162 void TabWindow::implts_SendNotification( Notification eNotify, sal_Int32 ID ) const
164 ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
165 cppu::UnoType<css::awt::XTabListener>::get());
166 if (pContainer!=NULL)
168 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
169 while (pIterator.hasMoreElements())
173 switch ( eNotify )
175 case NOTIFY_INSERTED:
176 static_cast<css::awt::XTabListener*>(pIterator.next())->inserted( ID );
177 break;
178 case NOTIFY_REMOVED:
179 static_cast<css::awt::XTabListener*>(pIterator.next())->removed( ID );
180 break;
181 case NOTIFY_ACTIVATED:
182 static_cast<css::awt::XTabListener*>(pIterator.next())->activated( ID );
183 break;
184 case NOTIFY_DEACTIVATED:
185 static_cast<css::awt::XTabListener*>(pIterator.next())->deactivated( ID );
186 break;
187 default:
188 break;
191 catch( const css::uno::RuntimeException& )
193 pIterator.remove();
199 void TabWindow::implts_SendNotification( Notification eNotify, sal_Int32 ID, const css::uno::Sequence< css::beans::NamedValue >& rSeq ) const
201 ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
202 cppu::UnoType<css::awt::XTabListener>::get());
203 if (pContainer!=NULL)
205 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
206 while (pIterator.hasMoreElements())
210 switch ( eNotify )
212 case NOTIFY_CHANGED:
213 static_cast<css::awt::XTabListener*>(pIterator.next())->changed( ID, rSeq );
214 break;
215 default:
216 break;
219 catch( const css::uno::RuntimeException& )
221 pIterator.remove();
227 // Links
229 IMPL_LINK( TabWindow, Activate, TabControl*, pTabControl )
231 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
232 SolarMutexClearableGuard aLock;
234 sal_Int32 nPageId = pTabControl->GetCurPageId();
236 OUString aTitle = pTabControl->GetPageText( sal_uInt16( nPageId ));
237 impl_SetTitle( aTitle );
238 aLock.clear();
239 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
241 implts_SendNotification( NOTIFY_ACTIVATED, nPageId );
243 return 1;
246 IMPL_LINK_TYPED( TabWindow, Deactivate, TabControl*, pTabControl, bool )
248 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
249 SolarMutexClearableGuard aLock;
250 sal_Int32 nPageId = pTabControl->GetCurPageId();
251 aLock.clear();
252 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
254 implts_SendNotification( NOTIFY_DEACTIVATED, nPageId );
256 return true;
259 // XInitilization
261 void SAL_CALL TabWindow::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
262 throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
264 const OUString aTopWindowArgName( "TopWindow" );
265 const OUString aSizeArgName( "Size" );
267 css::awt::Size aDefaultSize( 500, 500 );
268 css::awt::Size aSize( aDefaultSize );
270 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
271 SolarMutexResettableGuard aLock;
272 bool bInitalized( m_bInitialized );
273 css::uno::Reference< css::uno::XComponentContext > xContext( m_xContext );
274 aLock.clear();
275 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
277 if ( !bInitalized )
279 css::beans::PropertyValue aPropValue;
280 css::uno::Reference< css::awt::XTopWindow > xTopWindow;
281 css::uno::Reference< css::awt::XToolkit2 > xToolkit;
282 css::awt::WindowDescriptor aDescriptor;
284 if ( xContext.is() )
288 xToolkit = css::awt::Toolkit::create( xContext );
290 catch ( const css::uno::RuntimeException& )
292 throw;
294 catch ( const css::uno::Exception& )
299 for ( int i = 0; i < aArguments.getLength(); i++ )
301 if ( aArguments[i] >>= aPropValue )
303 if ( aPropValue.Name == aTopWindowArgName )
304 aPropValue.Value >>= xTopWindow;
305 else if ( aPropValue.Name == aSizeArgName )
307 aPropValue.Value >>= aSize;
308 if ( aSize.Width <= 0 )
309 aSize.Width = aDefaultSize.Width;
310 if ( aSize.Height <= 0 )
311 aSize.Height = aDefaultSize.Height;
316 if ( xToolkit.is() )
318 if ( !xTopWindow.is() )
320 // describe top window properties.
321 aDescriptor.Type = css::awt::WindowClass_TOP;
322 aDescriptor.ParentIndex = -1;
323 aDescriptor.Parent = css::uno::Reference< css::awt::XWindowPeer >();
324 aDescriptor.Bounds = css::awt::Rectangle( 0, 0, aSize.Width, aSize.Height );
325 aDescriptor.WindowAttributes = 0;
329 xTopWindow = css::uno::Reference< css::awt::XTopWindow >( xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
331 catch ( const css::uno::RuntimeException& )
333 throw;
335 catch ( const css::uno::Exception& )
340 if ( xTopWindow.is() )
342 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
343 aLock.reset();
344 m_bInitialized = true;
345 aLock.clear();
346 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
348 css::uno::Reference< css::awt::XWindow > xWindow( xTopWindow, css::uno::UNO_QUERY );
349 xWindow->addWindowListener( css::uno::Reference< css::awt::XWindowListener >(
350 static_cast< ::cppu::OWeakObject* >( this ), css::uno::UNO_QUERY_THROW ));
352 xTopWindow->addTopWindowListener( css::uno::Reference< css::awt::XTopWindowListener >(
353 static_cast< ::cppu::OWeakObject* >( this ), css::uno::UNO_QUERY_THROW ));
355 css::uno::Reference< css::awt::XWindow > xContainerWindow;
356 css::uno::Reference< css::awt::XWindow > xTabControl;
358 // describe container window properties.
359 aDescriptor.Type = css::awt::WindowClass_SIMPLE;
360 aDescriptor.ParentIndex = -1;
361 aDescriptor.Parent = css::uno::Reference< css::awt::XWindowPeer >( xTopWindow, css::uno::UNO_QUERY );
362 aDescriptor.Bounds = css::awt::Rectangle(0,0,0,0);
363 aDescriptor.WindowAttributes = 0;
365 xContainerWindow = css::uno::Reference< css::awt::XWindow >( xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
367 // create a tab control window properties
368 aDescriptor.Type = css::awt::WindowClass_SIMPLE;
369 aDescriptor.WindowServiceName = "tabcontrol";
370 aDescriptor.ParentIndex = -1;
371 aDescriptor.Parent = css::uno::Reference< css::awt::XWindowPeer >( xTopWindow, css::uno::UNO_QUERY );
372 aDescriptor.Bounds = css::awt::Rectangle( 0,0,0,0 );
373 aDescriptor.WindowAttributes = 0;
375 xTabControl = css::uno::Reference< css::awt::XWindow >( xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
377 if ( xContainerWindow.is() && xTabControl.is() )
379 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
380 aLock.reset();
381 m_xTopWindow = xTopWindow;
382 m_xContainerWindow = xContainerWindow;
383 m_xTabControlWindow = xTabControl;
384 aLock.clear();
385 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
387 xWindow->setPosSize( 0, 0, aSize.Width, aSize.Height, css::awt::PosSize::POSSIZE );
389 SolarMutexGuard aGuard;
390 vcl::Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
391 if( pWindow )
392 pWindow->Show( true );
394 pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
395 if ( pWindow )
396 pWindow->Show( true, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
398 pWindow = VCLUnoHelper::GetWindow( xTabControl );
399 if ( pWindow )
401 pWindow->Show( true, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
402 TabControl* pTabControl = static_cast<TabControl *>(pWindow);
403 pTabControl->SetActivatePageHdl( LINK( this, TabWindow, Activate ));
404 pTabControl->SetDeactivatePageHdl( LINK( this, TabWindow, Deactivate ));
407 implts_LayoutWindows();
414 // XComponent
416 void SAL_CALL TabWindow::dispose() throw (css::uno::RuntimeException, std::exception)
418 // Send message to all listener and forget her references.
419 css::uno::Reference< css::lang::XComponent > xThis(
420 static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
421 css::lang::EventObject aEvent( xThis );
423 m_aListenerContainer.disposeAndClear( aEvent );
425 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
426 SolarMutexResettableGuard aLock;
427 css::uno::Reference< css::awt::XWindow > xTabControlWindow( m_xTabControlWindow );
428 css::uno::Reference< css::awt::XWindow > xContainerWindow( m_xContainerWindow );
429 css::uno::Reference< css::awt::XTopWindow > xTopWindow( m_xTopWindow );
430 m_xTabControlWindow.clear();
431 m_xContainerWindow.clear();
432 m_xTopWindow.clear();
433 aLock.clear();
434 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
436 css::uno::Reference< css::lang::XComponent > xComponent( xTabControlWindow, css::uno::UNO_QUERY );
437 if ( xComponent.is() )
438 xComponent->dispose();
440 xComponent = css::uno::Reference< css::lang::XComponent >( xContainerWindow, css::uno::UNO_QUERY );
441 if ( xComponent.is() )
442 xComponent->dispose();
444 xComponent = css::uno::Reference< css::lang::XComponent >( xTopWindow, css::uno::UNO_QUERY );
445 if ( xComponent.is() )
446 xComponent->dispose();
448 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
449 aLock.reset();
450 m_bDisposed = true;
451 aLock.clear();
452 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
455 void SAL_CALL TabWindow::addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
456 throw (css::uno::RuntimeException, std::exception)
458 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
459 SolarMutexClearableGuard aLock;
460 if ( m_bDisposed )
461 return;
462 aLock.clear();
463 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
465 m_aListenerContainer.addInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
468 void SAL_CALL TabWindow::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
469 throw (css::uno::RuntimeException, std::exception)
471 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
472 SolarMutexClearableGuard aLock;
473 if ( m_bDisposed )
474 return;
475 aLock.clear();
476 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
478 m_aListenerContainer.removeInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
481 // XEventListener
483 void SAL_CALL TabWindow::disposing( const css::lang::EventObject& )
484 throw( css::uno::RuntimeException, std::exception )
488 // XWindowListener
490 void SAL_CALL TabWindow::windowResized( const css::awt::WindowEvent& )
491 throw( css::uno::RuntimeException, std::exception )
493 implts_LayoutWindows();
496 void SAL_CALL TabWindow::windowMoved( const css::awt::WindowEvent& )
497 throw( css::uno::RuntimeException, std::exception )
501 void SAL_CALL TabWindow::windowShown( const css::lang::EventObject& )
502 throw( css::uno::RuntimeException, std::exception )
504 SolarMutexGuard g;
506 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
507 if ( pTabControl )
508 pTabControl->Show();
510 if ( m_xContainerWindow.is() )
512 vcl::Window* pWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
513 if ( pWindow )
514 pWindow->Show();
518 void SAL_CALL TabWindow::windowHidden( const css::lang::EventObject& )
519 throw( css::uno::RuntimeException, std::exception )
521 SolarMutexGuard g;
522 if ( m_xContainerWindow.is() )
524 vcl::Window* pWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
525 if ( pWindow )
526 pWindow->Hide();
529 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
530 if ( pTabControl )
531 pTabControl->Hide();
534 // XTopWindowListener
536 void SAL_CALL TabWindow::windowOpened( const css::lang::EventObject& )
537 throw (css::uno::RuntimeException, std::exception)
541 void SAL_CALL TabWindow::windowClosing( const css::lang::EventObject& )
542 throw (css::uno::RuntimeException, std::exception)
544 css::uno::Reference< css::lang::XComponent > xComponent( (OWeakObject *)this, css::uno::UNO_QUERY );
545 if ( xComponent.is() )
546 xComponent->dispose();
549 void SAL_CALL TabWindow::windowClosed( const css::lang::EventObject& )
550 throw (css::uno::RuntimeException, std::exception)
554 void SAL_CALL TabWindow::windowMinimized( const css::lang::EventObject& )
555 throw (css::uno::RuntimeException, std::exception)
559 void SAL_CALL TabWindow::windowNormalized( const css::lang::EventObject& )
560 throw (css::uno::RuntimeException, std::exception)
564 void SAL_CALL TabWindow::windowActivated( const css::lang::EventObject& )
565 throw (css::uno::RuntimeException, std::exception)
569 void SAL_CALL TabWindow::windowDeactivated( const css::lang::EventObject& )
570 throw (css::uno::RuntimeException, std::exception)
574 // XSimpleTabController
576 ::sal_Int32 SAL_CALL TabWindow::insertTab()
577 throw (css::uno::RuntimeException, std::exception)
579 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
580 SolarMutexClearableGuard aLock;
582 if ( m_bDisposed )
583 throw css::lang::DisposedException();
585 sal_Int32 nNextTabID( m_nNextTabID++ );
587 OUString aTitle;
588 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
589 if ( pTabControl )
590 pTabControl->InsertPage( sal_uInt16( nNextTabID ), aTitle );
591 aLock.clear();
592 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
594 implts_SendNotification( NOTIFY_INSERTED, nNextTabID );
596 return nNextTabID;
599 void SAL_CALL TabWindow::removeTab( ::sal_Int32 ID )
600 throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception)
602 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
603 SolarMutexClearableGuard aLock;
605 if ( m_bDisposed )
606 throw css::lang::DisposedException();
608 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
609 if ( pTabControl )
611 sal_uInt16 nCurTabId = pTabControl->GetCurPageId();
612 sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
613 if ( nPos == TAB_PAGE_NOTFOUND )
614 throw css::lang::IndexOutOfBoundsException();
615 else
617 pTabControl->RemovePage( sal_uInt16( ID ));
618 nCurTabId = pTabControl->GetCurPageId();
620 aLock.clear();
621 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
623 implts_SendNotification( NOTIFY_REMOVED, ID );
625 // activate new tab if old tab was active!
626 nPos = pTabControl->GetPagePos( sal_uInt16( nCurTabId ));
627 if ( nPos != TAB_PAGE_NOTFOUND && nCurTabId != ID )
628 activateTab( nCurTabId );
632 void SAL_CALL TabWindow::setTabProps( ::sal_Int32 ID, const css::uno::Sequence< css::beans::NamedValue >& Properties )
633 throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception)
635 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
636 SolarMutexClearableGuard aLock;
638 if ( m_bDisposed )
639 throw css::lang::DisposedException();
641 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
642 if ( pTabControl )
644 sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
645 if ( nPos == TAB_PAGE_NOTFOUND )
646 throw css::lang::IndexOutOfBoundsException();
647 else
649 comphelper::SequenceAsHashMap aSeqHashMap( Properties );
651 OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID ));
652 sal_Int32 nNewPos = nPos;
654 aTitle = aSeqHashMap.getUnpackedValueOrDefault< OUString >(
655 m_aTitlePropName, aTitle );
656 pTabControl->SetPageText( sal_uInt16( ID ), aTitle );
657 nNewPos = aSeqHashMap.getUnpackedValueOrDefault< sal_Int32 >(
658 m_aPosPropName, nNewPos );
659 if ( nNewPos != sal_Int32( nPos ))
661 nPos = sal_uInt16( nNewPos );
662 if ( nPos >= pTabControl->GetPageCount() )
663 nPos = TAB_APPEND;
665 pTabControl->RemovePage( sal_uInt16( ID ));
666 pTabControl->InsertPage( sal_uInt16( ID ), aTitle, nPos );
669 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
670 aLock.clear();
672 css::uno::Sequence< css::beans::NamedValue > aNamedValueSeq = getTabProps( ID );
673 implts_SendNotification( NOTIFY_CHANGED, ID, aNamedValueSeq );
678 css::uno::Sequence< css::beans::NamedValue > SAL_CALL TabWindow::getTabProps( ::sal_Int32 ID )
679 throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception)
681 SolarMutexGuard g;
683 if ( m_bDisposed )
684 throw css::lang::DisposedException();
686 css::uno::Sequence< css::beans::NamedValue > aNamedValueSeq;
688 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
689 if ( pTabControl )
691 sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
692 if ( nPos == TAB_PAGE_NOTFOUND )
693 throw css::lang::IndexOutOfBoundsException();
694 else
696 OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID ));
697 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
699 css::uno::Sequence< css::beans::NamedValue > aSeq( 2 );
700 aSeq[0].Name = m_aTitlePropName;
701 aSeq[0].Value = css::uno::makeAny( aTitle );
702 aSeq[1].Name = m_aPosPropName;
703 aSeq[1].Value = css::uno::makeAny( sal_Int32( nPos ));
704 return aSeq;
708 return aNamedValueSeq;
711 void SAL_CALL TabWindow::activateTab( ::sal_Int32 ID )
712 throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception)
714 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
715 SolarMutexClearableGuard aLock;
717 if ( m_bDisposed )
718 throw css::lang::DisposedException();
720 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
721 if ( pTabControl )
723 sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID ));
724 if ( nPos == TAB_PAGE_NOTFOUND )
725 throw css::lang::IndexOutOfBoundsException();
726 else
728 sal_Int32 nOldID = pTabControl->GetCurPageId();
729 OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID ));
730 pTabControl->SetCurPageId( sal_uInt16( ID ));
731 pTabControl->SelectTabPage( sal_uInt16( ID ));
732 impl_SetTitle( aTitle );
734 aLock.clear();
735 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
737 if ( nOldID != TAB_PAGE_NOTFOUND )
738 implts_SendNotification( NOTIFY_DEACTIVATED, nOldID );
739 implts_SendNotification( NOTIFY_ACTIVATED, ID );
744 ::sal_Int32 SAL_CALL TabWindow::getActiveTabID()
745 throw (css::uno::RuntimeException, std::exception)
747 SolarMutexGuard g;
749 if ( m_bDisposed )
750 throw css::lang::DisposedException();
752 TabControl* pTabControl = impl_GetTabControl( m_xTabControlWindow );
753 if ( pTabControl )
755 sal_uInt16 nID = pTabControl->GetCurPageId();
756 if ( nID == TAB_PAGE_NOTFOUND )
757 return -1;
758 else
759 return sal_Int32( nID );
762 return -1;
765 void SAL_CALL TabWindow::addTabListener(
766 const css::uno::Reference< css::awt::XTabListener >& xListener )
767 throw (css::uno::RuntimeException, std::exception)
769 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
770 SolarMutexClearableGuard aLock;
771 if ( m_bDisposed )
772 return;
773 aLock.clear();
774 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
776 m_aListenerContainer.addInterface(
777 cppu::UnoType<css::awt::XTabListener>::get(), xListener );
780 void SAL_CALL TabWindow::removeTabListener( const css::uno::Reference< css::awt::XTabListener >& xListener )
781 throw (css::uno::RuntimeException, std::exception)
783 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
784 SolarMutexClearableGuard aLock;
785 if ( m_bDisposed )
786 return;
787 aLock.clear();
788 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
790 m_aListenerContainer.removeInterface(
791 cppu::UnoType<css::awt::XTabListener>::get(), xListener );
794 // OPropertySetHelper
796 // XPropertySet helper
797 sal_Bool SAL_CALL TabWindow::convertFastPropertyValue( css::uno::Any& aConvertedValue ,
798 css::uno::Any& aOldValue ,
799 sal_Int32 nHandle ,
800 const css::uno::Any& aValue )
801 throw( css::lang::IllegalArgumentException )
803 // Initialize state with sal_False !!!
804 // (Handle can be invalid)
805 bool bReturn = false;
807 switch( nHandle )
809 case TABWINDOW_PROPHANDLE_PARENTWINDOW :
810 bReturn = PropHelper::willPropertyBeChanged(
811 com::sun::star::uno::makeAny( m_xContainerWindow ),
812 aValue,
813 aOldValue,
814 aConvertedValue);
815 break;
817 case TABWINDOW_PROPHANDLE_TOPWINDOW :
818 bReturn = PropHelper::willPropertyBeChanged(
819 com::sun::star::uno::makeAny( m_xTopWindow ),
820 aValue,
821 aOldValue,
822 aConvertedValue);
823 break;
826 // Return state of operation.
827 return bReturn;
830 void SAL_CALL TabWindow::setFastPropertyValue_NoBroadcast( sal_Int32,
831 const css::uno::Any&)
832 throw( css::uno::Exception, std::exception )
836 void SAL_CALL TabWindow::getFastPropertyValue( css::uno::Any& aValue ,
837 sal_Int32 nHandle ) const
839 switch( nHandle )
841 case TABWINDOW_PROPHANDLE_PARENTWINDOW:
842 aValue <<= m_xContainerWindow;
843 break;
844 case TABWINDOW_PROPHANDLE_TOPWINDOW:
845 aValue <<= m_xTopWindow;
846 break;
850 ::cppu::IPropertyArrayHelper& SAL_CALL TabWindow::getInfoHelper()
852 // Optimize this method !
853 // We initialize a static variable only one time. And we don't must use a mutex at every call!
854 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
855 static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
857 if( pInfoHelper == NULL )
859 // Ready for multithreading
860 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
862 // Control this pointer again, another instance can be faster then these!
863 if( pInfoHelper == NULL )
865 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
866 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
867 // "sal_True" say: Table is sorted by name.
868 static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
869 pInfoHelper = &aInfoHelper;
873 return(*pInfoHelper);
876 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL TabWindow::getPropertySetInfo()
877 throw ( css::uno::RuntimeException, std::exception )
879 // Optimize this method !
880 // We initialize a static variable only one time. And we don't must use a mutex at every call!
881 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
882 static css::uno::Reference< css::beans::XPropertySetInfo >* pInfo = NULL;
884 if( pInfo == NULL )
886 // Ready for multithreading
887 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
888 // Control this pointer again, another instance can be faster then these!
889 if( pInfo == NULL )
891 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
892 // (Use method "getInfoHelper()".)
893 static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
894 pInfo = &xInfo;
898 return (*pInfo);
901 const css::uno::Sequence< css::beans::Property > TabWindow::impl_getStaticPropertyDescriptor()
903 // Create property array to initialize sequence!
904 // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
905 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
906 // It's necessary for methods of OPropertySetHelper.
907 // ATTENTION:
908 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
910 const com::sun::star::beans::Property pProperties[] =
912 com::sun::star::beans::Property( TABWINDOW_PROPNAME_PARENTWINDOW,
913 TABWINDOW_PROPHANDLE_PARENTWINDOW,
914 cppu::UnoType<css::awt::XWindow>::get(),
915 com::sun::star::beans::PropertyAttribute::READONLY ),
916 com::sun::star::beans::Property( TABWINDOW_PROPNAME_TOPWINDOW,
917 TABWINDOW_PROPHANDLE_TOPWINDOW,
918 cppu::UnoType<css::awt::XWindow>::get(),
919 com::sun::star::beans::PropertyAttribute::READONLY )
920 }; // Use it to initialize sequence!
921 const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, TABWINDOW_PROPCOUNT );
923 // Return "PropertyDescriptor"
924 return lPropertyDescriptor;
929 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */