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