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_svx.hxx"
30 #include "fmtextcontrolfeature.hxx"
31 
32 /** === begin UNO includes === **/
33 /** === end UNO includes === **/
34 
35 //........................................................................
36 namespace svx
37 {
38 //........................................................................
39 
40     using namespace ::com::sun::star::uno;
41     using namespace ::com::sun::star::frame;
42     using namespace ::com::sun::star::lang;
43     using namespace ::com::sun::star::beans;
44     using namespace ::com::sun::star::util;
45 
46     //====================================================================
47 	//= FmTextControlFeature
48 	//====================================================================
49 	//--------------------------------------------------------------------
50     FmTextControlFeature::FmTextControlFeature( const Reference< XDispatch >& _rxDispatcher, const URL& _rFeatureURL, SfxSlotId _nSlotId, ISlotInvalidator* _pInvalidator )
51         :m_xDispatcher    ( _rxDispatcher )
52         ,m_aFeatureURL    ( _rFeatureURL  )
53         ,m_nSlotId        ( _nSlotId      )
54         ,m_pInvalidator   ( _pInvalidator )
55         ,m_bFeatureEnabled( false         )
56     {
57         OSL_ENSURE( _rxDispatcher.is(), "FmTextControlFeature::FmTextControlFeature: invalid dispatcher!"  );
58         OSL_ENSURE( m_nSlotId,          "FmTextControlFeature::FmTextControlFeature: invalid slot id!"     );
59         OSL_ENSURE( m_pInvalidator,     "FmTextControlFeature::FmTextControlFeature: invalid invalidator!" );
60 
61         osl_incrementInterlockedCount( &m_refCount );
62         try
63         {
64             m_xDispatcher->addStatusListener( this, m_aFeatureURL );
65         }
66         catch( const Exception& )
67         {
68         	OSL_ENSURE( sal_False, "FmTextControlFeature::FmTextControlFeature: caught an exception!" );
69         }
70         osl_decrementInterlockedCount( &m_refCount );
71     }
72 
73 	//--------------------------------------------------------------------
74     FmTextControlFeature::~FmTextControlFeature( )
75     {
76     }
77 
78 	//--------------------------------------------------------------------
79     void FmTextControlFeature::dispatch() const SAL_THROW(())
80     {
81         dispatch( Sequence< PropertyValue >( ) );
82     }
83 
84     //--------------------------------------------------------------------
85     void FmTextControlFeature::dispatch( const Sequence< PropertyValue >& _rArgs ) const SAL_THROW(())
86     {
87         try
88         {
89             if ( m_xDispatcher.is() )
90                 m_xDispatcher->dispatch( m_aFeatureURL, _rArgs );
91         }
92         catch( const Exception& )
93         {
94         	OSL_ENSURE( sal_False, "FmTextControlFeature::dispatch: caught an exception!" );
95         }
96     }
97 
98     //--------------------------------------------------------------------
99     void SAL_CALL FmTextControlFeature::statusChanged( const FeatureStateEvent& _rState ) throw (RuntimeException)
100     {
101         m_aFeatureState   = _rState.State;
102         m_bFeatureEnabled = _rState.IsEnabled;
103 
104         if ( m_pInvalidator )
105             m_pInvalidator->Invalidate( m_nSlotId );
106     }
107 
108     //--------------------------------------------------------------------
109     void SAL_CALL FmTextControlFeature::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
110     {
111         // nothing to do
112     }
113 
114     //--------------------------------------------------------------------
115     void FmTextControlFeature::dispose() SAL_THROW(())
116     {
117         try
118         {
119             m_xDispatcher->removeStatusListener( this, m_aFeatureURL );
120             m_xDispatcher.clear();
121         }
122         catch( const Exception& )
123         {
124         	OSL_ENSURE( sal_False, "FmTextControlFeature::dispose: caught an exception!" );
125         }
126     }
127 
128 //........................................................................
129 }   // namespace svx
130 //........................................................................
131 
132