xref: /trunk/main/chart2/source/controller/main/StatusBarCommandDispatch.cxx (revision a3cdc23e488c57f3433f22cd4458e65c27aa499c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_chart2.hxx"
24 
25 #include "StatusBarCommandDispatch.hxx"
26 #include "ObjectNameProvider.hxx"
27 #include "macros.hxx"
28 #include <com/sun/star/util/XModifyBroadcaster.hpp>
29 
30 // #ifndef _VOS_MUTEX_HXX_
31 // #include <vos/mutex.hxx>
32 // #endif
33 // #ifndef _SV_SVAPP_HXX
34 // #include <vcl/svapp.hxx>
35 // #endif
36 
37 #include "ResId.hxx"
38 
39 using namespace ::com::sun::star;
40 
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Sequence;
43 using ::rtl::OUString;
44 
45 namespace chart
46 {
47 
48 StatusBarCommandDispatch::StatusBarCommandDispatch(
49     const Reference< uno::XComponentContext > & xContext,
50     const Reference< frame::XModel > & xModel,
51     const Reference< view::XSelectionSupplier > & xSelSupp ) :
52         impl::StatusBarCommandDispatch_Base( xContext ),
53         m_xModifiable( xModel, uno::UNO_QUERY  ),
54         m_xSelectionSupplier( xSelSupp ),
55         m_bIsModified( false )
56 {}
57 
58 StatusBarCommandDispatch::~StatusBarCommandDispatch()
59 {}
60 
61 void StatusBarCommandDispatch::initialize()
62 {
63     if( m_xModifiable.is())
64     {
65         Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xModifiable, uno::UNO_QUERY );
66         OSL_ASSERT( xModifyBroadcaster.is());
67         if( xModifyBroadcaster.is())
68             xModifyBroadcaster->addModifyListener( this );
69     }
70 
71     if( m_xSelectionSupplier.is())
72     {
73         m_xSelectionSupplier->addSelectionChangeListener( this );
74     }
75 }
76 
77 void StatusBarCommandDispatch::fireStatusEvent(
78     const OUString & rURL,
79     const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
80 {
81     bool bFireAll( rURL.isEmpty() );
82     bool bFireContext(  bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Context")));
83     bool bFireModified( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:ModifiedStatus")));
84 
85     if( bFireContext )
86     {
87         uno::Any aArg;
88         Reference< chart2::XChartDocument > xDoc( m_xModifiable, uno::UNO_QUERY );
89         aArg <<= ObjectNameProvider::getSelectedObjectText( m_aSelectedOID.getObjectCID(), xDoc );
90         fireStatusEventForURL( C2U(".uno:Context"), aArg, true, xSingleListener );
91     }
92     if( bFireModified )
93     {
94         uno::Any aArg;
95         if( m_bIsModified )
96             aArg <<= C2U("*");
97         fireStatusEventForURL( C2U(".uno:ModifiedStatus"), aArg, true, xSingleListener );
98     }
99 }
100 
101 // ____ XDispatch ____
102 void SAL_CALL StatusBarCommandDispatch::dispatch(
103     const util::URL& /* URL */,
104     const Sequence< beans::PropertyValue >& /* Arguments */ )
105     throw (uno::RuntimeException)
106 {
107     // nothing to do here
108 }
109 
110 // ____ WeakComponentImplHelperBase ____
111 // is called when this is disposed
112 void SAL_CALL StatusBarCommandDispatch::disposing()
113 {
114     m_xModifiable.clear();
115     m_xSelectionSupplier.clear();
116 }
117 
118 // ____ XEventListener (base of XModifyListener) ____
119 void SAL_CALL StatusBarCommandDispatch::disposing( const lang::EventObject& /* Source */ )
120     throw (uno::RuntimeException)
121 {
122     m_xModifiable.clear();
123     m_xSelectionSupplier.clear();
124 }
125 
126 // ____ XModifyListener ____
127 void SAL_CALL StatusBarCommandDispatch::modified( const lang::EventObject& aEvent )
128     throw (uno::RuntimeException)
129 {
130     if( m_xModifiable.is())
131         m_bIsModified = m_xModifiable->isModified();
132 
133     CommandDispatch::modified( aEvent );
134 }
135 
136 // ____ XSelectionChangeListener ____
137 void SAL_CALL StatusBarCommandDispatch::selectionChanged( const lang::EventObject& /* aEvent */ )
138     throw (uno::RuntimeException)
139 {
140     if( m_xSelectionSupplier.is())
141         m_aSelectedOID = ObjectIdentifier( m_xSelectionSupplier->getSelection() );
142     else
143         m_aSelectedOID = ObjectIdentifier();
144     fireAllStatusEvents( 0 );
145 }
146 
147 } //  namespace chart
148 
149 /* vim: set noet sw=4 ts=4: */
150