1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabwindow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <tabwin/tabwindow.hxx>
34 #include <properties.h>
36 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
39 #include <threadhelp/resetableguard.hxx>
41 //_________________________________________________________________________________________________________________
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/util/XURLTransformer.hpp>
45 #include <com/sun/star/awt/PosSize.hpp>
46 #include <com/sun/star/awt/WindowDescriptor.hpp>
47 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 #include <com/sun/star/lang/DisposedException.hpp>
49 //_________________________________________________________________________________________________________________
50 // includes of other projects
51 //_________________________________________________________________________________________________________________
52 #include <rtl/ustrbuf.hxx>
53 #include <tools/urlobj.hxx>
54 #include <vcl/svapp.hxx>
55 #include <vcl/window.hxx>
56 #include <vcl/wrkwin.hxx>
57 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
58 #include <toolkit/unohlp.hxx>
60 #include <comphelper/sequenceashashmap.hxx>
62 //_________________________________________________________________________________________________________________
64 //_________________________________________________________________________________________________________________
68 using namespace com::sun::star
;
73 //*****************************************************************************************************************
74 // XInterface, XTypeProvider, XServiceInfo
75 //*****************************************************************************************************************
76 DEFINE_XINTERFACE_11 ( TabWindow
,
78 DIRECT_INTERFACE( css::lang::XTypeProvider
),
79 DIRECT_INTERFACE( css::lang::XServiceInfo
),
80 DIRECT_INTERFACE( css::lang::XInitialization
),
81 DIRECT_INTERFACE( css::lang::XComponent
),
82 DIRECT_INTERFACE( css::awt::XWindowListener
),
83 DIRECT_INTERFACE( css::awt::XTopWindowListener
),
84 DIRECT_INTERFACE( css::awt::XSimpleTabController
),
85 DERIVED_INTERFACE( css::lang::XEventListener
, css::awt::XWindowListener
),
86 DIRECT_INTERFACE( css::beans::XMultiPropertySet
),
87 DIRECT_INTERFACE( css::beans::XFastPropertySet
),
88 DIRECT_INTERFACE( css::beans::XPropertySet
)
91 DEFINE_XTYPEPROVIDER_11 ( TabWindow
,
92 css::lang::XTypeProvider
,
93 css::lang::XServiceInfo
,
94 css::lang::XInitialization
,
95 css::lang::XComponent
,
96 css::awt::XWindowListener
,
97 css::awt::XTopWindowListener
,
98 css::awt::XSimpleTabController
,
99 css::lang::XEventListener
,
100 css::beans::XMultiPropertySet
,
101 css::beans::XFastPropertySet
,
102 css::beans::XPropertySet
105 DEFINE_XSERVICEINFO_MULTISERVICE ( TabWindow
,
106 ::cppu::OWeakObject
,
107 SERVICENAME_TABWINDOW
,
108 IMPLEMENTATIONNAME_TABWINDOW
111 DEFINE_INIT_SERVICE ( TabWindow
, {} )
113 TabWindow::TabWindow( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xServiceManager
) :
114 ThreadHelpBase( &Application::GetSolarMutex() )
115 , ::cppu::OBroadcastHelperVar
< ::cppu::OMultiTypeInterfaceContainerHelper
, ::cppu::OMultiTypeInterfaceContainerHelper::keyType
>( m_aLock
.getShareableOslMutex() )
116 , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper
* >(this)) )
117 , m_bInitialized( sal_False
)
118 , m_bDisposed( sal_False
)
120 , m_aTitlePropName( RTL_CONSTASCII_USTRINGPARAM( "Title" ))
121 , m_aPosPropName( RTL_CONSTASCII_USTRINGPARAM( "Position" ))
122 , m_xServiceManager( xServiceManager
)
123 , m_aListenerContainer( m_aLock
.getShareableOslMutex() )
127 TabWindow::~TabWindow()
131 //---------------------------------------------------------------------------------------------------------
133 //---------------------------------------------------------------------------------------------------------
135 void TabWindow::implts_LayoutWindows() const
137 const sal_Int32 nTabControlHeight
= 30;
139 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
140 ResetableGuard
aLock( m_aLock
);
141 css::uno::Reference
< css::awt::XDevice
> xDevice( m_xTopWindow
, css::uno::UNO_QUERY
);
142 css::uno::Reference
< css::awt::XWindow
> xWindow( m_xTopWindow
, css::uno::UNO_QUERY
);
143 css::uno::Reference
< css::awt::XWindow
> xTabControlWindow( m_xTabControlWindow
);
144 css::uno::Reference
< css::awt::XWindow
> xContainerWindow( m_xContainerWindow
);
146 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
148 // Convert relativ size to output size.
149 if ( xWindow
.is() && xDevice
.is() )
151 css::awt::Rectangle aRectangle
= xWindow
->getPosSize();
152 css::awt::DeviceInfo aInfo
= xDevice
->getInfo();
153 css::awt::Size
aSize ( aRectangle
.Width
- aInfo
.LeftInset
- aInfo
.RightInset
,
154 aRectangle
.Height
- aInfo
.TopInset
- aInfo
.BottomInset
);
156 css::awt::Size aContainerWindowSize
;
157 css::awt::Size aTabControlSize
;
159 aContainerWindowSize
.Width
= aSize
.Width
;
160 aTabControlSize
.Width
= aSize
.Width
;
162 aContainerWindowSize
.Height
= std::max( sal_Int32( 0 ), aSize
.Height
- nTabControlHeight
);
163 aTabControlSize
.Height
= nTabControlHeight
;
165 xContainerWindow
->setPosSize( 0, 0,
166 aContainerWindowSize
.Width
, aContainerWindowSize
.Height
,
167 css::awt::PosSize::POSSIZE
);
168 xTabControlWindow
->setPosSize( 0, std::max( nTabControlHeight
, sal_Int32( aSize
.Height
- nTabControlHeight
)),
169 aTabControlSize
.Width
, aTabControlSize
.Height
,
170 css::awt::PosSize::POSSIZE
);
174 TabControl
* TabWindow::impl_GetTabControl( const css::uno::Reference
< css::awt::XWindow
>& rTabControlWindow
) const
176 Window
* pWindow
= VCLUnoHelper::GetWindow( rTabControlWindow
);
178 return (TabControl
*)pWindow
;
183 void TabWindow::impl_SetTitle( const ::rtl::OUString
& rTitle
)
185 if ( m_xTopWindow
.is() )
187 Window
* pWindow
= VCLUnoHelper::GetWindow(
188 css::uno::Reference
< css::awt::XWindow
>(
189 m_xTopWindow
, css::uno::UNO_QUERY
));
191 pWindow
->SetText( rTitle
);
195 void TabWindow::implts_SendNotification( Notification eNotify
, sal_Int32 ID
) const
197 ::cppu::OInterfaceContainerHelper
* pContainer
= m_aListenerContainer
.getContainer(
198 ::getCppuType( ( const css::uno::Reference
< css::awt::XTabListener
>*) NULL
) );
199 if (pContainer
!=NULL
)
201 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
202 while (pIterator
.hasMoreElements())
208 case NOTIFY_INSERTED
:
209 ((css::awt::XTabListener
*)pIterator
.next())->inserted( ID
);
212 ((css::awt::XTabListener
*)pIterator
.next())->removed( ID
);
214 case NOTIFY_ACTIVATED
:
215 ((css::awt::XTabListener
*)pIterator
.next())->activated( ID
);
217 case NOTIFY_DEACTIVATED
:
218 ((css::awt::XTabListener
*)pIterator
.next())->deactivated( ID
);
224 catch( css::uno::RuntimeException
& )
232 void TabWindow::implts_SendNotification( Notification eNotify
, sal_Int32 ID
, const css::uno::Sequence
< css::beans::NamedValue
>& rSeq
) const
234 ::cppu::OInterfaceContainerHelper
* pContainer
= m_aListenerContainer
.getContainer(
235 ::getCppuType( ( const css::uno::Reference
< css::awt::XTabListener
>*) NULL
) );
236 if (pContainer
!=NULL
)
238 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
239 while (pIterator
.hasMoreElements())
246 ((css::awt::XTabListener
*)pIterator
.next())->changed( ID
, rSeq
);
252 catch( css::uno::RuntimeException
& )
260 //---------------------------------------------------------------------------------------------------------
262 //---------------------------------------------------------------------------------------------------------
264 IMPL_LINK( TabWindow
, Activate
, TabControl
*, pTabControl
)
266 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
267 ResetableGuard
aLock( m_aLock
);
269 sal_Int32 nPageId
= pTabControl
->GetCurPageId();
271 rtl::OUString aTitle
= pTabControl
->GetPageText( sal_uInt16( nPageId
));
272 impl_SetTitle( aTitle
);
274 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
276 implts_SendNotification( NOTIFY_ACTIVATED
, nPageId
);
281 IMPL_LINK( TabWindow
, Deactivate
, TabControl
*, pTabControl
)
283 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
284 ResetableGuard
aLock( m_aLock
);
285 sal_Int32 nPageId
= pTabControl
->GetCurPageId();
287 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
289 implts_SendNotification( NOTIFY_DEACTIVATED
, nPageId
);
294 //---------------------------------------------------------------------------------------------------------
296 //---------------------------------------------------------------------------------------------------------
298 void SAL_CALL
TabWindow::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
299 throw (css::uno::Exception
, css::uno::RuntimeException
)
301 const rtl::OUString
aTopWindowArgName( RTL_CONSTASCII_USTRINGPARAM( "TopWindow" ));
302 const rtl::OUString
aSizeArgName( RTL_CONSTASCII_USTRINGPARAM( "Size" ));
304 css::awt::Size
aDefaultSize( 500, 500 );
305 css::awt::Size
aSize( aDefaultSize
);
307 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
308 ResetableGuard
aLock( m_aLock
);
309 sal_Bool
bInitalized( m_bInitialized
);
310 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR( m_xServiceManager
);
312 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
316 css::beans::PropertyValue aPropValue
;
317 css::uno::Reference
< css::awt::XTopWindow
> xTopWindow
;
318 css::uno::Reference
< css::awt::XToolkit
> xToolkit
;
319 css::awt::WindowDescriptor aDescriptor
;
325 xToolkit
= css::uno::Reference
< css::awt::XToolkit
>(
326 xSMGR
->createInstance( SERVICENAME_VCLTOOLKIT
), css::uno::UNO_QUERY
);
328 catch ( css::uno::RuntimeException
& )
332 catch ( css::uno::Exception
& )
337 for ( int i
= 0; i
< aArguments
.getLength(); i
++ )
339 if ( aArguments
[i
] >>= aPropValue
)
341 if ( aPropValue
.Name
== aTopWindowArgName
)
342 aPropValue
.Value
>>= xTopWindow
;
343 else if ( aPropValue
.Name
== aSizeArgName
)
345 aPropValue
.Value
>>= aSize
;
346 if ( aSize
.Width
<= 0 )
347 aSize
.Width
= aDefaultSize
.Width
;
348 if ( aSize
.Height
<= 0 )
349 aSize
.Height
= aDefaultSize
.Height
;
356 if ( !xTopWindow
.is() )
358 // describe top window properties.
359 aDescriptor
.Type
= css::awt::WindowClass_TOP
;
360 aDescriptor
.ParentIndex
= -1;
361 aDescriptor
.Parent
= css::uno::Reference
< css::awt::XWindowPeer
>();
362 aDescriptor
.Bounds
= css::awt::Rectangle( 0, 0, aSize
.Width
, aSize
.Height
);
363 aDescriptor
.WindowAttributes
= 0;
367 xTopWindow
= css::uno::Reference
< css::awt::XTopWindow
>( xToolkit
->createWindow( aDescriptor
), css::uno::UNO_QUERY
);
369 catch ( css::uno::RuntimeException
& )
373 catch ( css::uno::Exception
& )
378 if ( xTopWindow
.is() )
380 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
382 m_bInitialized
= sal_True
;
384 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
386 css::uno::Reference
< css::awt::XWindow
> xWindow( xTopWindow
, css::uno::UNO_QUERY
);
387 xWindow
->addWindowListener( css::uno::Reference
< css::awt::XWindowListener
>(
388 static_cast< ::cppu::OWeakObject
* >( this ), css::uno::UNO_QUERY_THROW
));
390 xTopWindow
->addTopWindowListener( css::uno::Reference
< css::awt::XTopWindowListener
>(
391 static_cast< ::cppu::OWeakObject
* >( this ), css::uno::UNO_QUERY_THROW
));
393 css::uno::Reference
< css::awt::XWindow
> xContainerWindow
;
394 css::uno::Reference
< css::awt::XWindow
> xTabControl
;
396 // describe container window properties.
397 aDescriptor
.Type
= css::awt::WindowClass_SIMPLE
;
398 aDescriptor
.ParentIndex
= -1;
399 aDescriptor
.Parent
= css::uno::Reference
< css::awt::XWindowPeer
>( xTopWindow
, css::uno::UNO_QUERY
);
400 aDescriptor
.Bounds
= css::awt::Rectangle(0,0,0,0);
401 aDescriptor
.WindowAttributes
= 0;
403 xContainerWindow
= css::uno::Reference
< css::awt::XWindow
>( xToolkit
->createWindow( aDescriptor
), css::uno::UNO_QUERY
);
405 // create a tab control window properties
406 aDescriptor
.Type
= css::awt::WindowClass_SIMPLE
;
407 aDescriptor
.WindowServiceName
= DECLARE_ASCII("tabcontrol");
408 aDescriptor
.ParentIndex
= -1;
409 aDescriptor
.Parent
= css::uno::Reference
< css::awt::XWindowPeer
>( xTopWindow
, css::uno::UNO_QUERY
);
410 aDescriptor
.Bounds
= css::awt::Rectangle( 0,0,0,0 );
411 aDescriptor
.WindowAttributes
= 0;
413 xTabControl
= css::uno::Reference
< css::awt::XWindow
>( xToolkit
->createWindow( aDescriptor
), css::uno::UNO_QUERY
);
415 if ( xContainerWindow
.is() && xTabControl
.is() )
417 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
419 m_xTopWindow
= xTopWindow
;
420 m_xContainerWindow
= xContainerWindow
;
421 m_xTabControlWindow
= xTabControl
;
423 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
425 xWindow
->setPosSize( 0, 0, aSize
.Width
, aSize
.Height
, css::awt::PosSize::POSSIZE
);
427 vos::OGuard
aGuard( Application::GetSolarMutex() );
428 Window
* pWindow
= VCLUnoHelper::GetWindow( xWindow
);
430 pWindow
->Show( TRUE
);
432 pWindow
= VCLUnoHelper::GetWindow( xContainerWindow
);
434 pWindow
->Show( TRUE
, SHOW_NOFOCUSCHANGE
| SHOW_NOACTIVATE
);
436 pWindow
= VCLUnoHelper::GetWindow( xTabControl
);
439 pWindow
->Show( TRUE
, SHOW_NOFOCUSCHANGE
| SHOW_NOACTIVATE
);
440 TabControl
* pTabControl
= (TabControl
*)pWindow
;
441 pTabControl
->SetActivatePageHdl( LINK( this, TabWindow
, Activate
));
442 pTabControl
->SetDeactivatePageHdl( LINK( this, TabWindow
, Deactivate
));
445 implts_LayoutWindows();
452 //---------------------------------------------------------------------------------------------------------
454 //---------------------------------------------------------------------------------------------------------
455 void SAL_CALL
TabWindow::dispose() throw (css::uno::RuntimeException
)
457 // Send message to all listener and forget her references.
458 css::uno::Reference
< css::lang::XComponent
> xThis(
459 static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
);
460 css::lang::EventObject
aEvent( xThis
);
462 m_aListenerContainer
.disposeAndClear( aEvent
);
464 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
465 ResetableGuard
aLock( m_aLock
);
466 css::uno::Reference
< css::awt::XWindow
> xTabControlWindow( m_xTabControlWindow
);
467 css::uno::Reference
< css::awt::XWindow
> xContainerWindow( m_xContainerWindow
);
468 css::uno::Reference
< css::awt::XTopWindow
> xTopWindow( m_xTopWindow
);
469 m_xTabControlWindow
.clear();
470 m_xContainerWindow
.clear();
471 m_xTopWindow
.clear();
473 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
475 css::uno::Reference
< css::lang::XComponent
> xComponent( xTabControlWindow
, css::uno::UNO_QUERY
);
476 if ( xComponent
.is() )
477 xComponent
->dispose();
479 xComponent
= css::uno::Reference
< css::lang::XComponent
>( xContainerWindow
, css::uno::UNO_QUERY
);
480 if ( xComponent
.is() )
481 xComponent
->dispose();
483 xComponent
= css::uno::Reference
< css::lang::XComponent
>( xTopWindow
, css::uno::UNO_QUERY
);
484 if ( xComponent
.is() )
485 xComponent
->dispose();
487 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
489 m_bDisposed
= sal_True
;
491 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
494 void SAL_CALL
TabWindow::addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
)
495 throw (css::uno::RuntimeException
)
497 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
498 ResetableGuard
aLock( m_aLock
);
502 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
504 m_aListenerContainer
.addInterface( ::getCppuType( ( const css::uno::Reference
< css::lang::XEventListener
>* ) NULL
), xListener
);
507 void SAL_CALL
TabWindow::removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
)
508 throw (css::uno::RuntimeException
)
510 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
511 ResetableGuard
aLock( m_aLock
);
515 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
517 m_aListenerContainer
.removeInterface( ::getCppuType( ( const css::uno::Reference
< css::lang::XEventListener
>* ) NULL
), xListener
);
520 //---------------------------------------------------------------------------------------------------------
522 //---------------------------------------------------------------------------------------------------------
523 void SAL_CALL
TabWindow::disposing( const css::lang::EventObject
& )
524 throw( css::uno::RuntimeException
)
528 //---------------------------------------------------------------------------------------------------------
530 //---------------------------------------------------------------------------------------------------------
531 void SAL_CALL
TabWindow::windowResized( const css::awt::WindowEvent
& )
532 throw( css::uno::RuntimeException
)
534 implts_LayoutWindows();
537 void SAL_CALL
TabWindow::windowMoved( const css::awt::WindowEvent
& )
538 throw( css::uno::RuntimeException
)
542 void SAL_CALL
TabWindow::windowShown( const css::lang::EventObject
& )
543 throw( css::uno::RuntimeException
)
545 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
546 ResetableGuard
aLock( m_aLock
);
548 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
552 if ( m_xContainerWindow
.is() )
554 Window
* pWindow
= VCLUnoHelper::GetWindow( m_xContainerWindow
);
560 void SAL_CALL
TabWindow::windowHidden( const css::lang::EventObject
& )
561 throw( css::uno::RuntimeException
)
563 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
564 ResetableGuard
aLock( m_aLock
);
565 if ( m_xContainerWindow
.is() )
567 Window
* pWindow
= VCLUnoHelper::GetWindow( m_xContainerWindow
);
572 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
577 //---------------------------------------------------------------------------------------------------------
578 // XTopWindowListener
579 //---------------------------------------------------------------------------------------------------------
580 void SAL_CALL
TabWindow::windowOpened( const css::lang::EventObject
& )
581 throw (css::uno::RuntimeException
)
585 void SAL_CALL
TabWindow::windowClosing( const css::lang::EventObject
& )
586 throw (css::uno::RuntimeException
)
588 css::uno::Reference
< css::lang::XComponent
> xComponent( (OWeakObject
*)this, css::uno::UNO_QUERY
);
589 if ( xComponent
.is() )
590 xComponent
->dispose();
593 void SAL_CALL
TabWindow::windowClosed( const css::lang::EventObject
& )
594 throw (css::uno::RuntimeException
)
598 void SAL_CALL
TabWindow::windowMinimized( const css::lang::EventObject
& )
599 throw (css::uno::RuntimeException
)
603 void SAL_CALL
TabWindow::windowNormalized( const css::lang::EventObject
& )
604 throw (css::uno::RuntimeException
)
608 void SAL_CALL
TabWindow::windowActivated( const css::lang::EventObject
& )
609 throw (css::uno::RuntimeException
)
613 void SAL_CALL
TabWindow::windowDeactivated( const css::lang::EventObject
& )
614 throw (css::uno::RuntimeException
)
618 //---------------------------------------------------------------------------------------------------------
619 // XSimpleTabController
620 //---------------------------------------------------------------------------------------------------------
622 ::sal_Int32 SAL_CALL
TabWindow::insertTab()
623 throw (css::uno::RuntimeException
)
625 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
626 ResetableGuard
aLock( m_aLock
);
629 throw css::lang::DisposedException();
631 sal_Int32
nNextTabID( m_nNextTabID
++ );
633 rtl::OUString aTitle
;
634 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
636 pTabControl
->InsertPage( sal_uInt16( nNextTabID
), aTitle
);
638 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
640 implts_SendNotification( NOTIFY_INSERTED
, nNextTabID
);
645 void SAL_CALL
TabWindow::removeTab( ::sal_Int32 ID
)
646 throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
)
648 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
649 ResetableGuard
aLock( m_aLock
);
652 throw css::lang::DisposedException();
654 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
657 sal_uInt16 nCurTabId
= pTabControl
->GetCurPageId();
658 sal_uInt16 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
659 if ( nPos
== TAB_PAGE_NOTFOUND
)
660 throw css::lang::IndexOutOfBoundsException();
663 pTabControl
->RemovePage( sal_uInt16( ID
));
664 nCurTabId
= pTabControl
->GetCurPageId();
667 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
669 implts_SendNotification( NOTIFY_REMOVED
, ID
);
671 // activate new tab if old tab was active!
672 nPos
= pTabControl
->GetPagePos( sal_uInt16( nCurTabId
));
673 if ( nPos
!= TAB_PAGE_NOTFOUND
&& nCurTabId
!= ID
)
674 activateTab( nCurTabId
);
678 void SAL_CALL
TabWindow::setTabProps( ::sal_Int32 ID
, const css::uno::Sequence
< css::beans::NamedValue
>& Properties
)
679 throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
)
681 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
682 ResetableGuard
aLock( m_aLock
);
685 throw css::lang::DisposedException();
687 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
690 sal_uInt16 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
691 if ( nPos
== TAB_PAGE_NOTFOUND
)
692 throw css::lang::IndexOutOfBoundsException();
695 comphelper::SequenceAsHashMap
aSeqHashMap( Properties
);
697 ::rtl::OUString aTitle
= pTabControl
->GetPageText( sal_uInt16( ID
));
698 sal_Int32 nNewPos
= nPos
;
700 aTitle
= aSeqHashMap
.getUnpackedValueOrDefault
< ::rtl::OUString
>(
701 m_aTitlePropName
, aTitle
);
702 pTabControl
->SetPageText( sal_uInt16( ID
), aTitle
);
703 nNewPos
= aSeqHashMap
.getUnpackedValueOrDefault
< sal_Int32
>(
704 m_aPosPropName
, nNewPos
);
705 if ( nNewPos
!= sal_Int32( nPos
))
707 nPos
= sal_uInt16( nNewPos
);
708 if ( nPos
>= pTabControl
->GetPageCount() )
711 pTabControl
->RemovePage( sal_uInt16( ID
));
712 pTabControl
->InsertPage( sal_uInt16( ID
), aTitle
, nPos
);
715 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
718 css::uno::Sequence
< css::beans::NamedValue
> aNamedValueSeq
= getTabProps( ID
);
719 implts_SendNotification( NOTIFY_CHANGED
, ID
, aNamedValueSeq
);
724 css::uno::Sequence
< css::beans::NamedValue
> SAL_CALL
TabWindow::getTabProps( ::sal_Int32 ID
)
725 throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
)
727 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
728 ResetableGuard
aLock( m_aLock
);
731 throw css::lang::DisposedException();
733 css::uno::Sequence
< css::beans::NamedValue
> aNamedValueSeq
;
735 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
738 sal_uInt16 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
739 if ( nPos
== TAB_PAGE_NOTFOUND
)
740 throw css::lang::IndexOutOfBoundsException();
743 rtl::OUString aTitle
= pTabControl
->GetPageText( sal_uInt16( ID
));
744 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
746 css::uno::Sequence
< css::beans::NamedValue
> aSeq( 2 );
747 aSeq
[0].Name
= m_aTitlePropName
;
748 aSeq
[0].Value
= css::uno::makeAny( aTitle
);
749 aSeq
[1].Name
= m_aPosPropName
;
750 aSeq
[1].Value
= css::uno::makeAny( sal_Int32( nPos
));
754 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
756 return aNamedValueSeq
;
759 void SAL_CALL
TabWindow::activateTab( ::sal_Int32 ID
)
760 throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
)
762 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
763 ResetableGuard
aLock( m_aLock
);
766 throw css::lang::DisposedException();
768 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
771 sal_uInt16 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
772 if ( nPos
== TAB_PAGE_NOTFOUND
)
773 throw css::lang::IndexOutOfBoundsException();
776 sal_Int32 nOldID
= pTabControl
->GetCurPageId();
777 rtl::OUString aTitle
= pTabControl
->GetPageText( sal_uInt16( ID
));
778 pTabControl
->SetCurPageId( sal_uInt16( ID
));
779 pTabControl
->SelectTabPage( sal_uInt16( ID
));
780 impl_SetTitle( aTitle
);
783 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
785 if ( nOldID
!= TAB_PAGE_NOTFOUND
)
786 implts_SendNotification( NOTIFY_DEACTIVATED
, nOldID
);
787 implts_SendNotification( NOTIFY_ACTIVATED
, ID
);
792 ::sal_Int32 SAL_CALL
TabWindow::getActiveTabID()
793 throw (css::uno::RuntimeException
)
795 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
796 ResetableGuard
aLock( m_aLock
);
799 throw css::lang::DisposedException();
801 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
804 sal_uInt16 nID
= pTabControl
->GetCurPageId();
805 if ( nID
== TAB_PAGE_NOTFOUND
)
808 return sal_Int32( nID
);
812 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
815 void SAL_CALL
TabWindow::addTabListener(
816 const css::uno::Reference
< css::awt::XTabListener
>& xListener
)
817 throw (css::uno::RuntimeException
)
819 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
820 ResetableGuard
aLock( m_aLock
);
824 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
826 m_aListenerContainer
.addInterface(
827 ::getCppuType( ( const css::uno::Reference
< css::awt::XTabListener
>* ) NULL
), xListener
);
830 void SAL_CALL
TabWindow::removeTabListener( const css::uno::Reference
< css::awt::XTabListener
>& xListener
)
831 throw (css::uno::RuntimeException
)
833 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
834 ResetableGuard
aLock( m_aLock
);
838 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
840 m_aListenerContainer
.removeInterface(
841 ::getCppuType( ( const css::uno::Reference
< css::awt::XTabListener
>* ) NULL
), xListener
);
844 //---------------------------------------------------------------------------------------------------------
845 // OPropertySetHelper
846 //---------------------------------------------------------------------------------------------------------
848 // XPropertySet helper
849 sal_Bool SAL_CALL
TabWindow::convertFastPropertyValue( css::uno::Any
& aConvertedValue
,
850 css::uno::Any
& aOldValue
,
852 const css::uno::Any
& aValue
)
853 throw( css::lang::IllegalArgumentException
)
855 // Initialize state with FALSE !!!
856 // (Handle can be invalid)
857 sal_Bool bReturn
= sal_False
;
861 case TABWINDOW_PROPHANDLE_PARENTWINDOW
:
862 bReturn
= PropHelper::willPropertyBeChanged(
863 com::sun::star::uno::makeAny( m_xContainerWindow
),
869 case TABWINDOW_PROPHANDLE_TOPWINDOW
:
870 bReturn
= PropHelper::willPropertyBeChanged(
871 com::sun::star::uno::makeAny( m_xTopWindow
),
878 // Return state of operation.
882 void SAL_CALL
TabWindow::setFastPropertyValue_NoBroadcast( sal_Int32
,
883 const css::uno::Any
&)
884 throw( css::uno::Exception
)
888 void SAL_CALL
TabWindow::getFastPropertyValue( css::uno::Any
& aValue
,
889 sal_Int32 nHandle
) const
893 case TABWINDOW_PROPHANDLE_PARENTWINDOW
:
894 aValue
<<= m_xContainerWindow
;
896 case TABWINDOW_PROPHANDLE_TOPWINDOW
:
897 aValue
<<= m_xTopWindow
;
902 ::cppu::IPropertyArrayHelper
& SAL_CALL
TabWindow::getInfoHelper()
904 // Optimize this method !
905 // We initialize a static variable only one time. And we don't must use a mutex at every call!
906 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
907 static ::cppu::OPropertyArrayHelper
* pInfoHelper
= NULL
;
909 if( pInfoHelper
== NULL
)
911 // Ready for multithreading
912 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
914 // Control this pointer again, another instance can be faster then these!
915 if( pInfoHelper
== NULL
)
917 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
918 // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
919 // "sal_True" say: Table is sorted by name.
920 static ::cppu::OPropertyArrayHelper
aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True
);
921 pInfoHelper
= &aInfoHelper
;
925 return(*pInfoHelper
);
928 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
TabWindow::getPropertySetInfo()
929 throw ( css::uno::RuntimeException
)
931 // Optimize this method !
932 // We initialize a static variable only one time. And we don't must use a mutex at every call!
933 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
934 static css::uno::Reference
< css::beans::XPropertySetInfo
>* pInfo
= NULL
;
938 // Ready for multithreading
939 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
940 // Control this pointer again, another instance can be faster then these!
943 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
944 // (Use method "getInfoHelper()".)
945 static css::uno::Reference
< css::beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
953 const css::uno::Sequence
< css::beans::Property
> TabWindow::impl_getStaticPropertyDescriptor()
955 // Create a new static property array to initialize sequence!
956 // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
957 // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
958 // It's necessary for methods of OPropertySetHelper.
960 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
962 static const com::sun::star::beans::Property pProperties
[] =
964 com::sun::star::beans::Property( TABWINDOW_PROPNAME_PARENTWINDOW
,
965 TABWINDOW_PROPHANDLE_PARENTWINDOW
,
966 ::getCppuType((const css::uno::Reference
< css::awt::XWindow
>*)NULL
),
967 com::sun::star::beans::PropertyAttribute::READONLY
),
968 com::sun::star::beans::Property( TABWINDOW_PROPNAME_TOPWINDOW
,
969 TABWINDOW_PROPHANDLE_TOPWINDOW
,
970 ::getCppuType((const css::uno::Reference
< css::awt::XWindow
>*)NULL
),
971 com::sun::star::beans::PropertyAttribute::READONLY
)
972 }; // Use it to initialize sequence!
973 static const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
> lPropertyDescriptor( pProperties
, TABWINDOW_PROPCOUNT
);
975 // Return static "PropertyDescriptor"
976 return lPropertyDescriptor
;