fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / RangeSelectionHelper.cxx
blobb2fd8fb31a6240f7dcd74286a03c41c187eb7293
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 "macros.hxx"
23 #include "ControllerLockGuard.hxx"
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <com/sun/star/awt/XTopWindow.hpp>
26 #include <com/sun/star/text/XText.hpp>
27 #include <com/sun/star/embed/XEmbeddedObject.hpp>
28 #include <com/sun/star/embed/EmbedStates.hpp>
29 #include <com/sun/star/embed/XComponentSupplier.hpp>
30 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
31 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
32 #include <com/sun/star/sheet/XCellRangesAccess.hpp>
33 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
34 #include <rtl/ustrbuf.hxx>
36 using namespace ::com::sun::star;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
41 namespace chart
44 RangeSelectionHelper::RangeSelectionHelper(
45 const Reference< chart2::XChartDocument > & xChartDocument ) :
46 m_xChartDocument( xChartDocument )
49 RangeSelectionHelper::~RangeSelectionHelper()
52 bool RangeSelectionHelper::hasRangeSelection()
54 return getRangeSelection().is();
57 Reference< sheet::XRangeSelection > RangeSelectionHelper::getRangeSelection()
59 if( !m_xRangeSelection.is() &&
60 m_xChartDocument.is() )
62 try
64 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
65 if( xDataProvider.is())
66 m_xRangeSelection.set( xDataProvider->getRangeSelection());
68 catch( const uno::Exception & ex )
70 ASSERT_EXCEPTION( ex );
72 m_xRangeSelection.clear();
76 return m_xRangeSelection;
79 void RangeSelectionHelper::raiseRangeSelectionDocument()
81 Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection());
82 if( xRangeSel.is())
84 try
86 // bring document to front
87 Reference< frame::XController > xCtrl( xRangeSel, uno::UNO_QUERY );
88 if( xCtrl.is())
90 Reference< frame::XFrame > xFrame( xCtrl->getFrame());
91 if( xFrame.is())
93 Reference< awt::XTopWindow > xWin( xFrame->getContainerWindow(),
94 uno::UNO_QUERY_THROW );
95 xWin->toFront();
99 catch( const uno::Exception & ex )
101 ASSERT_EXCEPTION( ex );
106 bool RangeSelectionHelper::chooseRange(
107 const OUString & aCurrentRange,
108 const OUString & aUIString,
109 RangeSelectionListenerParent & rListenerParent )
111 ControllerLockGuardUNO aGuard( Reference< frame::XModel >(m_xChartDocument, uno::UNO_QUERY ) );
113 bool bResult = true;
114 raiseRangeSelectionDocument();
118 Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection());
119 if( xRangeSel.is())
121 Sequence< beans::PropertyValue > aArgs( 4 );
122 aArgs[0] = beans::PropertyValue(
123 "InitialValue", -1, uno::makeAny( aCurrentRange ),
124 beans::PropertyState_DIRECT_VALUE );
125 aArgs[1] = beans::PropertyValue(
126 "Title", -1,
127 uno::makeAny( aUIString ),
128 beans::PropertyState_DIRECT_VALUE );
129 aArgs[2] = beans::PropertyValue(
130 "CloseOnMouseRelease", -1, uno::makeAny( true ),
131 beans::PropertyState_DIRECT_VALUE );
132 aArgs[3] = beans::PropertyValue(
133 "MultiSelectionMode", -1, uno::makeAny( true ),
134 beans::PropertyState_DIRECT_VALUE );
136 if( m_xRangeSelectionListener.is() )
137 stopRangeListening();
138 m_xRangeSelectionListener.set( Reference< sheet::XRangeSelectionListener >(
139 new RangeSelectionListener( rListenerParent, aCurrentRange, Reference< frame::XModel >(m_xChartDocument, uno::UNO_QUERY ) )));
141 xRangeSel->addRangeSelectionListener( m_xRangeSelectionListener );
142 xRangeSel->startRangeSelection( aArgs );
145 catch( const uno::Exception & ex )
147 bResult = false;
148 ASSERT_EXCEPTION( ex );
151 return bResult;
154 void RangeSelectionHelper::stopRangeListening( bool bRemoveListener /* = true */ )
156 if( bRemoveListener &&
157 m_xRangeSelectionListener.is() &&
158 m_xRangeSelection.is() )
160 m_xRangeSelection->removeRangeSelectionListener( m_xRangeSelectionListener );
163 m_xRangeSelectionListener = 0;
166 bool RangeSelectionHelper::verifyCellRange( const OUString & rRangeStr )
168 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
169 if( ! xDataProvider.is())
170 return false;
172 return xDataProvider->createDataSequenceByRangeRepresentationPossible( rRangeStr );
175 bool RangeSelectionHelper::verifyArguments( const Sequence< beans::PropertyValue > & rArguments )
177 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
178 if( ! xDataProvider.is())
179 return false;
181 return xDataProvider->createDataSourcePossible( rArguments );
184 } // namespace chart
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */