update dev300-m58
[ooovba.git] / forms / source / richtext / attributedispatcher.cxx
blob49b0920e02ac34fb1e3aecfebc4c290db445abc0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: attributedispatcher.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "attributedispatcher.hxx"
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
37 #include <svx/editview.hxx>
39 //........................................................................
40 namespace frm
42 //........................................................................
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::frame;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::util;
48 using namespace ::com::sun::star::beans;
50 //====================================================================
51 //= OAttributeDispatcher
52 //====================================================================
53 //--------------------------------------------------------------------
54 OAttributeDispatcher::OAttributeDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL,
55 IMultiAttributeDispatcher* _pMasterDispatcher )
56 :ORichTextFeatureDispatcher( _rView, _rURL )
57 ,m_pMasterDispatcher( _pMasterDispatcher )
58 ,m_nAttributeId( _nAttributeId )
60 OSL_ENSURE( m_pMasterDispatcher, "OAttributeDispatcher::OAttributeDispatcher: invalid master dispatcher!" );
63 //--------------------------------------------------------------------
64 OAttributeDispatcher::~OAttributeDispatcher( )
66 acquire();
67 dispose();
70 //--------------------------------------------------------------------
71 void OAttributeDispatcher::disposing( ::osl::ClearableMutexGuard& _rClearBeforeNotify )
73 m_pMasterDispatcher = NULL;
74 ORichTextFeatureDispatcher::disposing( _rClearBeforeNotify );
77 //--------------------------------------------------------------------
78 void OAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const
80 if ( _rState.eSimpleState == eChecked )
81 _rEvent.State <<= (sal_Bool)sal_True;
82 else if ( _rState.eSimpleState == eUnchecked )
83 _rEvent.State <<= (sal_Bool)sal_False;
86 //--------------------------------------------------------------------
87 FeatureStateEvent OAttributeDispatcher::buildStatusEvent() const
89 FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
90 aEvent.IsEnabled = getEditView() ? !getEditView()->IsReadOnly() : sal_False;
92 AttributeState aState;
93 if ( m_pMasterDispatcher )
94 aState = m_pMasterDispatcher->getState( m_nAttributeId );
96 fillFeatureEventFromAttributeState( aEvent, aState );
98 return aEvent;
101 //--------------------------------------------------------------------
102 void SAL_CALL OAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException)
104 ::osl::MutexGuard aGuard( m_aMutex );
106 checkDisposed();
108 (void)_rURL;
109 (void)_rArguments;
111 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OAttributeDispatcher::dispatch: invalid URL!" );
112 #if OSL_DEBUG_LEVEL > 0
113 if ( _rArguments.getLength() )
115 ::rtl::OString sMessage( "OAttributeDispatcher::dispatch: found arguments, but can't handle arguments at all" );
116 sMessage += "\n (URL: ";
117 sMessage += ::rtl::OString( _rURL.Complete.getStr(), _rURL.Complete.getLength(), RTL_TEXTENCODING_ASCII_US );
118 sMessage += ")";
119 DBG_ERROR( sMessage.getStr() );
121 #endif
123 if ( m_pMasterDispatcher )
124 m_pMasterDispatcher->executeAttribute( m_nAttributeId, NULL );
127 //--------------------------------------------------------------------
128 void OAttributeDispatcher::onAttributeStateChanged( AttributeId _nAttributeId, const AttributeState& /*_rState*/ )
130 OSL_ENSURE( _nAttributeId == m_nAttributeId, "OAttributeDispatcher::onAttributeStateChanged: wrong attribute!" );
131 (void)_nAttributeId;
133 FeatureStateEvent aEvent( buildStatusEvent() );
134 ::cppu::OInterfaceIteratorHelper aIter( getStatusListeners() );
135 while ( aIter.hasMoreElements() )
136 doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent );
139 //........................................................................
140 } // namespace frm
141 //........................................................................