Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / dialogs / RangeSelectionHelper.cxx
blobdf3b1a190ce1aa38aba56df0a87edba9ed242625
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/diagnose_ex.h>
25 using namespace ::com::sun::star;
27 using ::com::sun::star::uno::Reference;
28 using ::com::sun::star::uno::Sequence;
30 namespace chart
33 RangeSelectionHelper::RangeSelectionHelper(
34 const Reference< chart2::XChartDocument > & xChartDocument ) :
35 m_xChartDocument( xChartDocument )
38 RangeSelectionHelper::~RangeSelectionHelper()
41 bool RangeSelectionHelper::hasRangeSelection()
43 return getRangeSelection().is();
46 Reference< sheet::XRangeSelection > const & RangeSelectionHelper::getRangeSelection()
48 if( !m_xRangeSelection.is() &&
49 m_xChartDocument.is() )
51 try
53 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
54 if( xDataProvider.is())
55 m_xRangeSelection.set( xDataProvider->getRangeSelection());
57 catch( const uno::Exception & )
59 DBG_UNHANDLED_EXCEPTION("chart2");
61 m_xRangeSelection.clear();
65 return m_xRangeSelection;
68 void RangeSelectionHelper::raiseRangeSelectionDocument()
70 Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection());
71 if( xRangeSel.is())
73 try
75 // bring document to front
76 Reference< frame::XController > xCtrl( xRangeSel, uno::UNO_QUERY );
77 if( xCtrl.is())
79 Reference< frame::XFrame > xFrame( xCtrl->getFrame());
80 if( xFrame.is())
82 Reference< awt::XTopWindow > xWin( xFrame->getContainerWindow(),
83 uno::UNO_QUERY_THROW );
84 xWin->toFront();
88 catch( const uno::Exception & )
90 DBG_UNHANDLED_EXCEPTION("chart2");
95 bool RangeSelectionHelper::chooseRange(
96 const OUString & aCurrentRange,
97 const OUString & aUIString,
98 RangeSelectionListenerParent & rListenerParent )
100 ControllerLockGuardUNO aGuard( Reference< frame::XModel >(m_xChartDocument, uno::UNO_QUERY ) );
102 bool bResult = true;
103 raiseRangeSelectionDocument();
107 Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection());
108 if( xRangeSel.is())
110 Sequence< beans::PropertyValue > aArgs( 4 );
111 aArgs[0] = beans::PropertyValue(
112 "InitialValue", -1, uno::Any( aCurrentRange ),
113 beans::PropertyState_DIRECT_VALUE );
114 aArgs[1] = beans::PropertyValue(
115 "Title", -1,
116 uno::Any( aUIString ),
117 beans::PropertyState_DIRECT_VALUE );
118 aArgs[2] = beans::PropertyValue(
119 "CloseOnMouseRelease", -1, uno::Any( true ),
120 beans::PropertyState_DIRECT_VALUE );
121 aArgs[3] = beans::PropertyValue(
122 "MultiSelectionMode", -1, uno::Any( true ),
123 beans::PropertyState_DIRECT_VALUE );
125 if( m_xRangeSelectionListener.is() )
126 stopRangeListening();
127 m_xRangeSelectionListener.set( Reference< sheet::XRangeSelectionListener >(
128 new RangeSelectionListener( rListenerParent, aCurrentRange, Reference< frame::XModel >(m_xChartDocument, uno::UNO_QUERY ) )));
130 xRangeSel->addRangeSelectionListener( m_xRangeSelectionListener );
131 xRangeSel->startRangeSelection( aArgs );
134 catch( const uno::Exception & )
136 DBG_UNHANDLED_EXCEPTION("chart2");
137 bResult = false;
140 return bResult;
143 void RangeSelectionHelper::stopRangeListening( bool bRemoveListener /* = true */ )
145 if( bRemoveListener &&
146 m_xRangeSelectionListener.is() &&
147 m_xRangeSelection.is() )
149 m_xRangeSelection->removeRangeSelectionListener( m_xRangeSelectionListener );
152 m_xRangeSelectionListener = nullptr;
155 bool RangeSelectionHelper::verifyCellRange( const OUString & rRangeStr )
157 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
158 if( ! xDataProvider.is())
159 return false;
161 return xDataProvider->createDataSequenceByRangeRepresentationPossible( rRangeStr );
164 bool RangeSelectionHelper::verifyArguments( const Sequence< beans::PropertyValue > & rArguments )
166 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
167 if( ! xDataProvider.is())
168 return false;
170 return xDataProvider->createDataSourcePossible( rArguments );
173 } // namespace chart
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */