1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 31 #include "StatusBarCommandDispatch.hxx" 32 #include "ObjectNameProvider.hxx" 33 #include "macros.hxx" 34 #include <com/sun/star/util/XModifyBroadcaster.hpp> 35 36 // #ifndef _VOS_MUTEX_HXX_ 37 // #include <vos/mutex.hxx> 38 // #endif 39 // #ifndef _SV_SVAPP_HXX 40 // #include <vcl/svapp.hxx> 41 // #endif 42 43 #include "ResId.hxx" 44 45 using namespace ::com::sun::star; 46 47 using ::com::sun::star::uno::Reference; 48 using ::com::sun::star::uno::Sequence; 49 using ::rtl::OUString; 50 51 namespace chart 52 { 53 54 StatusBarCommandDispatch::StatusBarCommandDispatch( 55 const Reference< uno::XComponentContext > & xContext, 56 const Reference< frame::XModel > & xModel, 57 const Reference< view::XSelectionSupplier > & xSelSupp ) : 58 impl::StatusBarCommandDispatch_Base( xContext ), 59 m_xModifiable( xModel, uno::UNO_QUERY ), 60 m_xSelectionSupplier( xSelSupp ), 61 m_bIsModified( false ) 62 {} 63 64 StatusBarCommandDispatch::~StatusBarCommandDispatch() 65 {} 66 67 void StatusBarCommandDispatch::initialize() 68 { 69 if( m_xModifiable.is()) 70 { 71 Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xModifiable, uno::UNO_QUERY ); 72 OSL_ASSERT( xModifyBroadcaster.is()); 73 if( xModifyBroadcaster.is()) 74 xModifyBroadcaster->addModifyListener( this ); 75 } 76 77 if( m_xSelectionSupplier.is()) 78 { 79 m_xSelectionSupplier->addSelectionChangeListener( this ); 80 } 81 } 82 83 void StatusBarCommandDispatch::fireStatusEvent( 84 const OUString & rURL, 85 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ ) 86 { 87 bool bFireAll(rURL.getLength() == 0); 88 bool bFireContext( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Context"))); 89 bool bFireModified( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:ModifiedStatus"))); 90 91 if( bFireContext ) 92 { 93 uno::Any aArg; 94 Reference< chart2::XChartDocument > xDoc( m_xModifiable, uno::UNO_QUERY ); 95 aArg <<= ObjectNameProvider::getSelectedObjectText( m_aSelectedOID.getObjectCID(), xDoc ); 96 fireStatusEventForURL( C2U(".uno:Context"), aArg, true, xSingleListener ); 97 } 98 if( bFireModified ) 99 { 100 uno::Any aArg; 101 if( m_bIsModified ) 102 aArg <<= C2U("*"); 103 fireStatusEventForURL( C2U(".uno:ModifiedStatus"), aArg, true, xSingleListener ); 104 } 105 } 106 107 // ____ XDispatch ____ 108 void SAL_CALL StatusBarCommandDispatch::dispatch( 109 const util::URL& /* URL */, 110 const Sequence< beans::PropertyValue >& /* Arguments */ ) 111 throw (uno::RuntimeException) 112 { 113 // nothing to do here 114 } 115 116 // ____ WeakComponentImplHelperBase ____ 117 /// is called when this is disposed 118 void SAL_CALL StatusBarCommandDispatch::disposing() 119 { 120 m_xModifiable.clear(); 121 m_xSelectionSupplier.clear(); 122 } 123 124 // ____ XEventListener (base of XModifyListener) ____ 125 void SAL_CALL StatusBarCommandDispatch::disposing( const lang::EventObject& /* Source */ ) 126 throw (uno::RuntimeException) 127 { 128 m_xModifiable.clear(); 129 m_xSelectionSupplier.clear(); 130 } 131 132 // ____ XModifyListener ____ 133 void SAL_CALL StatusBarCommandDispatch::modified( const lang::EventObject& aEvent ) 134 throw (uno::RuntimeException) 135 { 136 if( m_xModifiable.is()) 137 m_bIsModified = m_xModifiable->isModified(); 138 139 CommandDispatch::modified( aEvent ); 140 } 141 142 // ____ XSelectionChangeListener ____ 143 void SAL_CALL StatusBarCommandDispatch::selectionChanged( const lang::EventObject& /* aEvent */ ) 144 throw (uno::RuntimeException) 145 { 146 if( m_xSelectionSupplier.is()) 147 m_aSelectedOID = ObjectIdentifier( m_xSelectionSupplier->getSelection() ); 148 else 149 m_aSelectedOID = ObjectIdentifier(); 150 fireAllStatusEvents( 0 ); 151 } 152 153 } // namespace chart 154