1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 
31 #include <uielement/statusbarmanager.hxx>
32 
33 //_________________________________________________________________________________________________________________
34 //	my own includes
35 //_________________________________________________________________________________________________________________
36 #include <threadhelp/threadhelpbase.hxx>
37 #include <threadhelp/resetableguard.hxx>
38 #include <framework/sfxhelperfunctions.hxx>
39 #include <macros/generic.hxx>
40 #include <macros/xinterface.hxx>
41 #include <macros/xtypeprovider.hxx>
42 #include <stdtypes.h>
43 #include "services.h"
44 #include "general.h"
45 #include "properties.h"
46 #include <helper/mischelper.hxx>
47 
48 //_________________________________________________________________________________________________________________
49 //	interface includes
50 //_________________________________________________________________________________________________________________
51 #include <com/sun/star/frame/XFrame.hpp>
52 #include <com/sun/star/frame/XStatusListener.hpp>
53 #include <com/sun/star/util/XUpdatable.hpp>
54 #include <com/sun/star/ui/ItemStyle.hpp>
55 #include <com/sun/star/ui/ItemType.hpp>
56 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include <com/sun/star/awt/Command.hpp>
59 #include <com/sun/star/lang/DisposedException.hpp>
60 
61 //_________________________________________________________________________________________________________________
62 //	other includes
63 //_________________________________________________________________________________________________________________
64 
65 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
66 #include <toolkit/unohlp.hxx>
67 #endif
68 #include <svtools/statusbarcontroller.hxx>
69 
70 #include <vcl/status.hxx>
71 #include <vcl/svapp.hxx>
72 #include <rtl/logfile.hxx>
73 
74 using namespace ::com::sun::star;
75 #ifndef css
76 #define css ::com::sun::star
77 #endif
78 #ifndef css_ui
79 #define css_ui ::com::sun::star::ui
80 #endif
81 
82 const sal_Int32  HELPID_PREFIX_LENGTH    = 7;
83 static const char*      HELPID_PREFIX           = "helpid:";
84 
85 // Property names of a menu/menu item ItemDescriptor
86 static const char ITEM_DESCRIPTOR_COMMANDURL[]  = "CommandURL";
87 static const char ITEM_DESCRIPTOR_HELPURL[]     = "HelpURL";
88 static const char ITEM_DESCRIPTOR_OFFSET[]      = "Offset";
89 static const char ITEM_DESCRIPTOR_STYLE[]       = "Style";
90 static const char ITEM_DESCRIPTOR_WIDTH[]       = "Width";
91 static const char ITEM_DESCRIPTOR_TYPE[]        = "Type";
92 
93 namespace framework
94 {
95 
96 static sal_uInt16 impl_convertItemStyleToItemBits( sal_Int16 nStyle )
97 {
98     sal_uInt16 nItemBits( 0 );
99 
100     if (( nStyle & css_ui::ItemStyle::ALIGN_RIGHT ) == css_ui::ItemStyle::ALIGN_RIGHT )
101         nItemBits |= SIB_RIGHT;
102     else if ( nStyle & css_ui::ItemStyle::ALIGN_LEFT )
103         nItemBits |= SIB_LEFT;
104     else
105         nItemBits |= SIB_CENTER;
106 
107     if (( nStyle & css_ui::ItemStyle::DRAW_FLAT ) == css_ui::ItemStyle::DRAW_FLAT )
108         nItemBits |= SIB_FLAT;
109     else if ( nStyle & css_ui::ItemStyle::DRAW_OUT3D )
110         nItemBits |= SIB_OUT;
111     else
112         nItemBits |= SIB_IN;
113 
114     if (( nStyle & css_ui::ItemStyle::AUTO_SIZE ) == css_ui::ItemStyle::AUTO_SIZE )
115         nItemBits |= SIB_AUTOSIZE;
116     if ( nStyle & css_ui::ItemStyle::OWNER_DRAW )
117         nItemBits |= SIB_USERDRAW;
118 
119     return nItemBits;
120 }
121 
122 //*****************************************************************************************************************
123 //	XInterface, XTypeProvider, XServiceInfo
124 //*****************************************************************************************************************
125 DEFINE_XINTERFACE_5                     (   StatusBarManager                                                        ,
126                                             ::cppu::OWeakObject                                                     ,
127                                             DIRECT_INTERFACE( lang::XTypeProvider                                   ),
128                                             DIRECT_INTERFACE( lang::XComponent                                      ),
129 											DIRECT_INTERFACE( frame::XFrameActionListener                           ),
130                                             DIRECT_INTERFACE( css::ui::XUIConfigurationListener                    ),
131 											DERIVED_INTERFACE( lang::XEventListener, frame::XFrameActionListener    )
132 										)
133 
134 DEFINE_XTYPEPROVIDER_5                  (   StatusBarManager                    ,
135                                             lang::XTypeProvider		            ,
136                                             lang::XComponent                    ,
137                                             css::ui::XUIConfigurationListener  ,
138 											frame::XFrameActionListener         ,
139 											lang::XEventListener
140 										)
141 
142 StatusBarManager::StatusBarManager(
143     const uno::Reference< lang::XMultiServiceFactory >& rServiceManager,
144     const uno::Reference< frame::XFrame >& rFrame,
145     const rtl::OUString& rResourceName,
146     StatusBar* pStatusBar ) :
147     ThreadHelpBase( &Application::GetSolarMutex() ),
148     OWeakObject(),
149     m_bDisposed( sal_False ),
150     m_bFrameActionRegistered( sal_False ),
151     m_bUpdateControllers( sal_False ),
152     m_bModuleIdentified( sal_False ),
153     m_pStatusBar( pStatusBar ),
154     m_aResourceName( rResourceName ),
155     m_xFrame( rFrame ),
156     m_aListenerContainer( m_aLock.getShareableOslMutex() ),
157     m_xServiceManager( rServiceManager )
158 {
159     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::StatusBarManager" );
160 
161     if ( m_xServiceManager.is() )
162         m_xStatusbarControllerRegistration = uno::Reference< css::frame::XUIControllerRegistration >(
163                                                     m_xServiceManager->createInstance( SERVICENAME_STATUSBARCONTROLLERFACTORY ),
164                                                     uno::UNO_QUERY );
165 
166     m_pStatusBar->SetClickHdl( LINK( this, StatusBarManager, Click ) );
167     m_pStatusBar->SetDoubleClickHdl( LINK( this, StatusBarManager, DoubleClick ) );
168 }
169 
170 StatusBarManager::~StatusBarManager()
171 {
172 }
173 
174 StatusBar* StatusBarManager::GetStatusBar() const
175 {
176     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::GetStatusBar" );
177     ResetableGuard aGuard( m_aLock );
178     return m_pStatusBar;
179 }
180 
181 void StatusBarManager::frameAction( const frame::FrameActionEvent& Action )
182 throw ( uno::RuntimeException )
183 {
184     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::frameAction" );
185     ResetableGuard aGuard( m_aLock );
186     if ( Action.Action == frame::FrameAction_CONTEXT_CHANGED )
187         UpdateControllers();
188 }
189 
190 void SAL_CALL StatusBarManager::disposing( const lang::EventObject& Source ) throw ( uno::RuntimeException )
191 {
192     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::disposing" );
193     {
194         ResetableGuard aGuard( m_aLock );
195         if ( m_bDisposed )
196             return;
197     }
198 
199     RemoveControllers();
200 
201 	{
202 	    ResetableGuard aGuard( m_aLock );
203         if ( Source.Source == uno::Reference< uno::XInterface >( m_xFrame, uno::UNO_QUERY ))
204             m_xFrame.clear();
205 
206         m_xServiceManager.clear();
207     }
208 }
209 
210 // XComponent
211 void SAL_CALL StatusBarManager::dispose() throw( uno::RuntimeException )
212 {
213     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::dispose" );
214     uno::Reference< lang::XComponent > xThis(
215         static_cast< OWeakObject* >(this), uno::UNO_QUERY );
216 
217     lang::EventObject aEvent( xThis );
218     m_aListenerContainer.disposeAndClear( aEvent );
219 
220     {
221 	    ResetableGuard aGuard( m_aLock );
222         if ( !m_bDisposed )
223         {
224             RemoveControllers();
225 
226             delete m_pStatusBar;
227             m_pStatusBar = 0;
228 
229             if ( m_bFrameActionRegistered && m_xFrame.is() )
230             {
231                 try
232                 {
233                     m_xFrame->removeFrameActionListener( uno::Reference< frame::XFrameActionListener >(
234                                                             static_cast< ::cppu::OWeakObject *>( this ),
235                                                             uno::UNO_QUERY ));
236                 }
237                 catch ( uno::Exception& )
238                 {
239                 }
240             }
241 
242             m_xFrame.clear();
243             m_xServiceManager.clear();
244 
245             m_bDisposed = sal_True;
246         }
247     }
248 }
249 
250 void SAL_CALL StatusBarManager::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) throw( uno::RuntimeException )
251 {
252     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::addEventListener" );
253     ResetableGuard aGuard( m_aLock );
254 
255 	/* SAFE AREA ----------------------------------------------------------------------------------------------- */
256     if ( m_bDisposed )
257         throw lang::DisposedException();
258 
259     m_aListenerContainer.addInterface( ::getCppuType(
260         ( const uno::Reference< lang::XEventListener >* ) NULL ), xListener );
261 }
262 
263 void SAL_CALL StatusBarManager::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) throw( uno::RuntimeException )
264 {
265     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::removeEventListener" );
266     m_aListenerContainer.removeInterface( ::getCppuType(
267         ( const uno::Reference< lang::XEventListener >* ) NULL ), xListener );
268 }
269 
270 // XUIConfigurationListener
271 void SAL_CALL StatusBarManager::elementInserted( const css::ui::ConfigurationEvent& ) throw ( uno::RuntimeException )
272 {
273     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::elementInserted" );
274     ResetableGuard aGuard( m_aLock );
275 
276 	/* SAFE AREA ----------------------------------------------------------------------------------------------- */
277     if ( m_bDisposed )
278         return;
279 }
280 
281 void SAL_CALL StatusBarManager::elementRemoved( const css::ui::ConfigurationEvent& ) throw ( uno::RuntimeException )
282 {
283     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::elementRemoved" );
284     ResetableGuard aGuard( m_aLock );
285 
286 	/* SAFE AREA ----------------------------------------------------------------------------------------------- */
287     if ( m_bDisposed )
288         return;
289 }
290 
291 void SAL_CALL StatusBarManager::elementReplaced( const css::ui::ConfigurationEvent& ) throw ( uno::RuntimeException )
292 {
293     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::elementReplaced" );
294     ResetableGuard aGuard( m_aLock );
295 
296 	/* SAFE AREA ----------------------------------------------------------------------------------------------- */
297     if ( m_bDisposed )
298         return;
299 }
300 
301 void StatusBarManager::UpdateControllers()
302 {
303     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::UpdateControllers" );
304     if ( !m_bUpdateControllers )
305     {
306         m_bUpdateControllers = sal_True;
307         const sal_uInt32 nCount = m_aControllerVector.size();
308         for ( sal_uInt32 n = 0; n < nCount; n++ )
309         {
310             try
311             {
312                 uno::Reference< util::XUpdatable > xUpdatable( m_aControllerVector[n], uno::UNO_QUERY );
313                 if ( xUpdatable.is() )
314                     xUpdatable->update();
315             }
316             catch ( uno::Exception& )
317             {
318             }
319         }
320     }
321     m_bUpdateControllers = sal_False;
322 }
323 
324 void StatusBarManager::RemoveControllers()
325 {
326     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::RemoveControllers" );
327     ResetableGuard aGuard( m_aLock );
328 
329     if ( m_bDisposed )
330         return;
331 
332     const sal_uInt32 nCount = m_aControllerVector.size();
333     for ( sal_uInt32 n = 0; n < nCount; n++ )
334     {
335         try
336         {
337             uno::Reference< lang::XComponent > xComponent(
338                 m_aControllerVector[n], uno::UNO_QUERY );
339             if ( xComponent.is() )
340                 xComponent->dispose();
341         }
342         catch ( uno::Exception& )
343         {
344         }
345 
346         m_aControllerVector[n].clear();
347     }
348 }
349 
350 rtl::OUString StatusBarManager::RetrieveLabelFromCommand( const rtl::OUString& aCmdURL )
351 {
352     return framework::RetrieveLabelFromCommand(aCmdURL,m_xServiceManager,m_xUICommandLabels,m_xFrame,m_aModuleIdentifier,m_bModuleIdentified,"Name");
353 }
354 
355 void StatusBarManager::CreateControllers()
356 {
357     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::CreateControllers" );
358     uno::Reference< lang::XMultiComponentFactory > xStatusbarControllerFactory( m_xStatusbarControllerRegistration, uno::UNO_QUERY );
359     uno::Reference< uno::XComponentContext > xComponentContext;
360     uno::Reference< beans::XPropertySet > xProps( m_xServiceManager, uno::UNO_QUERY );
361     uno::Reference< awt::XWindow > xStatusbarWindow = VCLUnoHelper::GetInterface( m_pStatusBar );
362 
363     if ( xProps.is() )
364         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComponentContext;
365 
366     for ( sal_uInt16 i = 0; i < m_pStatusBar->GetItemCount(); i++ )
367     {
368         sal_uInt16 nId = m_pStatusBar->GetItemId( i );
369         if ( nId == 0 )
370             continue;
371 
372         rtl::OUString                            aCommandURL( m_pStatusBar->GetItemCommand( nId ));
373         sal_Bool                                 bInit( sal_True );
374         uno::Reference< frame::XStatusListener > xController;
375 
376         svt::StatusbarController* pController( 0 );
377 
378         if ( m_xStatusbarControllerRegistration.is() &&
379              m_xStatusbarControllerRegistration->hasController( aCommandURL, m_aModuleIdentifier ))
380         {
381             if ( xStatusbarControllerFactory.is() )
382             {
383                 uno::Sequence< uno::Any > aSeq( 5 );
384                 beans::PropertyValue aPropValue;
385 
386                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
387                 aPropValue.Value    = uno::makeAny( m_aModuleIdentifier );
388                 aSeq[0] = uno::makeAny( aPropValue );
389                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
390                 aPropValue.Value    = uno::makeAny( m_xFrame );
391                 aSeq[1] = uno::makeAny( aPropValue );
392                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
393                 aPropValue.Value    = uno::makeAny( m_xServiceManager );
394                 aSeq[2] = uno::makeAny( aPropValue );
395                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
396                 aPropValue.Value    = uno::makeAny( xStatusbarWindow );
397                 aSeq[3] = uno::makeAny( aPropValue );
398                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Identifier" ));
399                 aPropValue.Value    = uno::makeAny( nId );
400                 aSeq[4] = uno::makeAny( aPropValue );
401 
402                 xController = uno::Reference< frame::XStatusListener >(
403                                 xStatusbarControllerFactory->createInstanceWithArgumentsAndContext(
404                                     aCommandURL, aSeq, xComponentContext ),
405                                 uno::UNO_QUERY );
406                 bInit = sal_False; // Initialization is done through the factory service
407             }
408         }
409 
410         if ( !xController.is() )
411         {
412             pController = CreateStatusBarController( m_xFrame, m_pStatusBar, nId, aCommandURL );
413             if ( !pController )
414                 pController = new svt::StatusbarController( m_xServiceManager, m_xFrame, aCommandURL, nId );
415 
416             if ( pController )
417                 xController = uno::Reference< frame::XStatusListener >(
418                                 static_cast< ::cppu::OWeakObject *>( pController ),
419                                 uno::UNO_QUERY );
420         }
421 
422         m_aControllerVector.push_back( xController );
423         uno::Reference< lang::XInitialization > xInit( xController, uno::UNO_QUERY );
424 
425         if ( xInit.is() )
426         {
427             if ( bInit )
428             {
429                 beans::PropertyValue aPropValue;
430                 uno::Sequence< uno::Any > aArgs( 5 );
431                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
432                 aPropValue.Value    = uno::makeAny( m_xFrame );
433                 aArgs[0] = uno::makeAny( aPropValue );
434                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
435                 aPropValue.Value    = uno::makeAny( aCommandURL );
436                 aArgs[1] = uno::makeAny( aPropValue );
437                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
438                 aPropValue.Value    = uno::makeAny( m_xServiceManager );
439                 aArgs[2] = uno::makeAny( aPropValue );
440                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
441                 aPropValue.Value    = uno::makeAny( xStatusbarWindow );
442                 aArgs[3] = uno::makeAny( aPropValue );
443                 aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Identifier" ));
444                 aPropValue.Value    = uno::makeAny( nId );
445                 aArgs[4] = uno::makeAny( aPropValue );
446                 xInit->initialize( aArgs );
447             }
448         }
449     }
450 
451     AddFrameActionListener();
452 }
453 
454 void StatusBarManager::AddFrameActionListener()
455 {
456     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::AddFrameActionListener" );
457     if ( !m_bFrameActionRegistered && m_xFrame.is() )
458     {
459         m_bFrameActionRegistered = sal_True;
460         m_xFrame->addFrameActionListener( uno::Reference< frame::XFrameActionListener >(
461             static_cast< ::cppu::OWeakObject *>( this ), uno::UNO_QUERY ));
462     }
463 }
464 
465 void StatusBarManager::FillStatusBar( const uno::Reference< container::XIndexAccess >& rItemContainer )
466 {
467     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::StatusBarManager::FillStatusbar" );
468 
469     ResetableGuard aGuard( m_aLock );
470 
471     if ( m_bDisposed || !m_pStatusBar )
472         return;
473 
474     sal_uInt16         nId( 1 );
475     rtl::OUString  aHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( HELPID_PREFIX ));
476 
477     RemoveControllers();
478 
479     // reset and fill command map
480     m_pStatusBar->Clear();
481     m_aControllerVector.clear();
482 
483     for ( sal_Int32 n = 0; n < rItemContainer->getCount(); n++ )
484     {
485         RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::FillStatusBar" );
486         uno::Sequence< beans::PropertyValue >   aProp;
487         rtl::OUString                           aCommandURL;
488         rtl::OUString                           aHelpURL;
489         sal_Int16                               nOffset( 0 );
490         sal_Int16                               nStyle( 0 );
491         sal_Int16                               nWidth( 0 );
492         sal_uInt16                              nType( css_ui::ItemType::DEFAULT );
493 
494         try
495         {
496             if ( rItemContainer->getByIndex( n ) >>= aProp )
497             {
498                 for ( int i = 0; i < aProp.getLength(); i++ )
499                 {
500                     if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
501                     {
502                         aProp[i].Value >>= aCommandURL;
503                     }
504                     else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_HELPURL ))
505                     {
506                         aProp[i].Value >>= aHelpURL;
507                     }
508                     else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
509                     {
510                         aProp[i].Value >>= nStyle;
511                     }
512                     else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
513                     {
514                         aProp[i].Value >>= nType;
515                     }
516                     else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_WIDTH ))
517                     {
518                         aProp[i].Value >>= nWidth;
519                     }
520                     else if ( aProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_OFFSET ))
521                     {
522                         aProp[i].Value >>= nOffset;
523                     }
524                 }
525 
526                 if (( nType == ::com::sun::star::ui::ItemType::DEFAULT ) && ( aCommandURL.getLength() > 0 ))
527                 {
528                     rtl::OUString aString( RetrieveLabelFromCommand( aCommandURL ));
529                     sal_uInt16        nItemBits( impl_convertItemStyleToItemBits( nStyle ));
530 
531                     m_pStatusBar->InsertItem( nId, nWidth, nItemBits, nOffset );
532                     m_pStatusBar->SetItemCommand( nId, aCommandURL );
533                     m_pStatusBar->SetAccessibleName( nId, aString );
534                     ++nId;
535                 }
536             }
537         }
538         catch ( ::com::sun::star::lang::IndexOutOfBoundsException& )
539         {
540             break;
541         }
542     }
543 
544     // Create controllers
545     CreateControllers();
546 
547     // Notify controllers that they are now correctly initialized and can start listening
548     UpdateControllers();
549 }
550 
551 void StatusBarManager::StateChanged( StateChangedType )
552 {
553     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::StateChanged" );
554 }
555 
556 void StatusBarManager::DataChanged( const DataChangedEvent& rDCEvt )
557 {
558     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::DataChanged" );
559     ResetableGuard aGuard( m_aLock );
560 
561     if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS	        ) ||
562          ( rDCEvt.GetType() == DATACHANGED_FONTS            ) ||
563 		 ( rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION ) ||
564 		 ( rDCEvt.GetType() == DATACHANGED_DISPLAY	        ))	&&
565          ( rDCEvt.GetFlags() & SETTINGS_STYLE		        ))
566     {
567         css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
568         css::uno::Reference< css::beans::XPropertySet > xPropSet( m_xFrame, css::uno::UNO_QUERY );
569         if ( xPropSet.is() )
570             xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager;
571         if ( xLayoutManager.is() )
572         {
573             aGuard.unlock();
574             xLayoutManager->doLayout();
575         }
576     }
577 }
578 
579 void StatusBarManager::UserDraw( const UserDrawEvent& rUDEvt )
580 {
581     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::UserDraw" );
582     ResetableGuard aGuard( m_aLock );
583 
584     if ( m_bDisposed )
585         return;
586 
587     sal_uInt16 nId( rUDEvt.GetItemId() );
588     if (( nId > 0 ) && ( nId <= m_aControllerVector.size() ))
589     {
590         uno::Reference< frame::XStatusbarController > xController(
591             m_aControllerVector[nId-1], uno::UNO_QUERY );
592         if ( xController.is() && rUDEvt.GetDevice() )
593         {
594             uno::Reference< awt::XGraphics > xGraphics =
595                 rUDEvt.GetDevice()->CreateUnoGraphics();
596 
597             awt::Rectangle aRect( rUDEvt.GetRect().Left(),
598                                   rUDEvt.GetRect().Top(),
599                                   rUDEvt.GetRect().GetWidth(),
600                                   rUDEvt.GetRect().GetHeight() );
601             aGuard.unlock();
602             xController->paint( xGraphics, aRect, rUDEvt.GetItemId(), rUDEvt.GetStyle() );
603         }
604     }
605 }
606 
607 void StatusBarManager::Command( const CommandEvent& rEvt )
608 {
609     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::Command" );
610     ResetableGuard aGuard( m_aLock );
611 
612     if ( m_bDisposed )
613         return;
614 
615     if ( rEvt.GetCommand() == COMMAND_CONTEXTMENU )
616     {
617         sal_uInt16 nId = m_pStatusBar->GetItemId( rEvt.GetMousePosPixel() );
618         if (( nId > 0 ) && ( nId <= m_aControllerVector.size() ))
619         {
620             uno::Reference< frame::XStatusbarController > xController(
621                 m_aControllerVector[nId-1], uno::UNO_QUERY );
622             if ( xController.is() )
623             {
624                 awt::Point aPos;
625                 aPos.X = rEvt.GetMousePosPixel().X();
626                 aPos.Y = rEvt.GetMousePosPixel().Y();
627                 xController->command( aPos, awt::Command::CONTEXTMENU, sal_True, uno::Any() );
628             }
629         }
630     }
631 }
632 
633 void StatusBarManager::MouseMove( const MouseEvent& rMEvt )
634 {
635     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::MouseMove" );
636     MouseButton(rMEvt,&frame::XStatusbarController::mouseMove);
637 }
638 void StatusBarManager::MouseButton( const MouseEvent& rMEvt ,sal_Bool ( SAL_CALL frame::XStatusbarController::*_pMethod )(const ::com::sun::star::awt::MouseEvent&))
639 {
640     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::MouseButton" );
641     ResetableGuard aGuard( m_aLock );
642 
643     if ( !m_bDisposed )
644     {
645         sal_uInt16 nId = m_pStatusBar->GetItemId( rMEvt.GetPosPixel() );
646         if (( nId > 0 ) && ( nId <= m_aControllerVector.size() ))
647         {
648             uno::Reference< frame::XStatusbarController > xController(
649                 m_aControllerVector[nId-1], uno::UNO_QUERY );
650             if ( xController.is() )
651             {
652                 ::com::sun::star::awt::MouseEvent aMouseEvent;
653                 aMouseEvent.Buttons = rMEvt.GetButtons();
654                 aMouseEvent.X = rMEvt.GetPosPixel().X();
655                 aMouseEvent.Y = rMEvt.GetPosPixel().Y();
656                 aMouseEvent.ClickCount = rMEvt.GetClicks();
657                 (xController.get()->*_pMethod)( aMouseEvent);
658             }
659         } // if (( nId > 0 ) && ( nId <= m_aControllerVector.size() ))
660     }
661 }
662 void StatusBarManager::MouseButtonDown( const MouseEvent& rMEvt )
663 {
664     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::MouseButtonDown" );
665     MouseButton(rMEvt,&frame::XStatusbarController::mouseButtonDown);
666 }
667 
668 void StatusBarManager::MouseButtonUp( const MouseEvent& rMEvt )
669 {
670     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "StatusBarManager::MouseButtonUp" );
671     MouseButton(rMEvt,&frame::XStatusbarController::mouseButtonUp);
672 }
673 
674 IMPL_LINK( StatusBarManager, Click, StatusBar*, EMPTYARG )
675 {
676     ResetableGuard aGuard( m_aLock );
677 
678     if ( m_bDisposed )
679         return 1;
680 
681     sal_uInt16 nId = m_pStatusBar->GetCurItemId();
682     if (( nId > 0 ) && ( nId <= m_aControllerVector.size() ))
683     {
684         uno::Reference< frame::XStatusbarController > xController(
685             m_aControllerVector[nId-1], uno::UNO_QUERY );
686         if ( xController.is() )
687             xController->click();
688     }
689 
690     return 1;
691 }
692 
693 IMPL_LINK( StatusBarManager, DoubleClick, StatusBar*, EMPTYARG )
694 {
695     ResetableGuard aGuard( m_aLock );
696 
697     if ( m_bDisposed )
698         return 1;
699 
700     sal_uInt16 nId = m_pStatusBar->GetCurItemId();
701     if (( nId > 0 ) && ( nId <= m_aControllerVector.size() ))
702     {
703         uno::Reference< frame::XStatusbarController > xController(
704             m_aControllerVector[nId-1], uno::UNO_QUERY );
705         if ( xController.is() )
706             xController->doubleClick();
707     }
708 
709     return 1;
710 }
711 
712 }
713