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