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