| 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 <com/sun/star/view/XSelectionSupplier.hpp> |
| 23 |
#include <ChartModel.hxx> |
| 24 |
#include <utility> |
| 25 |
|
| 26 |
using namespace ::com::sun::star; |
| 27 |
|
| 28 |
using ::com::sun::star::uno::Reference; |
| 29 |
using ::com::sun::star::uno::Sequence; |
| 30 |
|
| 31 |
namespace chart |
| 32 |
{ |
| 33 |
|
| 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 ) |
| 42 |
{} |
| 43 |
|
| 44 |
StatusBarCommandDispatch::~StatusBarCommandDispatch() |
| 45 |
{} |
| 46 |
|
| 47 |
void StatusBarCommandDispatch::initialize() |
| 48 |
{ |
| 49 |
if( m_xChartModel.is()) |
| 50 |
{ |
| 51 |
m_xChartModel->addModifyListener( this ); |
| 52 |
} |
| 53 |
|
| 54 |
if( m_xSelectionSupplier.is()) |
| 55 |
{ |
| 56 |
m_xSelectionSupplier->addSelectionChangeListener( this ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
void StatusBarCommandDispatch::fireStatusEvent( |
| 61 |
const OUString & rURL, |
| 62 |
const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ ) |
| 63 |
{ |
| 64 |
bool bFireAll( rURL.isEmpty() ); |
| 65 |
bool bFireContext( bFireAll || rURL == ".uno:Context" ); |
| 66 |
bool bFireModified( bFireAll || rURL == ".uno:ModifiedStatus" ); |
| 67 |
|
| 68 |
if( bFireContext && m_xChartModel.is()) |
| 69 |
{ |
| 70 |
uno::Any aArg; |
| 71 |
aArg <<= ObjectNameProvider::getSelectedObjectText( m_aSelectedOID.getObjectCID(), m_xChartModel ); |
| 72 |
fireStatusEventForURL( u".uno:Context"_ustr, aArg, true, xSingleListener ); |
| 73 |
} |
| 74 |
if( bFireModified ) |
| 75 |
{ |
| 76 |
uno::Any aArg; |
| 77 |
if( m_bIsModified ) |
| 78 |
aArg <<= u"*"_ustr; |
| 79 |
fireStatusEventForURL( u".uno:ModifiedStatus"_ustr, aArg, true, xSingleListener ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
// ____ XDispatch ____ |
| 84 |
void SAL_CALL StatusBarCommandDispatch::dispatch( |
| 85 |
const util::URL& /* URL */, |
| 86 |
const Sequence< beans::PropertyValue >& /* Arguments */ ) |
| 87 |
{ |
| 88 |
// nothing to do here |
| 89 |
} |
| 90 |
|
| 91 |
// ____ WeakComponentImplHelperBase ____ |
| 92 |
/// is called when this is disposed |
| 93 |
void StatusBarCommandDispatch::disposing(std::unique_lock<std::mutex>& /*rGuard*/) |
| 94 |
{ |
| 95 |
m_xChartModel.clear(); |
| 96 |
m_xSelectionSupplier.clear(); |
| 97 |
} |
| 98 |
|
| 99 |
// ____ XEventListener (base of XModifyListener) ____ |
| 100 |
void SAL_CALL StatusBarCommandDispatch::disposing( const lang::EventObject& /* Source */ ) |
| 101 |
{ |
| 102 |
m_xChartModel.clear(); |
| 103 |
m_xSelectionSupplier.clear(); |
| 104 |
} |
| 105 |
|
| 106 |
// ____ XModifyListener ____ |
| 107 |
void SAL_CALL StatusBarCommandDispatch::modified( const lang::EventObject& aEvent ) |
| 108 |
{ |
| 109 |
if( m_xChartModel.is()) |
| 110 |
m_bIsModified = m_xChartModel->isModified(); |
| 111 |
|
| 112 |
CommandDispatch::modified( aEvent ); |
| 113 |
} |
| 114 |
|
| 115 |
// ____ XSelectionChangeListener ____ |
| 116 |
void SAL_CALL StatusBarCommandDispatch::selectionChanged( const lang::EventObject& /* aEvent */ ) |
| 117 |
{ |
| 118 |
if( m_xSelectionSupplier.is()) |
| 119 |
m_aSelectedOID = ObjectIdentifier( m_xSelectionSupplier->getSelection() ); |
| 120 |
else |
| 121 |
m_aSelectedOID = ObjectIdentifier(); |
| 122 |
fireAllStatusEvents( nullptr ); |
| 123 |
} |
| 124 |
|
| 125 |
} // namespace chart |
| 126 |
|
| 127 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |