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