merge the formfield patch from ooo-build
[ooovba.git] / framework / source / services / tabwindowservice.cxx
blob6c78600aa91b31c25740b9d8adede0a0f422a00e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: urltransformer.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
38 #include <services/tabwindowservice.hxx>
39 #include <classes/fwktabwindow.hxx>
40 #include <threadhelp/resetableguard.hxx>
41 #include <services.h>
42 #include <properties.h>
44 //_________________________________________________________________________________________________________________
45 // interface includes
46 //_________________________________________________________________________________________________________________
48 #include <com/sun/star/awt/PosSize.hpp>
49 #include <com/sun/star/beans/PropertyAttribute.hpp>
51 //_________________________________________________________________________________________________________________
52 // includes of other projects
53 //_________________________________________________________________________________________________________________
55 #include <toolkit/helper/vclunohelper.hxx>
56 #include <tools/urlobj.hxx>
57 #include <rtl/ustrbuf.hxx>
58 #include <vcl/svapp.hxx>
60 //_________________________________________________________________________________________________________________
61 // namespace
62 //_________________________________________________________________________________________________________________
64 namespace framework{
66 //_________________________________________________________________________________________________________________
67 // non exported definitions
68 //_________________________________________________________________________________________________________________
70 //_________________________________________________________________________________________________________________
71 // declarations
72 //_________________________________________________________________________________________________________________
74 //*****************************************************************************************************************
75 // css::uno::XInterface, XTypeProvider, XServiceInfo
76 //*****************************************************************************************************************
78 DEFINE_XINTERFACE_5 ( TabWindowService ,
79 OWeakObject ,
80 DIRECT_INTERFACE(css::lang::XTypeProvider ),
81 DIRECT_INTERFACE(css::lang::XServiceInfo ),
82 DIRECT_INTERFACE(css::awt::XSimpleTabController),
83 DIRECT_INTERFACE(css::beans::XPropertySet ),
84 DIRECT_INTERFACE(css::beans::XPropertySetInfo )
87 DEFINE_XTYPEPROVIDER_5 ( TabWindowService ,
88 css::lang::XTypeProvider ,
89 css::lang::XServiceInfo ,
90 css::awt::XSimpleTabController ,
91 css::beans::XPropertySet ,
92 css::beans::XPropertySetInfo
95 DEFINE_XSERVICEINFO_MULTISERVICE ( TabWindowService ,
96 OWeakObject ,
97 SERVICENAME_TABWINDOWSERVICE ,
98 IMPLEMENTATIONNAME_TABWINDOWSERVICE
101 DEFINE_INIT_SERVICE ( TabWindowService,
103 impl_initializePropInfo();
104 m_aTransactionManager.setWorkingMode( E_WORK );
108 //*****************************************************************************************************************
109 // constructor
110 //*****************************************************************************************************************
111 TabWindowService::TabWindowService( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
112 // Init baseclasses first
113 // Attention:
114 // Don't change order of initialization!
115 // ThreadHelpBase is a struct with a mutex as member. We can't use a mutex as member, while
116 // we must garant right initialization and a valid value of this! First initialize
117 // baseclasses and then members. And we need the mutex for other baseclasses !!!
118 : ThreadHelpBase ( &Application::GetSolarMutex() )
119 , TransactionBase ( )
120 , PropertySetHelper ( xFactory ,
121 &m_aLock ,
122 &m_aTransactionManager ,
123 sal_False ) // FALSE => dont release shared mutex on calling us!
124 , OWeakObject ( )
126 // Init member
127 , m_xFactory ( xFactory )
128 , m_xTabWin ( )
129 , m_pTabWin ( NULL )
130 , m_lTabPageInfos ( )
131 , m_lListener ( m_aLock.getShareableOslMutex())
132 , m_nPageIndexCounter ( 1 )
133 , m_nCurrentPageIndex ( 0 )
135 // Safe impossible cases.
136 // Method not defined for all incoming parameter.
137 LOG_ASSERT( xFactory.is(), "TabWindowService::TabWindowService()\nInvalid parameter detected!\n" )
140 //*****************************************************************************************************************
141 // destructor
142 //*****************************************************************************************************************
143 TabWindowService::~TabWindowService()
147 //*****************************************************************************************************************
148 // XSimpleTabController
149 //*****************************************************************************************************************
150 ::sal_Int32 SAL_CALL TabWindowService::insertTab()
151 throw ( css::uno::RuntimeException )
153 // SAFE ->
154 ResetableGuard aGuard( m_aLock );
156 ::sal_Int32 nID = m_nPageIndexCounter++;
157 TTabPageInfo aInfo(nID);
159 m_lTabPageInfos[nID] = aInfo;
161 return nID;
164 //*****************************************************************************************************************
165 // XSimpleTabController
166 //*****************************************************************************************************************
167 void SAL_CALL TabWindowService::removeTab(::sal_Int32 nID)
168 throw (css::lang::IndexOutOfBoundsException,
169 css::uno::RuntimeException )
171 // SAFE ->
172 ResetableGuard aGuard(m_aLock);
174 // throws suitable IndexOutOfBoundsException .-)
175 TTabPageInfoHash::iterator pIt = impl_getTabPageInfo (nID);
176 m_lTabPageInfos.erase(pIt);
178 FwkTabWindow* pTabWin = mem_TabWin ();
179 if (pTabWin)
180 pTabWin->RemovePage(nID);
183 //*****************************************************************************************************************
184 // XSimpleTabController
185 //*****************************************************************************************************************
186 void SAL_CALL TabWindowService::setTabProps( ::sal_Int32 nID ,
187 const css::uno::Sequence< css::beans::NamedValue >& lProperties)
188 throw (css::lang::IndexOutOfBoundsException,
189 css::uno::RuntimeException )
191 // SAFE ->
192 ResetableGuard aGuard(m_aLock);
194 // throws suitable IndexOutOfBoundsException .-)
195 TTabPageInfoHash::iterator pIt = impl_getTabPageInfo (nID);
196 TTabPageInfo& rInfo = pIt->second;
197 rInfo.m_lProperties = lProperties;
199 if ( ! rInfo.m_bCreated)
201 FwkTabWindow* pTabWin = mem_TabWin ();
202 if (pTabWin)
204 pTabWin->AddTabPage(rInfo.m_nIndex, rInfo.m_lProperties);
205 rInfo.m_bCreated = sal_True;
210 //*****************************************************************************************************************
211 // XSimpleTabController
212 //*****************************************************************************************************************
213 css::uno::Sequence< css::beans::NamedValue > SAL_CALL TabWindowService::getTabProps(::sal_Int32 nID)
214 throw (css::lang::IndexOutOfBoundsException,
215 css::uno::RuntimeException )
217 // SAFE ->
218 ResetableGuard aGuard(m_aLock);
220 // throws suitable IndexOutOfBoundsException .-)
221 TTabPageInfoHash::const_iterator pIt = impl_getTabPageInfo (nID);
222 const TTabPageInfo& rInfo = pIt->second;
224 return rInfo.m_lProperties;
227 //*****************************************************************************************************************
228 // XSimpleTabController
229 //*****************************************************************************************************************
230 void SAL_CALL TabWindowService::activateTab(::sal_Int32 nID)
231 throw (css::lang::IndexOutOfBoundsException,
232 css::uno::RuntimeException )
234 // SAFE ->
235 ResetableGuard aGuard(m_aLock);
237 // throws suitable IndexOutOfBoundsException .-)
238 impl_checkTabIndex (nID);
239 m_nCurrentPageIndex = nID;
241 FwkTabWindow* pTabWin = mem_TabWin ();
242 if (pTabWin)
243 pTabWin->ActivatePage(nID);
246 //*****************************************************************************************************************
247 // XSimpleTabController
248 //*****************************************************************************************************************
249 ::sal_Int32 SAL_CALL TabWindowService::getActiveTabID()
250 throw (css::uno::RuntimeException)
252 // SAFE->
253 ResetableGuard aGuard( m_aLock );
254 return m_nCurrentPageIndex;
257 //*****************************************************************************************************************
258 // XSimpleTabController
259 //*****************************************************************************************************************
260 void SAL_CALL TabWindowService::addTabListener(const css::uno::Reference< css::awt::XTabListener >& xListener)
261 throw (css::uno::RuntimeException)
263 m_lListener.addInterface(::getCppuType((const css::uno::Reference< css::awt::XTabListener >*)NULL), xListener);
266 //*****************************************************************************************************************
267 // XSimpleTabController
268 //*****************************************************************************************************************
269 void SAL_CALL TabWindowService::removeTabListener(const css::uno::Reference< css::awt::XTabListener >& xListener)
270 throw (css::uno::RuntimeException)
272 m_lListener.removeInterface(::getCppuType((const css::uno::Reference< css::awt::XTabListener >*)NULL), xListener);
275 //*****************************************************************************************************************
276 // XComponent
277 //*****************************************************************************************************************
278 void SAL_CALL TabWindowService::dispose()
279 throw (css::uno::RuntimeException)
281 // SAFE->
282 ResetableGuard aGuard(m_aLock);
284 css::uno::Reference< css::uno::XInterface > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
285 css::lang::EventObject aEvent(xThis);
287 m_lListener.disposeAndClear (aEvent);
289 m_pTabWin = NULL;
290 m_xTabWin.clear ();
293 //*****************************************************************************************************************
294 // XComponent
295 //*****************************************************************************************************************
296 void SAL_CALL TabWindowService::addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener)
297 throw (css::uno::RuntimeException)
299 m_lListener.addInterface(::getCppuType((const css::uno::Reference< css::lang::XEventListener >*)NULL), xListener);
302 //*****************************************************************************************************************
303 // XComponent
304 //*****************************************************************************************************************
305 void SAL_CALL TabWindowService::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener)
306 throw (css::uno::RuntimeException)
308 m_lListener.removeInterface(::getCppuType((const css::uno::Reference< css::lang::XEventListener >*)NULL), xListener);
311 //*****************************************************************************************************************
312 void TabWindowService::impl_initializePropInfo()
314 impl_setPropertyChangeBroadcaster(static_cast< css::awt::XSimpleTabController* >(this));
316 impl_addPropertyInfo(
317 css::beans::Property(
318 TABWINDOWSERVICE_PROPNAME_WINDOW,
319 TABWINDOWSERVICE_PROPHANDLE_WINDOW,
320 ::getCppuType((const css::uno::Reference< css::awt::XWindow >*)NULL),
321 css::beans::PropertyAttribute::TRANSIENT));
324 //*****************************************************************************************************************
325 void SAL_CALL TabWindowService::impl_setPropertyValue(const ::rtl::OUString& /*sProperty*/,
326 sal_Int32 /*nHandle */,
327 const css::uno::Any& /*aValue */)
332 //*****************************************************************************************************************
333 css::uno::Any SAL_CALL TabWindowService::impl_getPropertyValue(const ::rtl::OUString& /*sProperty*/,
334 sal_Int32 nHandle )
336 /* There is no need to lock any mutex here. Because we share the
337 solar mutex with our base class. And we said to our base class: "dont release it on calling us" .-)
338 see ctor of PropertySetHelper for further informations.
340 css::uno::Any aValue;
342 switch (nHandle)
344 case TABWINDOWSERVICE_PROPHANDLE_WINDOW:
346 mem_TabWin (); // force "creation on demand" of m_xTabWin :-)
347 aValue <<= m_xTabWin;
349 break;
352 return aValue;
355 //*****************************************************************************************************************
356 // TabWindowService
357 //*****************************************************************************************************************
358 IMPL_LINK( TabWindowService, EventListener, VclSimpleEvent*, pEvent )
360 if ( !pEvent && !pEvent->ISA(VclWindowEvent))
361 return 0;
363 ULONG nEventId = pEvent->GetId();
364 VclWindowEvent* pWinEvt = static_cast< VclWindowEvent* >(pEvent);
366 css::uno::Reference< css::uno::XInterface > xThis ( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
367 css::lang::EventObject aEvent( xThis );
369 if (nEventId == VCLEVENT_OBJECT_DYING)
371 m_lListener.disposeAndClear (aEvent);
372 return 0;
375 ::cppu::OInterfaceContainerHelper* pContainer = m_lListener.getContainer(::getCppuType((const css::uno::Reference< css::awt::XTabListener >*) NULL));
376 if ( ! pContainer)
377 return 0;
379 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
380 while (pIterator.hasMoreElements())
384 css::awt::XTabListener* pListener = (css::awt::XTabListener*)pIterator.next();
386 switch (nEventId)
388 case VCLEVENT_TABPAGE_ACTIVATE :
389 pListener->activated( (sal_Int32)(ULONG)pWinEvt->GetData() );
390 break;
392 case VCLEVENT_TABPAGE_DEACTIVATE :
393 pListener->deactivated( (sal_Int32)(ULONG)pWinEvt->GetData() );
394 break;
396 case VCLEVENT_TABPAGE_INSERTED :
397 pListener->inserted( (sal_Int32)(ULONG)pWinEvt->GetData() );
398 break;
400 case VCLEVENT_TABPAGE_REMOVED :
401 pListener->removed( (sal_Int32)(ULONG)pWinEvt->GetData() );
402 break;
404 case VCLEVENT_TABPAGE_PAGETEXTCHANGED :
405 case VCLEVENT_TABPAGE_REMOVEDALL :
406 break;
409 catch(const css::uno::RuntimeException&)
411 pIterator.remove();
415 return 0;
418 //*****************************************************************************************************************
419 // TabWindowService
420 //*****************************************************************************************************************
421 void TabWindowService::impl_checkTabIndex (::sal_Int32 nID)
422 throw (css::lang::IndexOutOfBoundsException)
424 if (
425 (nID <= 0 ) ||
426 (nID > m_nPageIndexCounter)
429 throw css::lang::IndexOutOfBoundsException(
430 ::rtl::OUString::createFromAscii("Tab index out of bounds."),
431 css::uno::Reference< css::uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY ));
435 //*****************************************************************************************************************
436 // TabWindowService
437 //*****************************************************************************************************************
438 TTabPageInfoHash::iterator TabWindowService::impl_getTabPageInfo(::sal_Int32 nID)
439 throw (css::lang::IndexOutOfBoundsException)
441 TTabPageInfoHash::iterator pIt = m_lTabPageInfos.find(nID);
442 if (pIt == m_lTabPageInfos.end ())
443 throw css::lang::IndexOutOfBoundsException(
444 ::rtl::OUString::createFromAscii("Tab index out of bounds."),
445 css::uno::Reference< css::uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY ));
446 return pIt;
449 //*****************************************************************************************************************
450 // TabWindowService
451 //*****************************************************************************************************************
452 FwkTabWindow* TabWindowService::mem_TabWin ()
454 FwkTabWindow* pWin = NULL;
456 if ( ! m_xTabWin.is ())
458 Window* pFakeParent = dynamic_cast< Window* >(Application::GetDefaultDevice ());
460 m_pTabWin = new FwkTabWindow (pFakeParent);
461 m_xTabWin = VCLUnoHelper::GetInterface (m_pTabWin);
463 m_pTabWin->AddEventListener( LINK( this, TabWindowService, EventListener ) );
466 if (m_xTabWin.is ())
467 pWin = m_pTabWin;
469 return pWin;
472 } // namespace framework