1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "StatusBarCommandDispatch.hxx"
21 #include <ObjectNameProvider.hxx>
22 #include <com/sun/star/view/XSelectionSupplier.hpp>
23 #include <ChartModel.hxx>
26 using namespace ::com::sun::star
;
28 using ::com::sun::star::uno::Reference
;
29 using ::com::sun::star::uno::Sequence
;
34 StatusBarCommandDispatch::StatusBarCommandDispatch(
35 const Reference
< uno::XComponentContext
> & xContext
,
36 rtl::Reference
<::chart::ChartModel
> xModel
,
37 const Reference
< view::XSelectionSupplier
> & xSelSupp
) :
38 impl::StatusBarCommandDispatch_Base( xContext
),
39 m_xChartModel(std::move( xModel
)),
40 m_xSelectionSupplier( xSelSupp
),
41 m_bIsModified( false )
44 StatusBarCommandDispatch::~StatusBarCommandDispatch()
47 void StatusBarCommandDispatch::initialize()
49 if( m_xChartModel
.is())
51 m_xChartModel
->addModifyListener( this );
54 if( m_xSelectionSupplier
.is())
56 m_xSelectionSupplier
->addSelectionChangeListener( this );
60 void StatusBarCommandDispatch::fireStatusEvent(
61 const OUString
& rURL
,
62 const Reference
< frame::XStatusListener
> & xSingleListener
/* = 0 */ )
64 bool bFireAll( rURL
.isEmpty() );
65 bool bFireContext( bFireAll
|| rURL
== ".uno:Context" );
66 bool bFireModified( bFireAll
|| rURL
== ".uno:ModifiedStatus" );
68 if( bFireContext
&& m_xChartModel
.is())
71 aArg
<<= ObjectNameProvider::getSelectedObjectText( m_aSelectedOID
.getObjectCID(), m_xChartModel
);
72 fireStatusEventForURL( u
".uno:Context"_ustr
, aArg
, true, xSingleListener
);
79 fireStatusEventForURL( u
".uno:ModifiedStatus"_ustr
, aArg
, true, xSingleListener
);
83 // ____ XDispatch ____
84 void SAL_CALL
StatusBarCommandDispatch::dispatch(
85 const util::URL
& /* URL */,
86 const Sequence
< beans::PropertyValue
>& /* Arguments */ )
91 // ____ WeakComponentImplHelperBase ____
92 /// is called when this is disposed
93 void StatusBarCommandDispatch::disposing(std::unique_lock
<std::mutex
>& /*rGuard*/)
95 m_xChartModel
.clear();
96 m_xSelectionSupplier
.clear();
99 // ____ XEventListener (base of XModifyListener) ____
100 void SAL_CALL
StatusBarCommandDispatch::disposing( const lang::EventObject
& /* Source */ )
102 m_xChartModel
.clear();
103 m_xSelectionSupplier
.clear();
106 // ____ XModifyListener ____
107 void SAL_CALL
StatusBarCommandDispatch::modified( const lang::EventObject
& aEvent
)
109 if( m_xChartModel
.is())
110 m_bIsModified
= m_xChartModel
->isModified();
112 CommandDispatch::modified( aEvent
);
115 // ____ XSelectionChangeListener ____
116 void SAL_CALL
StatusBarCommandDispatch::selectionChanged( const lang::EventObject
& /* aEvent */ )
118 if( m_xSelectionSupplier
.is())
119 m_aSelectedOID
= ObjectIdentifier( m_xSelectionSupplier
->getSelection() );
121 m_aSelectedOID
= ObjectIdentifier();
122 fireAllStatusEvents( nullptr );
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */