Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <services/tabwindowservice.hxx>
30 : : #include <classes/fwktabwindow.hxx>
31 : : #include <threadhelp/resetableguard.hxx>
32 : : #include <services.h>
33 : : #include <properties.h>
34 : :
35 : : #include <com/sun/star/awt/PosSize.hpp>
36 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
37 : :
38 : : #include <toolkit/helper/vclunohelper.hxx>
39 : : #include <rtl/ustrbuf.hxx>
40 : : #include <vcl/svapp.hxx>
41 : :
42 : : namespace framework{
43 : :
44 : : //*****************************************************************************************************************
45 : : // css::uno::XInterface, XTypeProvider, XServiceInfo
46 : : //*****************************************************************************************************************
47 : :
48 [ # # ][ # # ]: 0 : DEFINE_XINTERFACE_6 ( TabWindowService ,
49 : : OWeakObject ,
50 : : DIRECT_INTERFACE(css::lang::XTypeProvider ),
51 : : DIRECT_INTERFACE(css::lang::XServiceInfo ),
52 : : DIRECT_INTERFACE(css::lang::XComponent),
53 : : DIRECT_INTERFACE(css::awt::XSimpleTabController),
54 : : DIRECT_INTERFACE(css::beans::XPropertySet ),
55 : : DIRECT_INTERFACE(css::beans::XPropertySetInfo )
56 : : )
57 : :
58 [ # # ][ # # ]: 0 : DEFINE_XTYPEPROVIDER_6 ( TabWindowService ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
59 : : css::lang::XTypeProvider ,
60 : : css::lang::XServiceInfo ,
61 : : css::lang::XComponent ,
62 : : css::awt::XSimpleTabController ,
63 : : css::beans::XPropertySet ,
64 : : css::beans::XPropertySetInfo
65 : : )
66 : :
67 [ # # ][ # # ]: 466 : DEFINE_XSERVICEINFO_MULTISERVICE ( TabWindowService ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
68 : : OWeakObject ,
69 : : SERVICENAME_TABWINDOWSERVICE ,
70 : : IMPLEMENTATIONNAME_TABWINDOWSERVICE
71 : : )
72 : :
73 : 0 : DEFINE_INIT_SERVICE ( TabWindowService,
74 : : {
75 : : impl_initializePropInfo();
76 : : m_aTransactionManager.setWorkingMode( E_WORK );
77 : : }
78 : : )
79 : :
80 : : //*****************************************************************************************************************
81 : : // constructor
82 : : //*****************************************************************************************************************
83 : 0 : TabWindowService::TabWindowService( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
84 : : // Init baseclasses first
85 : : // Attention:
86 : : // Don't change order of initialization!
87 : : // ThreadHelpBase is a struct with a mutex as member. We can't use a mutex as member, while
88 : : // we must garant right initialization and a valid value of this! First initialize
89 : : // baseclasses and then members. And we need the mutex for other baseclasses !!!
90 [ # # ]: 0 : : ThreadHelpBase ( &Application::GetSolarMutex() )
91 : : , TransactionBase ( )
92 : : , PropertySetHelper ( xFactory ,
93 : : &m_aLock ,
94 : : &m_aTransactionManager ,
95 : : sal_False ) // sal_False => dont release shared mutex on calling us!
96 : : , OWeakObject ( )
97 : :
98 : : // Init member
99 : : , m_xFactory ( xFactory )
100 : : , m_xTabWin ( )
101 : : , m_pTabWin ( NULL )
102 : : , m_lTabPageInfos ( )
103 [ # # ]: 0 : , m_lListener ( m_aLock.getShareableOslMutex())
104 : : , m_nPageIndexCounter ( 1 )
105 [ # # ][ # # ]: 0 : , m_nCurrentPageIndex ( 0 )
[ # # ][ # # ]
[ # # ]
106 : : {
107 : : // Safe impossible cases.
108 : : // Method not defined for all incoming parameter.
109 : : LOG_ASSERT( xFactory.is(), "TabWindowService::TabWindowService()\nInvalid parameter detected!\n" )
110 : 0 : }
111 : :
112 : : //*****************************************************************************************************************
113 : : // destructor
114 : : //*****************************************************************************************************************
115 [ # # ][ # # ]: 0 : TabWindowService::~TabWindowService()
[ # # ][ # # ]
[ # # ][ # # ]
116 : : {
117 : : // SAFE->
118 [ # # ]: 0 : ResetableGuard aGuard(m_aLock);
119 : :
120 [ # # ]: 0 : if (m_pTabWin)
121 [ # # ][ # # ]: 0 : m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
[ # # ]
122 [ # # ]: 0 : }
123 : :
124 : : //*****************************************************************************************************************
125 : : // XSimpleTabController
126 : : //*****************************************************************************************************************
127 : 0 : ::sal_Int32 SAL_CALL TabWindowService::insertTab()
128 : : throw ( css::uno::RuntimeException )
129 : : {
130 : : // SAFE ->
131 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
132 : :
133 : 0 : ::sal_Int32 nID = m_nPageIndexCounter++;
134 [ # # ]: 0 : TTabPageInfo aInfo(nID);
135 : :
136 [ # # ][ # # ]: 0 : m_lTabPageInfos[nID] = aInfo;
137 : :
138 [ # # ][ # # ]: 0 : return nID;
139 : : }
140 : :
141 : : //*****************************************************************************************************************
142 : : // XSimpleTabController
143 : : //*****************************************************************************************************************
144 : 0 : void SAL_CALL TabWindowService::removeTab(::sal_Int32 nID)
145 : : throw (css::lang::IndexOutOfBoundsException,
146 : : css::uno::RuntimeException )
147 : : {
148 : : // SAFE ->
149 [ # # ]: 0 : ResetableGuard aGuard(m_aLock);
150 : :
151 : : // throws suitable IndexOutOfBoundsException .-)
152 [ # # ]: 0 : TTabPageInfoHash::iterator pIt = impl_getTabPageInfo (nID);
153 [ # # ]: 0 : m_lTabPageInfos.erase(pIt);
154 : :
155 [ # # ]: 0 : FwkTabWindow* pTabWin = mem_TabWin ();
156 [ # # ]: 0 : if (pTabWin)
157 [ # # ][ # # ]: 0 : pTabWin->RemovePage(nID);
158 : 0 : }
159 : :
160 : : //*****************************************************************************************************************
161 : : // XSimpleTabController
162 : : //*****************************************************************************************************************
163 : 0 : void SAL_CALL TabWindowService::setTabProps( ::sal_Int32 nID ,
164 : : const css::uno::Sequence< css::beans::NamedValue >& lProperties)
165 : : throw (css::lang::IndexOutOfBoundsException,
166 : : css::uno::RuntimeException )
167 : : {
168 : : // SAFE ->
169 [ # # ]: 0 : ResetableGuard aGuard(m_aLock);
170 : :
171 : : // throws suitable IndexOutOfBoundsException .-)
172 [ # # ]: 0 : TTabPageInfoHash::iterator pIt = impl_getTabPageInfo (nID);
173 [ # # ]: 0 : TTabPageInfo& rInfo = pIt->second;
174 [ # # ]: 0 : rInfo.m_lProperties = lProperties;
175 : :
176 [ # # ]: 0 : if ( ! rInfo.m_bCreated)
177 : : {
178 [ # # ]: 0 : FwkTabWindow* pTabWin = mem_TabWin ();
179 [ # # ]: 0 : if (pTabWin)
180 : : {
181 [ # # ]: 0 : pTabWin->AddTabPage(rInfo.m_nIndex, rInfo.m_lProperties);
182 : 0 : rInfo.m_bCreated = sal_True;
183 : : }
184 [ # # ]: 0 : }
185 : 0 : }
186 : :
187 : : //*****************************************************************************************************************
188 : : // XSimpleTabController
189 : : //*****************************************************************************************************************
190 : 0 : css::uno::Sequence< css::beans::NamedValue > SAL_CALL TabWindowService::getTabProps(::sal_Int32 nID)
191 : : throw (css::lang::IndexOutOfBoundsException,
192 : : css::uno::RuntimeException )
193 : : {
194 : : // SAFE ->
195 [ # # ]: 0 : ResetableGuard aGuard(m_aLock);
196 : :
197 : : // throws suitable IndexOutOfBoundsException .-)
198 [ # # ]: 0 : TTabPageInfoHash::const_iterator pIt = impl_getTabPageInfo (nID);
199 [ # # ]: 0 : const TTabPageInfo& rInfo = pIt->second;
200 : :
201 [ # # ][ # # ]: 0 : return rInfo.m_lProperties;
202 : : }
203 : :
204 : : //*****************************************************************************************************************
205 : : // XSimpleTabController
206 : : //*****************************************************************************************************************
207 : 0 : void SAL_CALL TabWindowService::activateTab(::sal_Int32 nID)
208 : : throw (css::lang::IndexOutOfBoundsException,
209 : : css::uno::RuntimeException )
210 : : {
211 : : // SAFE ->
212 [ # # ]: 0 : ResetableGuard aGuard(m_aLock);
213 : :
214 : : // throws suitable IndexOutOfBoundsException .-)
215 [ # # ]: 0 : impl_checkTabIndex (nID);
216 : 0 : m_nCurrentPageIndex = nID;
217 : :
218 [ # # ]: 0 : FwkTabWindow* pTabWin = mem_TabWin ();
219 [ # # ]: 0 : if (pTabWin)
220 [ # # ][ # # ]: 0 : pTabWin->ActivatePage(nID);
221 : 0 : }
222 : :
223 : : //*****************************************************************************************************************
224 : : // XSimpleTabController
225 : : //*****************************************************************************************************************
226 : 0 : ::sal_Int32 SAL_CALL TabWindowService::getActiveTabID()
227 : : throw (css::uno::RuntimeException)
228 : : {
229 : : // SAFE->
230 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
231 [ # # ]: 0 : return m_nCurrentPageIndex;
232 : : }
233 : :
234 : : //*****************************************************************************************************************
235 : : // XSimpleTabController
236 : : //*****************************************************************************************************************
237 : 0 : void SAL_CALL TabWindowService::addTabListener(const css::uno::Reference< css::awt::XTabListener >& xListener)
238 : : throw (css::uno::RuntimeException)
239 : : {
240 : 0 : m_lListener.addInterface(::getCppuType((const css::uno::Reference< css::awt::XTabListener >*)NULL), xListener);
241 : 0 : }
242 : :
243 : : //*****************************************************************************************************************
244 : : // XSimpleTabController
245 : : //*****************************************************************************************************************
246 : 0 : void SAL_CALL TabWindowService::removeTabListener(const css::uno::Reference< css::awt::XTabListener >& xListener)
247 : : throw (css::uno::RuntimeException)
248 : : {
249 : 0 : m_lListener.removeInterface(::getCppuType((const css::uno::Reference< css::awt::XTabListener >*)NULL), xListener);
250 : 0 : }
251 : :
252 : : //*****************************************************************************************************************
253 : : // XComponent
254 : : //*****************************************************************************************************************
255 : 0 : void SAL_CALL TabWindowService::dispose()
256 : : throw (css::uno::RuntimeException)
257 : : {
258 : : // SAFE->
259 [ # # ]: 0 : ResetableGuard aGuard(m_aLock);
260 : :
261 [ # # ]: 0 : css::uno::Reference< css::uno::XInterface > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
262 [ # # ]: 0 : css::lang::EventObject aEvent(xThis);
263 : :
264 [ # # ]: 0 : m_lListener.disposeAndClear (aEvent);
265 : :
266 [ # # ]: 0 : if (m_pTabWin)
267 [ # # ][ # # ]: 0 : m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
268 : :
269 : 0 : m_pTabWin = NULL;
270 [ # # ][ # # ]: 0 : m_xTabWin.clear();
271 : 0 : }
272 : :
273 : : //*****************************************************************************************************************
274 : : // XComponent
275 : : //*****************************************************************************************************************
276 : 0 : void SAL_CALL TabWindowService::addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener)
277 : : throw (css::uno::RuntimeException)
278 : : {
279 : 0 : m_lListener.addInterface(::getCppuType((const css::uno::Reference< css::lang::XEventListener >*)NULL), xListener);
280 : 0 : }
281 : :
282 : : //*****************************************************************************************************************
283 : : // XComponent
284 : : //*****************************************************************************************************************
285 : 0 : void SAL_CALL TabWindowService::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener)
286 : : throw (css::uno::RuntimeException)
287 : : {
288 : 0 : m_lListener.removeInterface(::getCppuType((const css::uno::Reference< css::lang::XEventListener >*)NULL), xListener);
289 : 0 : }
290 : :
291 : : //*****************************************************************************************************************
292 : 0 : void TabWindowService::impl_initializePropInfo()
293 : : {
294 [ # # ]: 0 : impl_setPropertyChangeBroadcaster(static_cast< css::awt::XSimpleTabController* >(this));
295 : :
296 : : impl_addPropertyInfo(
297 : : css::beans::Property(
298 : : rtl::OUString("Window"),
299 : : TABWINDOWSERVICE_PROPHANDLE_WINDOW,
300 : 0 : ::getCppuType((const css::uno::Reference< css::awt::XWindow >*)NULL),
301 [ # # ]: 0 : css::beans::PropertyAttribute::TRANSIENT));
302 : 0 : }
303 : :
304 : : //*****************************************************************************************************************
305 : 0 : void SAL_CALL TabWindowService::impl_setPropertyValue(const ::rtl::OUString& /*sProperty*/,
306 : : sal_Int32 /*nHandle */,
307 : : const css::uno::Any& /*aValue */)
308 : :
309 : : {
310 : 0 : }
311 : :
312 : : //*****************************************************************************************************************
313 : 0 : css::uno::Any SAL_CALL TabWindowService::impl_getPropertyValue(const ::rtl::OUString& /*sProperty*/,
314 : : sal_Int32 nHandle )
315 : : {
316 : : /* There is no need to lock any mutex here. Because we share the
317 : : solar mutex with our base class. And we said to our base class: "dont release it on calling us" .-)
318 : : see ctor of PropertySetHelper for further informations.
319 : : */
320 : 0 : css::uno::Any aValue;
321 : :
322 [ # # ]: 0 : switch (nHandle)
323 : : {
324 : : case TABWINDOWSERVICE_PROPHANDLE_WINDOW:
325 : : {
326 [ # # ]: 0 : mem_TabWin (); // force "creation on demand" of m_xTabWin :-)
327 [ # # ]: 0 : aValue <<= m_xTabWin;
328 : : }
329 : 0 : break;
330 : : }
331 : :
332 : 0 : return aValue;
333 : : }
334 : :
335 : : //*****************************************************************************************************************
336 : : // TabWindowService
337 : : //*****************************************************************************************************************
338 : 0 : IMPL_LINK( TabWindowService, EventListener, VclSimpleEvent*, pEvent )
339 : : {
340 : :
341 [ # # ][ # # ]: 0 : if ( !pEvent && !pEvent->ISA(VclWindowEvent))
[ # # ][ # # ]
[ # # ]
342 : 0 : return 0;
343 : :
344 : 0 : sal_uLong nEventId = pEvent->GetId();
345 : 0 : VclWindowEvent* pWinEvt = static_cast< VclWindowEvent* >(pEvent);
346 : :
347 [ # # ]: 0 : css::uno::Reference< css::uno::XInterface > xThis ( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
348 [ # # ]: 0 : css::lang::EventObject aEvent( xThis );
349 : :
350 [ # # ]: 0 : if (nEventId == VCLEVENT_OBJECT_DYING)
351 : : {
352 [ # # ]: 0 : m_lListener.disposeAndClear (aEvent);
353 : :
354 [ # # ][ # # ]: 0 : m_pTabWin->RemoveEventListener( LINK( this, TabWindowService, EventListener ) );
355 : 0 : m_pTabWin = NULL;
356 : 0 : m_xTabWin.clear();
357 : :
358 : 0 : return 0;
359 : : }
360 : :
361 [ # # ][ # # ]: 0 : ::cppu::OInterfaceContainerHelper* pContainer = m_lListener.getContainer(::getCppuType((const css::uno::Reference< css::awt::XTabListener >*) NULL));
362 [ # # ]: 0 : if ( ! pContainer)
363 : 0 : return 0;
364 : :
365 [ # # ]: 0 : ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
366 [ # # ]: 0 : while (pIterator.hasMoreElements())
367 : : {
368 : : try
369 : : {
370 [ # # ]: 0 : css::awt::XTabListener* pListener = (css::awt::XTabListener*)pIterator.next();
371 : :
372 [ # # # # : 0 : switch (nEventId)
# # ]
373 : : {
374 : : case VCLEVENT_TABPAGE_ACTIVATE :
375 [ # # ]: 0 : pListener->activated( (sal_Int32)(sal_uLong)pWinEvt->GetData() );
376 : 0 : break;
377 : :
378 : : case VCLEVENT_TABPAGE_DEACTIVATE :
379 [ # # ]: 0 : pListener->deactivated( (sal_Int32)(sal_uLong)pWinEvt->GetData() );
380 : 0 : break;
381 : :
382 : : case VCLEVENT_TABPAGE_INSERTED :
383 [ # # ]: 0 : pListener->inserted( (sal_Int32)(sal_uLong)pWinEvt->GetData() );
384 : 0 : break;
385 : :
386 : : case VCLEVENT_TABPAGE_REMOVED :
387 [ # # ]: 0 : pListener->removed( (sal_Int32)(sal_uLong)pWinEvt->GetData() );
388 : 0 : break;
389 : :
390 : : case VCLEVENT_TABPAGE_PAGETEXTCHANGED :
391 : : case VCLEVENT_TABPAGE_REMOVEDALL :
392 : 0 : break;
393 : : }
394 : : }
395 [ # # # # ]: 0 : catch(const css::uno::RuntimeException&)
396 : : {
397 [ # # ]: 0 : pIterator.remove();
398 : : }
399 : : }
400 : :
401 [ # # ][ # # ]: 0 : return 0;
402 : : }
403 : :
404 : : //*****************************************************************************************************************
405 : : // TabWindowService
406 : : //*****************************************************************************************************************
407 : 0 : void TabWindowService::impl_checkTabIndex (::sal_Int32 nID)
408 : : throw (css::lang::IndexOutOfBoundsException)
409 : : {
410 [ # # ][ # # ]: 0 : if (
411 : : (nID <= 0 ) ||
412 : : (nID > m_nPageIndexCounter)
413 : : )
414 : : {
415 : : throw css::lang::IndexOutOfBoundsException(
416 : : ::rtl::OUString("Tab index out of bounds."),
417 [ # # ][ # # ]: 0 : css::uno::Reference< css::uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY ));
418 : : }
419 : 0 : }
420 : :
421 : : //*****************************************************************************************************************
422 : : // TabWindowService
423 : : //*****************************************************************************************************************
424 : 0 : TTabPageInfoHash::iterator TabWindowService::impl_getTabPageInfo(::sal_Int32 nID)
425 : : throw (css::lang::IndexOutOfBoundsException)
426 : : {
427 : 0 : TTabPageInfoHash::iterator pIt = m_lTabPageInfos.find(nID);
428 [ # # ]: 0 : if (pIt == m_lTabPageInfos.end ())
429 : : throw css::lang::IndexOutOfBoundsException(
430 : : ::rtl::OUString("Tab index out of bounds."),
431 [ # # ][ # # ]: 0 : css::uno::Reference< css::uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY ));
432 : 0 : return pIt;
433 : : }
434 : :
435 : : //*****************************************************************************************************************
436 : : // TabWindowService
437 : : //*****************************************************************************************************************
438 : 0 : FwkTabWindow* TabWindowService::mem_TabWin ()
439 : : {
440 : 0 : FwkTabWindow* pWin = NULL;
441 : :
442 [ # # ]: 0 : if ( ! m_xTabWin.is ())
443 : : {
444 [ # # ]: 0 : Window* pFakeParent = dynamic_cast< Window* >(Application::GetDefaultDevice ());
445 : :
446 [ # # ]: 0 : m_pTabWin = new FwkTabWindow (pFakeParent);
447 [ # # ]: 0 : m_xTabWin = VCLUnoHelper::GetInterface (m_pTabWin);
448 : :
449 [ # # ]: 0 : m_pTabWin->AddEventListener( LINK( this, TabWindowService, EventListener ) );
450 : : }
451 : :
452 [ # # ]: 0 : if (m_xTabWin.is ())
453 : 0 : pWin = m_pTabWin;
454 : :
455 : 0 : return pWin;
456 : : }
457 : :
458 : : } // namespace framework
459 : :
460 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|