LibreOffice Module chart2 (master) 1
RangeSelectionHelper.cxx
Go to the documentation of this file.
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
22#include <com/sun/star/awt/XTopWindow.hpp>
23#include <com/sun/star/chart2/data/XDataProvider.hpp>
25#include <ChartModel.hxx>
26#include <utility>
27
28using namespace ::com::sun::star;
29
30using ::com::sun::star::uno::Reference;
31using ::com::sun::star::uno::Sequence;
32
33namespace chart
34{
35
38 m_xChartDocument(std::move( xChartDocument ))
39{}
40
42{}
43
45{
46 return getRangeSelection().is();
47}
48
50{
51 if( !m_xRangeSelection.is() &&
52 m_xChartDocument.is() )
53 {
54 try
55 {
56 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
57 if( xDataProvider.is())
58 m_xRangeSelection.set( xDataProvider->getRangeSelection());
59 }
60 catch( const uno::Exception & )
61 {
63
64 m_xRangeSelection.clear();
65 }
66 }
67
68 return m_xRangeSelection;
69}
70
72{
74 if( !xRangeSel.is())
75 return;
76
77 try
78 {
79 // bring document to front
80 Reference< frame::XController > xCtrl( xRangeSel, uno::UNO_QUERY );
81 if( xCtrl.is())
82 {
83 Reference< frame::XFrame > xFrame( xCtrl->getFrame());
84 if( xFrame.is())
85 {
86 Reference< awt::XTopWindow > xWin( xFrame->getContainerWindow(),
87 uno::UNO_QUERY_THROW );
88 xWin->toFront();
89 }
90 }
91 }
92 catch( const uno::Exception & )
93 {
95 }
96}
97
99 const OUString & aCurrentRange,
100 const OUString & aUIString,
101 RangeSelectionListenerParent & rListenerParent )
102{
104
105 bool bResult = true;
107
108 try
109 {
111 if( xRangeSel.is())
112 {
114 beans::PropertyValue(
115 "InitialValue", -1, uno::Any( aCurrentRange ),
116 beans::PropertyState_DIRECT_VALUE ),
117 beans::PropertyValue(
118 "Title", -1,
119 uno::Any( aUIString ),
120 beans::PropertyState_DIRECT_VALUE ),
121 beans::PropertyValue(
122 "CloseOnMouseRelease", -1, uno::Any( true ),
123 beans::PropertyState_DIRECT_VALUE ),
124 beans::PropertyValue(
125 "MultiSelectionMode", -1, uno::Any( true ),
126 beans::PropertyState_DIRECT_VALUE )
127 };
131 new RangeSelectionListener( rListenerParent, aCurrentRange, m_xChartDocument )));
132
133 xRangeSel->addRangeSelectionListener( m_xRangeSelectionListener );
134 xRangeSel->startRangeSelection( aArgs );
135 }
136 }
137 catch( const uno::Exception & )
138 {
139 DBG_UNHANDLED_EXCEPTION("chart2");
140 bResult = false;
141 }
142
143 return bResult;
144}
145
146void RangeSelectionHelper::stopRangeListening( bool bRemoveListener /* = true */ )
147{
148 if( bRemoveListener &&
150 m_xRangeSelection.is() )
151 {
152 m_xRangeSelection->removeRangeSelectionListener( m_xRangeSelectionListener );
153 }
154
156}
157
158bool RangeSelectionHelper::verifyCellRange( const OUString & rRangeStr )
159{
160 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
161 if( ! xDataProvider.is())
162 return false;
163
164 return xDataProvider->createDataSequenceByRangeRepresentationPossible( rRangeStr );
165}
166
168{
169 Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
170 if( ! xDataProvider.is())
171 return false;
172
173 return xDataProvider->createDataSourcePossible( rArguments );
174}
175
176} // namespace chart
177
178/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
rtl::Reference<::chart::ChartModel > m_xChartDocument
bool chooseRange(const OUString &aCurrentRange, const OUString &aUIString, RangeSelectionListenerParent &rListenerParent)
void stopRangeListening(bool bRemoveListener=true)
css::uno::Reference< css::sheet::XRangeSelectionListener > m_xRangeSelectionListener
bool verifyCellRange(const OUString &rRangeStr)
css::uno::Reference< css::sheet::XRangeSelection > m_xRangeSelection
css::uno::Reference< css::sheet::XRangeSelection > const & getRangeSelection()
RangeSelectionHelper(rtl::Reference<::chart::ChartModel > xChartDocument)
bool verifyArguments(const css::uno::Sequence< css::beans::PropertyValue > &rArguments)
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XFrame > xFrame