1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 //_________________________________________________________________________________________________________________
33 //_________________________________________________________________________________________________________________
35 #include <services/tabwindowservice.hxx>
36 #include <classes/fwktabwindow.hxx>
37 #include <threadhelp/resetableguard.hxx>
39 #include <properties.h>
41 //_________________________________________________________________________________________________________________
43 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/awt/PosSize.hpp>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 //_________________________________________________________________________________________________________________
49 // includes of other projects
50 //_________________________________________________________________________________________________________________
52 #include <toolkit/helper/vclunohelper.hxx>
53 #include <tools/urlobj.hxx>
54 #include <rtl/ustrbuf.hxx>
55 #include <vcl/svapp.hxx>
57 //_________________________________________________________________________________________________________________
59 //_________________________________________________________________________________________________________________
63 //_________________________________________________________________________________________________________________
64 // non exported definitions
65 //_________________________________________________________________________________________________________________
67 //_________________________________________________________________________________________________________________
69 //_________________________________________________________________________________________________________________
71 //*****************************************************************************************************************
72 // css::uno::XInterface, XTypeProvider, XServiceInfo
73 //*****************************************************************************************************************
75 DEFINE_XINTERFACE_6 ( TabWindowService
,
77 DIRECT_INTERFACE(css::lang::XTypeProvider
),
78 DIRECT_INTERFACE(css::lang::XServiceInfo
),
79 DIRECT_INTERFACE(css::lang::XComponent
),
80 DIRECT_INTERFACE(css::awt::XSimpleTabController
),
81 DIRECT_INTERFACE(css::beans::XPropertySet
),
82 DIRECT_INTERFACE(css::beans::XPropertySetInfo
)
85 DEFINE_XTYPEPROVIDER_6 ( TabWindowService
,
86 css::lang::XTypeProvider
,
87 css::lang::XServiceInfo
,
88 css::lang::XComponent
,
89 css::awt::XSimpleTabController
,
90 css::beans::XPropertySet
,
91 css::beans::XPropertySetInfo
94 DEFINE_XSERVICEINFO_MULTISERVICE ( TabWindowService
,
96 SERVICENAME_TABWINDOWSERVICE
,
97 IMPLEMENTATIONNAME_TABWINDOWSERVICE
100 DEFINE_INIT_SERVICE ( TabWindowService
,
102 impl_initializePropInfo();
103 m_aTransactionManager
.setWorkingMode( E_WORK
);
107 //*****************************************************************************************************************
109 //*****************************************************************************************************************
110 TabWindowService::TabWindowService( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
)
111 // Init baseclasses first
113 // Don't change order of initialization!
114 // ThreadHelpBase is a struct with a mutex as member. We can't use a mutex as member, while
115 // we must garant right initialization and a valid value of this! First initialize
116 // baseclasses and then members. And we need the mutex for other baseclasses !!!
117 : ThreadHelpBase ( &Application::GetSolarMutex() )
118 , TransactionBase ( )
119 , PropertySetHelper ( xFactory
,
121 &m_aTransactionManager
,
122 sal_False
) // FALSE => dont release shared mutex on calling us!
126 , m_xFactory ( xFactory
)
129 , m_lTabPageInfos ( )
130 , m_lListener ( m_aLock
.getShareableOslMutex())
131 , m_nPageIndexCounter ( 1 )
132 , m_nCurrentPageIndex ( 0 )
134 // Safe impossible cases.
135 // Method not defined for all incoming parameter.
136 LOG_ASSERT( xFactory
.is(), "TabWindowService::TabWindowService()\nInvalid parameter detected!\n" )
139 //*****************************************************************************************************************
141 //*****************************************************************************************************************
142 TabWindowService::~TabWindowService()
145 ResetableGuard
aGuard(m_aLock
);
148 m_pTabWin
->RemoveEventListener( LINK( this, TabWindowService
, EventListener
) );
151 //*****************************************************************************************************************
152 // XSimpleTabController
153 //*****************************************************************************************************************
154 ::sal_Int32 SAL_CALL
TabWindowService::insertTab()
155 throw ( css::uno::RuntimeException
)
158 ResetableGuard
aGuard( m_aLock
);
160 ::sal_Int32 nID
= m_nPageIndexCounter
++;
161 TTabPageInfo
aInfo(nID
);
163 m_lTabPageInfos
[nID
] = aInfo
;
168 //*****************************************************************************************************************
169 // XSimpleTabController
170 //*****************************************************************************************************************
171 void SAL_CALL
TabWindowService::removeTab(::sal_Int32 nID
)
172 throw (css::lang::IndexOutOfBoundsException
,
173 css::uno::RuntimeException
)
176 ResetableGuard
aGuard(m_aLock
);
178 // throws suitable IndexOutOfBoundsException .-)
179 TTabPageInfoHash::iterator pIt
= impl_getTabPageInfo (nID
);
180 m_lTabPageInfos
.erase(pIt
);
182 FwkTabWindow
* pTabWin
= mem_TabWin ();
184 pTabWin
->RemovePage(nID
);
187 //*****************************************************************************************************************
188 // XSimpleTabController
189 //*****************************************************************************************************************
190 void SAL_CALL
TabWindowService::setTabProps( ::sal_Int32 nID
,
191 const css::uno::Sequence
< css::beans::NamedValue
>& lProperties
)
192 throw (css::lang::IndexOutOfBoundsException
,
193 css::uno::RuntimeException
)
196 ResetableGuard
aGuard(m_aLock
);
198 // throws suitable IndexOutOfBoundsException .-)
199 TTabPageInfoHash::iterator pIt
= impl_getTabPageInfo (nID
);
200 TTabPageInfo
& rInfo
= pIt
->second
;
201 rInfo
.m_lProperties
= lProperties
;
203 if ( ! rInfo
.m_bCreated
)
205 FwkTabWindow
* pTabWin
= mem_TabWin ();
208 pTabWin
->AddTabPage(rInfo
.m_nIndex
, rInfo
.m_lProperties
);
209 rInfo
.m_bCreated
= sal_True
;
214 //*****************************************************************************************************************
215 // XSimpleTabController
216 //*****************************************************************************************************************
217 css::uno::Sequence
< css::beans::NamedValue
> SAL_CALL
TabWindowService::getTabProps(::sal_Int32 nID
)
218 throw (css::lang::IndexOutOfBoundsException
,
219 css::uno::RuntimeException
)
222 ResetableGuard
aGuard(m_aLock
);
224 // throws suitable IndexOutOfBoundsException .-)
225 TTabPageInfoHash::const_iterator pIt
= impl_getTabPageInfo (nID
);
226 const TTabPageInfo
& rInfo
= pIt
->second
;
228 return rInfo
.m_lProperties
;
231 //*****************************************************************************************************************
232 // XSimpleTabController
233 //*****************************************************************************************************************
234 void SAL_CALL
TabWindowService::activateTab(::sal_Int32 nID
)
235 throw (css::lang::IndexOutOfBoundsException
,
236 css::uno::RuntimeException
)
239 ResetableGuard
aGuard(m_aLock
);
241 // throws suitable IndexOutOfBoundsException .-)
242 impl_checkTabIndex (nID
);
243 m_nCurrentPageIndex
= nID
;
245 FwkTabWindow
* pTabWin
= mem_TabWin ();
247 pTabWin
->ActivatePage(nID
);
250 //*****************************************************************************************************************
251 // XSimpleTabController
252 //*****************************************************************************************************************
253 ::sal_Int32 SAL_CALL
TabWindowService::getActiveTabID()
254 throw (css::uno::RuntimeException
)
257 ResetableGuard
aGuard( m_aLock
);
258 return m_nCurrentPageIndex
;
261 //*****************************************************************************************************************
262 // XSimpleTabController
263 //*****************************************************************************************************************
264 void SAL_CALL
TabWindowService::addTabListener(const css::uno::Reference
< css::awt::XTabListener
>& xListener
)
265 throw (css::uno::RuntimeException
)
267 m_lListener
.addInterface(::getCppuType((const css::uno::Reference
< css::awt::XTabListener
>*)NULL
), xListener
);
270 //*****************************************************************************************************************
271 // XSimpleTabController
272 //*****************************************************************************************************************
273 void SAL_CALL
TabWindowService::removeTabListener(const css::uno::Reference
< css::awt::XTabListener
>& xListener
)
274 throw (css::uno::RuntimeException
)
276 m_lListener
.removeInterface(::getCppuType((const css::uno::Reference
< css::awt::XTabListener
>*)NULL
), xListener
);
279 //*****************************************************************************************************************
281 //*****************************************************************************************************************
282 void SAL_CALL
TabWindowService::dispose()
283 throw (css::uno::RuntimeException
)
286 ResetableGuard
aGuard(m_aLock
);
288 css::uno::Reference
< css::uno::XInterface
> xThis(static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
);
289 css::lang::EventObject
aEvent(xThis
);
291 m_lListener
.disposeAndClear (aEvent
);
294 m_pTabWin
->RemoveEventListener( LINK( this, TabWindowService
, EventListener
) );
300 //*****************************************************************************************************************
302 //*****************************************************************************************************************
303 void SAL_CALL
TabWindowService::addEventListener(const css::uno::Reference
< css::lang::XEventListener
>& xListener
)
304 throw (css::uno::RuntimeException
)
306 m_lListener
.addInterface(::getCppuType((const css::uno::Reference
< css::lang::XEventListener
>*)NULL
), xListener
);
309 //*****************************************************************************************************************
311 //*****************************************************************************************************************
312 void SAL_CALL
TabWindowService::removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
)
313 throw (css::uno::RuntimeException
)
315 m_lListener
.removeInterface(::getCppuType((const css::uno::Reference
< css::lang::XEventListener
>*)NULL
), xListener
);
318 //*****************************************************************************************************************
319 void TabWindowService::impl_initializePropInfo()
321 impl_setPropertyChangeBroadcaster(static_cast< css::awt::XSimpleTabController
* >(this));
323 impl_addPropertyInfo(
324 css::beans::Property(
325 TABWINDOWSERVICE_PROPNAME_WINDOW
,
326 TABWINDOWSERVICE_PROPHANDLE_WINDOW
,
327 ::getCppuType((const css::uno::Reference
< css::awt::XWindow
>*)NULL
),
328 css::beans::PropertyAttribute::TRANSIENT
));
331 //*****************************************************************************************************************
332 void SAL_CALL
TabWindowService::impl_setPropertyValue(const ::rtl::OUString
& /*sProperty*/,
333 sal_Int32
/*nHandle */,
334 const css::uno::Any
& /*aValue */)
339 //*****************************************************************************************************************
340 css::uno::Any SAL_CALL
TabWindowService::impl_getPropertyValue(const ::rtl::OUString
& /*sProperty*/,
343 /* There is no need to lock any mutex here. Because we share the
344 solar mutex with our base class. And we said to our base class: "dont release it on calling us" .-)
345 see ctor of PropertySetHelper for further informations.
347 css::uno::Any aValue
;
351 case TABWINDOWSERVICE_PROPHANDLE_WINDOW
:
353 mem_TabWin (); // force "creation on demand" of m_xTabWin :-)
354 aValue
<<= m_xTabWin
;
362 //*****************************************************************************************************************
364 //*****************************************************************************************************************
365 IMPL_LINK( TabWindowService
, EventListener
, VclSimpleEvent
*, pEvent
)
368 if ( !pEvent
&& !pEvent
->ISA(VclWindowEvent
))
371 ULONG nEventId
= pEvent
->GetId();
372 VclWindowEvent
* pWinEvt
= static_cast< VclWindowEvent
* >(pEvent
);
374 css::uno::Reference
< css::uno::XInterface
> xThis ( static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
);
375 css::lang::EventObject
aEvent( xThis
);
377 if (nEventId
== VCLEVENT_OBJECT_DYING
)
379 m_lListener
.disposeAndClear (aEvent
);
381 m_pTabWin
->RemoveEventListener( LINK( this, TabWindowService
, EventListener
) );
388 ::cppu::OInterfaceContainerHelper
* pContainer
= m_lListener
.getContainer(::getCppuType((const css::uno::Reference
< css::awt::XTabListener
>*) NULL
));
392 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
393 while (pIterator
.hasMoreElements())
397 css::awt::XTabListener
* pListener
= (css::awt::XTabListener
*)pIterator
.next();
401 case VCLEVENT_TABPAGE_ACTIVATE
:
402 pListener
->activated( (sal_Int32
)(ULONG
)pWinEvt
->GetData() );
405 case VCLEVENT_TABPAGE_DEACTIVATE
:
406 pListener
->deactivated( (sal_Int32
)(ULONG
)pWinEvt
->GetData() );
409 case VCLEVENT_TABPAGE_INSERTED
:
410 pListener
->inserted( (sal_Int32
)(ULONG
)pWinEvt
->GetData() );
413 case VCLEVENT_TABPAGE_REMOVED
:
414 pListener
->removed( (sal_Int32
)(ULONG
)pWinEvt
->GetData() );
417 case VCLEVENT_TABPAGE_PAGETEXTCHANGED
:
418 case VCLEVENT_TABPAGE_REMOVEDALL
:
422 catch(const css::uno::RuntimeException
&)
431 //*****************************************************************************************************************
433 //*****************************************************************************************************************
434 void TabWindowService::impl_checkTabIndex (::sal_Int32 nID
)
435 throw (css::lang::IndexOutOfBoundsException
)
439 (nID
> m_nPageIndexCounter
)
442 throw css::lang::IndexOutOfBoundsException(
443 ::rtl::OUString::createFromAscii("Tab index out of bounds."),
444 css::uno::Reference
< css::uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
));
448 //*****************************************************************************************************************
450 //*****************************************************************************************************************
451 TTabPageInfoHash::iterator
TabWindowService::impl_getTabPageInfo(::sal_Int32 nID
)
452 throw (css::lang::IndexOutOfBoundsException
)
454 TTabPageInfoHash::iterator pIt
= m_lTabPageInfos
.find(nID
);
455 if (pIt
== m_lTabPageInfos
.end ())
456 throw css::lang::IndexOutOfBoundsException(
457 ::rtl::OUString::createFromAscii("Tab index out of bounds."),
458 css::uno::Reference
< css::uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this), css::uno::UNO_QUERY
));
462 //*****************************************************************************************************************
464 //*****************************************************************************************************************
465 FwkTabWindow
* TabWindowService::mem_TabWin ()
467 FwkTabWindow
* pWin
= NULL
;
469 if ( ! m_xTabWin
.is ())
471 Window
* pFakeParent
= dynamic_cast< Window
* >(Application::GetDefaultDevice ());
473 m_pTabWin
= new FwkTabWindow (pFakeParent
);
474 m_xTabWin
= VCLUnoHelper::GetInterface (m_pTabWin
);
476 m_pTabWin
->AddEventListener( LINK( this, TabWindowService
, EventListener
) );
485 } // namespace framework