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 <RangeSelectionHelper.hxx>
21 #include <RangeSelectionListener.hxx>
22 #include <com/sun/star/awt/XTopWindow.hpp>
23 #include <com/sun/star/chart2/data/XDataProvider.hpp>
24 #include <comphelper/diagnose_ex.hxx>
25 #include <ChartModel.hxx>
28 using namespace ::com::sun::star
;
30 using ::com::sun::star::uno::Reference
;
31 using ::com::sun::star::uno::Sequence
;
36 RangeSelectionHelper::RangeSelectionHelper(
37 rtl::Reference
<::chart::ChartModel
> xChartDocument
) :
38 m_xChartDocument(std::move( xChartDocument
))
41 RangeSelectionHelper::~RangeSelectionHelper()
44 bool RangeSelectionHelper::hasRangeSelection()
46 return getRangeSelection().is();
49 Reference
< sheet::XRangeSelection
> const & RangeSelectionHelper::getRangeSelection()
51 if( !m_xRangeSelection
.is() &&
52 m_xChartDocument
.is() )
56 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
57 if( xDataProvider
.is())
58 m_xRangeSelection
.set( xDataProvider
->getRangeSelection());
60 catch( const uno::Exception
& )
62 DBG_UNHANDLED_EXCEPTION("chart2");
64 m_xRangeSelection
.clear();
68 return m_xRangeSelection
;
71 void RangeSelectionHelper::raiseRangeSelectionDocument()
73 Reference
< sheet::XRangeSelection
> xRangeSel( getRangeSelection());
79 // bring document to front
80 Reference
< frame::XController
> xCtrl( xRangeSel
, uno::UNO_QUERY
);
83 Reference
< frame::XFrame
> xFrame( xCtrl
->getFrame());
86 Reference
< awt::XTopWindow
> xWin( xFrame
->getContainerWindow(),
87 uno::UNO_QUERY_THROW
);
92 catch( const uno::Exception
& )
94 DBG_UNHANDLED_EXCEPTION("chart2");
98 bool RangeSelectionHelper::chooseRange(
99 const OUString
& aCurrentRange
,
100 const OUString
& aUIString
,
101 RangeSelectionListenerParent
& rListenerParent
)
103 ControllerLockGuardUNO
aGuard( m_xChartDocument
);
106 raiseRangeSelectionDocument();
110 Reference
< sheet::XRangeSelection
> xRangeSel( getRangeSelection());
113 Sequence
< beans::PropertyValue
> aArgs
{
114 beans::PropertyValue(
115 u
"InitialValue"_ustr
, -1, uno::Any( aCurrentRange
),
116 beans::PropertyState_DIRECT_VALUE
),
117 beans::PropertyValue(
119 uno::Any( aUIString
),
120 beans::PropertyState_DIRECT_VALUE
),
121 beans::PropertyValue(
122 u
"CloseOnMouseRelease"_ustr
, -1, uno::Any( true ),
123 beans::PropertyState_DIRECT_VALUE
),
124 beans::PropertyValue(
125 u
"MultiSelectionMode"_ustr
, -1, uno::Any( true ),
126 beans::PropertyState_DIRECT_VALUE
)
128 if( m_xRangeSelectionListener
.is() )
129 stopRangeListening();
130 m_xRangeSelectionListener
.set( Reference
< sheet::XRangeSelectionListener
>(
131 new RangeSelectionListener( rListenerParent
, aCurrentRange
, m_xChartDocument
)));
133 xRangeSel
->addRangeSelectionListener( m_xRangeSelectionListener
);
134 xRangeSel
->startRangeSelection( aArgs
);
137 catch( const uno::Exception
& )
139 DBG_UNHANDLED_EXCEPTION("chart2");
146 void RangeSelectionHelper::stopRangeListening( bool bRemoveListener
/* = true */ )
148 if( bRemoveListener
&&
149 m_xRangeSelectionListener
.is() &&
150 m_xRangeSelection
.is() )
152 m_xRangeSelection
->removeRangeSelectionListener( m_xRangeSelectionListener
);
155 m_xRangeSelectionListener
= nullptr;
158 bool RangeSelectionHelper::verifyCellRange( const OUString
& rRangeStr
)
160 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
161 if( ! xDataProvider
.is())
164 return xDataProvider
->createDataSequenceByRangeRepresentationPossible( rRangeStr
);
167 bool RangeSelectionHelper::verifyArguments( const Sequence
< beans::PropertyValue
> & rArguments
)
169 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
170 if( ! xDataProvider
.is())
173 return xDataProvider
->createDataSourcePossible( rArguments
);
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */