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