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_forms.hxx"
26 #include "attributedispatcher.hxx"
27 
28 /** === begin UNO includes === **/
29 /** === end UNO includes === **/
30 #include <editeng/editview.hxx>
31 
32 //........................................................................
33 namespace frm
34 {
35 //........................................................................
36 
37     using namespace ::com::sun::star::uno;
38     using namespace ::com::sun::star::frame;
39     using namespace ::com::sun::star::lang;
40     using namespace ::com::sun::star::util;
41     using namespace ::com::sun::star::beans;
42 
43     //====================================================================
44 	//= OAttributeDispatcher
45 	//====================================================================
46 	//--------------------------------------------------------------------
OAttributeDispatcher(EditView & _rView,AttributeId _nAttributeId,const URL & _rURL,IMultiAttributeDispatcher * _pMasterDispatcher)47     OAttributeDispatcher::OAttributeDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL,
48             IMultiAttributeDispatcher* _pMasterDispatcher )
49         :ORichTextFeatureDispatcher( _rView, _rURL )
50         ,m_pMasterDispatcher( _pMasterDispatcher )
51         ,m_nAttributeId( _nAttributeId )
52     {
53         OSL_ENSURE( m_pMasterDispatcher, "OAttributeDispatcher::OAttributeDispatcher: invalid master dispatcher!" );
54     }
55 
56 	//--------------------------------------------------------------------
~OAttributeDispatcher()57     OAttributeDispatcher::~OAttributeDispatcher( )
58     {
59         acquire();
60         dispose();
61     }
62 
63     //--------------------------------------------------------------------
disposing(::osl::ClearableMutexGuard & _rClearBeforeNotify)64     void OAttributeDispatcher::disposing( ::osl::ClearableMutexGuard& _rClearBeforeNotify )
65     {
66         m_pMasterDispatcher = NULL;
67         ORichTextFeatureDispatcher::disposing( _rClearBeforeNotify );
68     }
69 
70     //--------------------------------------------------------------------
fillFeatureEventFromAttributeState(FeatureStateEvent & _rEvent,const AttributeState & _rState) const71     void OAttributeDispatcher::fillFeatureEventFromAttributeState( FeatureStateEvent& _rEvent, const AttributeState& _rState ) const
72     {
73         if ( _rState.eSimpleState == eChecked )
74             _rEvent.State <<= (sal_Bool)sal_True;
75         else if ( _rState.eSimpleState == eUnchecked )
76             _rEvent.State <<= (sal_Bool)sal_False;
77     }
78 
79     //--------------------------------------------------------------------
buildStatusEvent() const80     FeatureStateEvent OAttributeDispatcher::buildStatusEvent() const
81     {
82         FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
83         aEvent.IsEnabled = getEditView() ? !getEditView()->IsReadOnly() : sal_False;
84 
85         AttributeState aState;
86         if ( m_pMasterDispatcher )
87             aState = m_pMasterDispatcher->getState( m_nAttributeId );
88 
89         fillFeatureEventFromAttributeState( aEvent, aState );
90 
91         return aEvent;
92     }
93 
94     //--------------------------------------------------------------------
dispatch(const URL & _rURL,const Sequence<PropertyValue> & _rArguments)95     void SAL_CALL OAttributeDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException)
96     {
97         ::osl::MutexGuard aGuard( m_aMutex );
98 
99         checkDisposed();
100 
101         (void)_rURL;
102         (void)_rArguments;
103 
104         OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OAttributeDispatcher::dispatch: invalid URL!" );
105 #if OSL_DEBUG_LEVEL > 0
106         if ( _rArguments.getLength() )
107         {
108             ::rtl::OString sMessage( "OAttributeDispatcher::dispatch: found arguments, but can't handle arguments at all" );
109             sMessage += "\n (URL: ";
110             sMessage += ::rtl::OString( _rURL.Complete.getStr(), _rURL.Complete.getLength(), RTL_TEXTENCODING_ASCII_US );
111             sMessage += ")";
112             DBG_ERROR( sMessage.getStr() );
113         }
114 #endif
115 
116         if ( m_pMasterDispatcher )
117             m_pMasterDispatcher->executeAttribute( m_nAttributeId, NULL );
118     }
119 
120     //--------------------------------------------------------------------
onAttributeStateChanged(AttributeId _nAttributeId,const AttributeState &)121     void OAttributeDispatcher::onAttributeStateChanged( AttributeId _nAttributeId, const AttributeState& /*_rState*/ )
122     {
123         OSL_ENSURE( _nAttributeId == m_nAttributeId, "OAttributeDispatcher::onAttributeStateChanged: wrong attribute!" );
124         (void)_nAttributeId;
125 
126         FeatureStateEvent aEvent( buildStatusEvent() );
127         ::cppu::OInterfaceIteratorHelper aIter( getStatusListeners() );
128     	while ( aIter.hasMoreElements() )
129             doNotify( static_cast< XStatusListener* >( aIter.next() ), aEvent );
130     }
131 
132 //........................................................................
133 }   // namespace frm
134 //........................................................................
135