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/XChartDocument.hpp>
24 #include <com/sun/star/chart2/data/XDataProvider.hpp>
25 #include <tools/diagnose_ex.h>
27 using namespace ::com::sun::star
;
29 using ::com::sun::star::uno::Reference
;
30 using ::com::sun::star::uno::Sequence
;
35 RangeSelectionHelper::RangeSelectionHelper(
36 const Reference
< chart2::XChartDocument
> & xChartDocument
) :
37 m_xChartDocument( xChartDocument
)
40 RangeSelectionHelper::~RangeSelectionHelper()
43 bool RangeSelectionHelper::hasRangeSelection()
45 return getRangeSelection().is();
48 Reference
< sheet::XRangeSelection
> const & RangeSelectionHelper::getRangeSelection()
50 if( !m_xRangeSelection
.is() &&
51 m_xChartDocument
.is() )
55 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
56 if( xDataProvider
.is())
57 m_xRangeSelection
.set( xDataProvider
->getRangeSelection());
59 catch( const uno::Exception
& )
61 DBG_UNHANDLED_EXCEPTION("chart2");
63 m_xRangeSelection
.clear();
67 return m_xRangeSelection
;
70 void RangeSelectionHelper::raiseRangeSelectionDocument()
72 Reference
< sheet::XRangeSelection
> xRangeSel( getRangeSelection());
77 // bring document to front
78 Reference
< frame::XController
> xCtrl( xRangeSel
, uno::UNO_QUERY
);
81 Reference
< frame::XFrame
> xFrame( xCtrl
->getFrame());
84 Reference
< awt::XTopWindow
> xWin( xFrame
->getContainerWindow(),
85 uno::UNO_QUERY_THROW
);
90 catch( const uno::Exception
& )
92 DBG_UNHANDLED_EXCEPTION("chart2");
97 bool RangeSelectionHelper::chooseRange(
98 const OUString
& aCurrentRange
,
99 const OUString
& aUIString
,
100 RangeSelectionListenerParent
& rListenerParent
)
102 ControllerLockGuardUNO
aGuard( m_xChartDocument
);
105 raiseRangeSelectionDocument();
109 Reference
< sheet::XRangeSelection
> xRangeSel( getRangeSelection());
112 Sequence
< beans::PropertyValue
> aArgs( 4 );
113 aArgs
[0] = beans::PropertyValue(
114 "InitialValue", -1, uno::Any( aCurrentRange
),
115 beans::PropertyState_DIRECT_VALUE
);
116 aArgs
[1] = beans::PropertyValue(
118 uno::Any( aUIString
),
119 beans::PropertyState_DIRECT_VALUE
);
120 aArgs
[2] = beans::PropertyValue(
121 "CloseOnMouseRelease", -1, uno::Any( true ),
122 beans::PropertyState_DIRECT_VALUE
);
123 aArgs
[3] = beans::PropertyValue(
124 "MultiSelectionMode", -1, uno::Any( true ),
125 beans::PropertyState_DIRECT_VALUE
);
127 if( m_xRangeSelectionListener
.is() )
128 stopRangeListening();
129 m_xRangeSelectionListener
.set( Reference
< sheet::XRangeSelectionListener
>(
130 new RangeSelectionListener( rListenerParent
, aCurrentRange
, m_xChartDocument
)));
132 xRangeSel
->addRangeSelectionListener( m_xRangeSelectionListener
);
133 xRangeSel
->startRangeSelection( aArgs
);
136 catch( const uno::Exception
& )
138 DBG_UNHANDLED_EXCEPTION("chart2");
145 void RangeSelectionHelper::stopRangeListening( bool bRemoveListener
/* = true */ )
147 if( bRemoveListener
&&
148 m_xRangeSelectionListener
.is() &&
149 m_xRangeSelection
.is() )
151 m_xRangeSelection
->removeRangeSelectionListener( m_xRangeSelectionListener
);
154 m_xRangeSelectionListener
= nullptr;
157 bool RangeSelectionHelper::verifyCellRange( const OUString
& rRangeStr
)
159 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
160 if( ! xDataProvider
.is())
163 return xDataProvider
->createDataSequenceByRangeRepresentationPossible( rRangeStr
);
166 bool RangeSelectionHelper::verifyArguments( const Sequence
< beans::PropertyValue
> & rArguments
)
168 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
169 if( ! xDataProvider
.is())
172 return xDataProvider
->createDataSourcePossible( rArguments
);
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */