merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / services / tabwindowservice.cxx
blob9af8581652d335455e1a00e45fe2acd812dda483
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 //_________________________________________________________________________________________________________________
32 // my own includes
33 //_________________________________________________________________________________________________________________
35 #include <services/tabwindowservice.hxx>
36 #include <classes/fwktabwindow.hxx>
37 #include <threadhelp/resetableguard.hxx>
38 #include <services.h>
39 #include <properties.h>
41 //_________________________________________________________________________________________________________________
42 // interface includes
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 //_________________________________________________________________________________________________________________
58 // namespace
59 //_________________________________________________________________________________________________________________
61 namespace framework{
63 //_________________________________________________________________________________________________________________
64 // non exported definitions
65 //_________________________________________________________________________________________________________________
67 //_________________________________________________________________________________________________________________
68 // declarations
69 //_________________________________________________________________________________________________________________
71 //*****************************************************************************************************************
72 // css::uno::XInterface, XTypeProvider, XServiceInfo
73 //*****************************************************************************************************************
75 DEFINE_XINTERFACE_6 ( TabWindowService ,
76 OWeakObject ,
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 ,
95 OWeakObject ,
96 SERVICENAME_TABWINDOWSERVICE ,
97 IMPLEMENTATIONNAME_TABWINDOWSERVICE
100 DEFINE_INIT_SERVICE ( TabWindowService,
102 impl_initializePropInfo();
103 m_aTransactionManager.setWorkingMode( E_WORK );
107 //*****************************************************************************************************************
108 // constructor
109 //*****************************************************************************************************************
110 TabWindowService::TabWindowService( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
111 // Init baseclasses first
112 // Attention:
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 ,
120 &m_aLock ,
121 &m_aTransactionManager ,
122 sal_False ) // FALSE => dont release shared mutex on calling us!
123 , OWeakObject ( )
125 // Init member
126 , m_xFactory ( xFactory )
127 , m_xTabWin ( )
128 , m_pTabWin ( NULL )
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 //*****************************************************************************************************************
140 // destructor
141 //*****************************************************************************************************************
142 TabWindowService::~TabWindowService()
144 // SAFE->
145 ResetableGuard aGuard(m_aLock);
147 if (m_pTabWin)
148 m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
151 //*****************************************************************************************************************
152 // XSimpleTabController
153 //*****************************************************************************************************************
154 ::sal_Int32 SAL_CALL TabWindowService::insertTab()
155 throw ( css::uno::RuntimeException )
157 // SAFE ->
158 ResetableGuard aGuard( m_aLock );
160 ::sal_Int32 nID = m_nPageIndexCounter++;
161 TTabPageInfo aInfo(nID);
163 m_lTabPageInfos[nID] = aInfo;
165 return nID;
168 //*****************************************************************************************************************
169 // XSimpleTabController
170 //*****************************************************************************************************************
171 void SAL_CALL TabWindowService::removeTab(::sal_Int32 nID)
172 throw (css::lang::IndexOutOfBoundsException,
173 css::uno::RuntimeException )
175 // SAFE ->
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 ();
183 if (pTabWin)
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 )
195 // SAFE ->
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 ();
206 if (pTabWin)
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 )
221 // SAFE ->
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 )
238 // SAFE ->
239 ResetableGuard aGuard(m_aLock);
241 // throws suitable IndexOutOfBoundsException .-)
242 impl_checkTabIndex (nID);
243 m_nCurrentPageIndex = nID;
245 FwkTabWindow* pTabWin = mem_TabWin ();
246 if (pTabWin)
247 pTabWin->ActivatePage(nID);
250 //*****************************************************************************************************************
251 // XSimpleTabController
252 //*****************************************************************************************************************
253 ::sal_Int32 SAL_CALL TabWindowService::getActiveTabID()
254 throw (css::uno::RuntimeException)
256 // SAFE->
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 //*****************************************************************************************************************
280 // XComponent
281 //*****************************************************************************************************************
282 void SAL_CALL TabWindowService::dispose()
283 throw (css::uno::RuntimeException)
285 // SAFE->
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);
293 if (m_pTabWin)
294 m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
296 m_pTabWin = NULL;
297 m_xTabWin.clear();
300 //*****************************************************************************************************************
301 // XComponent
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 //*****************************************************************************************************************
310 // XComponent
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*/,
341 sal_Int32 nHandle )
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;
349 switch (nHandle)
351 case TABWINDOWSERVICE_PROPHANDLE_WINDOW:
353 mem_TabWin (); // force "creation on demand" of m_xTabWin :-)
354 aValue <<= m_xTabWin;
356 break;
359 return aValue;
362 //*****************************************************************************************************************
363 // TabWindowService
364 //*****************************************************************************************************************
365 IMPL_LINK( TabWindowService, EventListener, VclSimpleEvent*, pEvent )
368 if ( !pEvent && !pEvent->ISA(VclWindowEvent))
369 return 0;
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 ) );
382 m_pTabWin = NULL;
383 m_xTabWin.clear();
385 return 0;
388 ::cppu::OInterfaceContainerHelper* pContainer = m_lListener.getContainer(::getCppuType((const css::uno::Reference< css::awt::XTabListener >*) NULL));
389 if ( ! pContainer)
390 return 0;
392 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
393 while (pIterator.hasMoreElements())
397 css::awt::XTabListener* pListener = (css::awt::XTabListener*)pIterator.next();
399 switch (nEventId)
401 case VCLEVENT_TABPAGE_ACTIVATE :
402 pListener->activated( (sal_Int32)(ULONG)pWinEvt->GetData() );
403 break;
405 case VCLEVENT_TABPAGE_DEACTIVATE :
406 pListener->deactivated( (sal_Int32)(ULONG)pWinEvt->GetData() );
407 break;
409 case VCLEVENT_TABPAGE_INSERTED :
410 pListener->inserted( (sal_Int32)(ULONG)pWinEvt->GetData() );
411 break;
413 case VCLEVENT_TABPAGE_REMOVED :
414 pListener->removed( (sal_Int32)(ULONG)pWinEvt->GetData() );
415 break;
417 case VCLEVENT_TABPAGE_PAGETEXTCHANGED :
418 case VCLEVENT_TABPAGE_REMOVEDALL :
419 break;
422 catch(const css::uno::RuntimeException&)
424 pIterator.remove();
428 return 0;
431 //*****************************************************************************************************************
432 // TabWindowService
433 //*****************************************************************************************************************
434 void TabWindowService::impl_checkTabIndex (::sal_Int32 nID)
435 throw (css::lang::IndexOutOfBoundsException)
437 if (
438 (nID <= 0 ) ||
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 //*****************************************************************************************************************
449 // TabWindowService
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 ));
459 return pIt;
462 //*****************************************************************************************************************
463 // TabWindowService
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 ) );
479 if (m_xTabWin.is ())
480 pWin = m_pTabWin;
482 return pWin;
485 } // namespace framework