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