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