Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "StatusBarCommandDispatch.hxx"
21 : #include "ObjectNameProvider.hxx"
22 : #include "macros.hxx"
23 : #include <com/sun/star/util/XModifyBroadcaster.hpp>
24 :
25 : #include "ResId.hxx"
26 :
27 : using namespace ::com::sun::star;
28 :
29 : using ::com::sun::star::uno::Reference;
30 : using ::com::sun::star::uno::Sequence;
31 :
32 : namespace chart
33 : {
34 :
35 0 : StatusBarCommandDispatch::StatusBarCommandDispatch(
36 : const Reference< uno::XComponentContext > & xContext,
37 : const Reference< frame::XModel > & xModel,
38 : const Reference< view::XSelectionSupplier > & xSelSupp ) :
39 : impl::StatusBarCommandDispatch_Base( xContext ),
40 : m_xModifiable( xModel, uno::UNO_QUERY ),
41 : m_xSelectionSupplier( xSelSupp ),
42 0 : m_bIsModified( false )
43 0 : {}
44 :
45 0 : StatusBarCommandDispatch::~StatusBarCommandDispatch()
46 0 : {}
47 :
48 0 : void StatusBarCommandDispatch::initialize()
49 : {
50 0 : if( m_xModifiable.is())
51 : {
52 0 : Reference< util::XModifyBroadcaster > xModifyBroadcaster( m_xModifiable, uno::UNO_QUERY );
53 : OSL_ASSERT( xModifyBroadcaster.is());
54 0 : if( xModifyBroadcaster.is())
55 0 : xModifyBroadcaster->addModifyListener( this );
56 : }
57 :
58 0 : if( m_xSelectionSupplier.is())
59 : {
60 0 : m_xSelectionSupplier->addSelectionChangeListener( this );
61 : }
62 0 : }
63 :
64 0 : void StatusBarCommandDispatch::fireStatusEvent(
65 : const OUString & rURL,
66 : const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
67 : {
68 0 : bool bFireAll( rURL.isEmpty() );
69 0 : bool bFireContext( bFireAll || rURL == ".uno:Context" );
70 0 : bool bFireModified( bFireAll || rURL == ".uno:ModifiedStatus" );
71 :
72 0 : if( bFireContext )
73 : {
74 0 : uno::Any aArg;
75 0 : Reference< chart2::XChartDocument > xDoc( m_xModifiable, uno::UNO_QUERY );
76 0 : aArg <<= ObjectNameProvider::getSelectedObjectText( m_aSelectedOID.getObjectCID(), xDoc );
77 0 : fireStatusEventForURL( ".uno:Context", aArg, true, xSingleListener );
78 : }
79 0 : if( bFireModified )
80 : {
81 0 : uno::Any aArg;
82 0 : if( m_bIsModified )
83 0 : aArg <<= OUString("*");
84 0 : fireStatusEventForURL( ".uno:ModifiedStatus", aArg, true, xSingleListener );
85 : }
86 0 : }
87 :
88 : // ____ XDispatch ____
89 0 : void SAL_CALL StatusBarCommandDispatch::dispatch(
90 : const util::URL& /* URL */,
91 : const Sequence< beans::PropertyValue >& /* Arguments */ )
92 : throw (uno::RuntimeException, std::exception)
93 : {
94 : // nothing to do here
95 0 : }
96 :
97 : // ____ WeakComponentImplHelperBase ____
98 : /// is called when this is disposed
99 0 : void SAL_CALL StatusBarCommandDispatch::disposing()
100 : {
101 0 : m_xModifiable.clear();
102 0 : m_xSelectionSupplier.clear();
103 0 : }
104 :
105 : // ____ XEventListener (base of XModifyListener) ____
106 0 : void SAL_CALL StatusBarCommandDispatch::disposing( const lang::EventObject& /* Source */ )
107 : throw (uno::RuntimeException, std::exception)
108 : {
109 0 : m_xModifiable.clear();
110 0 : m_xSelectionSupplier.clear();
111 0 : }
112 :
113 : // ____ XModifyListener ____
114 0 : void SAL_CALL StatusBarCommandDispatch::modified( const lang::EventObject& aEvent )
115 : throw (uno::RuntimeException, std::exception)
116 : {
117 0 : if( m_xModifiable.is())
118 0 : m_bIsModified = m_xModifiable->isModified();
119 :
120 0 : CommandDispatch::modified( aEvent );
121 0 : }
122 :
123 : // ____ XSelectionChangeListener ____
124 0 : void SAL_CALL StatusBarCommandDispatch::selectionChanged( const lang::EventObject& /* aEvent */ )
125 : throw (uno::RuntimeException, std::exception)
126 : {
127 0 : if( m_xSelectionSupplier.is())
128 0 : m_aSelectedOID = ObjectIdentifier( m_xSelectionSupplier->getSelection() );
129 : else
130 0 : m_aSelectedOID = ObjectIdentifier();
131 0 : fireAllStatusEvents( 0 );
132 0 : }
133 :
134 : } // namespace chart
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|