1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
39 using namespace com::sun::star
;
44 // XInterface, XTypeProvider, XServiceInfo
46 DEFINE_XINTERFACE_11 ( TabWindow
,
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
,
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 )
89 , m_aTitlePropName( "Title" )
90 , m_aPosPropName( "Position" )
91 , m_xContext( xContext
)
92 , m_aListenerContainer( m_aMutex
)
96 TabWindow::~TabWindow()
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
);
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
);
145 return static_cast<TabControl
*>(pWindow
);
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
));
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())
175 case NOTIFY_INSERTED
:
176 static_cast<css::awt::XTabListener
*>(pIterator
.next())->inserted( ID
);
179 static_cast<css::awt::XTabListener
*>(pIterator
.next())->removed( ID
);
181 case NOTIFY_ACTIVATED
:
182 static_cast<css::awt::XTabListener
*>(pIterator
.next())->activated( ID
);
184 case NOTIFY_DEACTIVATED
:
185 static_cast<css::awt::XTabListener
*>(pIterator
.next())->deactivated( ID
);
191 catch( const css::uno::RuntimeException
& )
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())
213 static_cast<css::awt::XTabListener
*>(pIterator
.next())->changed( ID
, rSeq
);
219 catch( const css::uno::RuntimeException
& )
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
);
239 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
241 implts_SendNotification( NOTIFY_ACTIVATED
, nPageId
);
246 IMPL_LINK_TYPED( TabWindow
, Deactivate
, TabControl
*, pTabControl
, bool )
248 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
249 SolarMutexClearableGuard aLock
;
250 sal_Int32 nPageId
= pTabControl
->GetCurPageId();
252 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
254 implts_SendNotification( NOTIFY_DEACTIVATED
, nPageId
);
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
);
275 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
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
;
288 xToolkit
= css::awt::Toolkit::create( xContext
);
290 catch ( const css::uno::RuntimeException
& )
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
;
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
& )
335 catch ( const css::uno::Exception
& )
340 if ( xTopWindow
.is() )
342 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
344 m_bInitialized
= true;
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 ----------------------------------------------------------------------------------------------- */
381 m_xTopWindow
= xTopWindow
;
382 m_xContainerWindow
= xContainerWindow
;
383 m_xTabControlWindow
= xTabControl
;
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
);
392 pWindow
->Show( true );
394 pWindow
= VCLUnoHelper::GetWindow( xContainerWindow
);
396 pWindow
->Show( true, SHOW_NOFOCUSCHANGE
| SHOW_NOACTIVATE
);
398 pWindow
= VCLUnoHelper::GetWindow( xTabControl
);
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();
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();
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 ----------------------------------------------------------------------------------------------- */
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
;
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
;
476 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
478 m_aListenerContainer
.removeInterface( cppu::UnoType
<css::lang::XEventListener
>::get(), xListener
);
483 void SAL_CALL
TabWindow::disposing( const css::lang::EventObject
& )
484 throw( css::uno::RuntimeException
, std::exception
)
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
)
506 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
510 if ( m_xContainerWindow
.is() )
512 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( m_xContainerWindow
);
518 void SAL_CALL
TabWindow::windowHidden( const css::lang::EventObject
& )
519 throw( css::uno::RuntimeException
, std::exception
)
522 if ( m_xContainerWindow
.is() )
524 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( m_xContainerWindow
);
529 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
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
;
583 throw css::lang::DisposedException();
585 sal_Int32
nNextTabID( m_nNextTabID
++ );
588 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
590 pTabControl
->InsertPage( sal_uInt16( nNextTabID
), aTitle
);
592 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
594 implts_SendNotification( NOTIFY_INSERTED
, 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
;
606 throw css::lang::DisposedException();
608 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
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();
617 pTabControl
->RemovePage( sal_uInt16( ID
));
618 nCurTabId
= pTabControl
->GetCurPageId();
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
;
639 throw css::lang::DisposedException();
641 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
644 sal_uInt16 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
645 if ( nPos
== TAB_PAGE_NOTFOUND
)
646 throw css::lang::IndexOutOfBoundsException();
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() )
665 pTabControl
->RemovePage( sal_uInt16( ID
));
666 pTabControl
->InsertPage( sal_uInt16( ID
), aTitle
, nPos
);
669 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
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
)
684 throw css::lang::DisposedException();
686 css::uno::Sequence
< css::beans::NamedValue
> aNamedValueSeq
;
688 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
691 sal_uInt16 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
692 if ( nPos
== TAB_PAGE_NOTFOUND
)
693 throw css::lang::IndexOutOfBoundsException();
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
));
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
;
718 throw css::lang::DisposedException();
720 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
723 sal_uInt16 nPos
= pTabControl
->GetPagePos( sal_uInt16( ID
));
724 if ( nPos
== TAB_PAGE_NOTFOUND
)
725 throw css::lang::IndexOutOfBoundsException();
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
);
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
)
750 throw css::lang::DisposedException();
752 TabControl
* pTabControl
= impl_GetTabControl( m_xTabControlWindow
);
755 sal_uInt16 nID
= pTabControl
->GetCurPageId();
756 if ( nID
== TAB_PAGE_NOTFOUND
)
759 return sal_Int32( nID
);
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
;
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
;
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
,
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;
809 case TABWINDOW_PROPHANDLE_PARENTWINDOW
:
810 bReturn
= PropHelper::willPropertyBeChanged(
811 com::sun::star::uno::makeAny( m_xContainerWindow
),
817 case TABWINDOW_PROPHANDLE_TOPWINDOW
:
818 bReturn
= PropHelper::willPropertyBeChanged(
819 com::sun::star::uno::makeAny( m_xTopWindow
),
826 // Return state of operation.
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
841 case TABWINDOW_PROPHANDLE_PARENTWINDOW
:
842 aValue
<<= m_xContainerWindow
;
844 case TABWINDOW_PROPHANDLE_TOPWINDOW
:
845 aValue
<<= m_xTopWindow
;
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
;
886 // Ready for multithreading
887 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() );
888 // Control this pointer again, another instance can be faster then these!
891 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
892 // (Use method "getInfoHelper()".)
893 static css::uno::Reference
< css::beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
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.
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: */