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