/src/libreoffice/chart2/source/controller/dialogs/RangeSelectionHelper.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
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> |
26 | | #include <utility> |
27 | | |
28 | | using namespace ::com::sun::star; |
29 | | |
30 | | using ::com::sun::star::uno::Reference; |
31 | | using ::com::sun::star::uno::Sequence; |
32 | | |
33 | | namespace chart |
34 | | { |
35 | | |
36 | | RangeSelectionHelper::RangeSelectionHelper( |
37 | | rtl::Reference<::chart::ChartModel> xChartDocument ) : |
38 | 0 | m_xChartDocument(std::move( xChartDocument )) |
39 | 0 | {} |
40 | | |
41 | | RangeSelectionHelper::~RangeSelectionHelper() |
42 | 0 | {} |
43 | | |
44 | | bool RangeSelectionHelper::hasRangeSelection() |
45 | 0 | { |
46 | 0 | return getRangeSelection().is(); |
47 | 0 | } |
48 | | |
49 | | Reference< sheet::XRangeSelection > const & RangeSelectionHelper::getRangeSelection() |
50 | 0 | { |
51 | 0 | if( !m_xRangeSelection.is() && |
52 | 0 | m_xChartDocument.is() ) |
53 | 0 | { |
54 | 0 | try |
55 | 0 | { |
56 | 0 | Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider()); |
57 | 0 | if( xDataProvider.is()) |
58 | 0 | m_xRangeSelection.set( xDataProvider->getRangeSelection()); |
59 | 0 | } |
60 | 0 | catch( const uno::Exception & ) |
61 | 0 | { |
62 | 0 | DBG_UNHANDLED_EXCEPTION("chart2"); |
63 | |
|
64 | 0 | m_xRangeSelection.clear(); |
65 | 0 | } |
66 | 0 | } |
67 | |
|
68 | 0 | return m_xRangeSelection; |
69 | 0 | } |
70 | | |
71 | | void RangeSelectionHelper::raiseRangeSelectionDocument() |
72 | 0 | { |
73 | 0 | Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection()); |
74 | 0 | if( !xRangeSel.is()) |
75 | 0 | return; |
76 | | |
77 | 0 | try |
78 | 0 | { |
79 | | // bring document to front |
80 | 0 | Reference< frame::XController > xCtrl( xRangeSel, uno::UNO_QUERY ); |
81 | 0 | if( xCtrl.is()) |
82 | 0 | { |
83 | 0 | Reference< frame::XFrame > xFrame( xCtrl->getFrame()); |
84 | 0 | if( xFrame.is()) |
85 | 0 | { |
86 | 0 | Reference< awt::XTopWindow > xWin( xFrame->getContainerWindow(), |
87 | 0 | uno::UNO_QUERY_THROW ); |
88 | 0 | xWin->toFront(); |
89 | 0 | } |
90 | 0 | } |
91 | 0 | } |
92 | 0 | catch( const uno::Exception & ) |
93 | 0 | { |
94 | 0 | DBG_UNHANDLED_EXCEPTION("chart2"); |
95 | 0 | } |
96 | 0 | } |
97 | | |
98 | | bool RangeSelectionHelper::chooseRange( |
99 | | const OUString & aCurrentRange, |
100 | | const OUString & aUIString, |
101 | | RangeSelectionListenerParent & rListenerParent ) |
102 | 0 | { |
103 | 0 | ControllerLockGuardUNO aGuard( m_xChartDocument ); |
104 | |
|
105 | 0 | bool bResult = true; |
106 | 0 | raiseRangeSelectionDocument(); |
107 | |
|
108 | 0 | try |
109 | 0 | { |
110 | 0 | Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection()); |
111 | 0 | if( xRangeSel.is()) |
112 | 0 | { |
113 | 0 | Sequence< beans::PropertyValue > aArgs{ |
114 | 0 | beans::PropertyValue( |
115 | 0 | u"InitialValue"_ustr, -1, uno::Any( aCurrentRange ), |
116 | 0 | beans::PropertyState_DIRECT_VALUE ), |
117 | 0 | beans::PropertyValue( |
118 | 0 | u"Title"_ustr, -1, |
119 | 0 | uno::Any( aUIString ), |
120 | 0 | beans::PropertyState_DIRECT_VALUE ), |
121 | 0 | beans::PropertyValue( |
122 | 0 | u"CloseOnMouseRelease"_ustr, -1, uno::Any( true ), |
123 | 0 | beans::PropertyState_DIRECT_VALUE ), |
124 | 0 | beans::PropertyValue( |
125 | 0 | u"MultiSelectionMode"_ustr, -1, uno::Any( true ), |
126 | 0 | beans::PropertyState_DIRECT_VALUE ) |
127 | 0 | }; |
128 | 0 | if( m_xRangeSelectionListener.is() ) |
129 | 0 | stopRangeListening(); |
130 | 0 | m_xRangeSelectionListener.set( Reference< sheet::XRangeSelectionListener >( |
131 | 0 | new RangeSelectionListener( rListenerParent, aCurrentRange, m_xChartDocument ))); |
132 | |
|
133 | 0 | xRangeSel->addRangeSelectionListener( m_xRangeSelectionListener ); |
134 | 0 | xRangeSel->startRangeSelection( aArgs ); |
135 | 0 | } |
136 | 0 | } |
137 | 0 | catch( const uno::Exception & ) |
138 | 0 | { |
139 | 0 | DBG_UNHANDLED_EXCEPTION("chart2"); |
140 | 0 | bResult = false; |
141 | 0 | } |
142 | |
|
143 | 0 | return bResult; |
144 | 0 | } |
145 | | |
146 | | void RangeSelectionHelper::stopRangeListening( bool bRemoveListener /* = true */ ) |
147 | 0 | { |
148 | 0 | if( bRemoveListener && |
149 | 0 | m_xRangeSelectionListener.is() && |
150 | 0 | m_xRangeSelection.is() ) |
151 | 0 | { |
152 | 0 | m_xRangeSelection->removeRangeSelectionListener( m_xRangeSelectionListener ); |
153 | 0 | } |
154 | |
|
155 | 0 | m_xRangeSelectionListener = nullptr; |
156 | 0 | } |
157 | | |
158 | | bool RangeSelectionHelper::verifyCellRange( const OUString & rRangeStr ) |
159 | 0 | { |
160 | 0 | Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider()); |
161 | 0 | if( ! xDataProvider.is()) |
162 | 0 | return false; |
163 | | |
164 | 0 | return xDataProvider->createDataSequenceByRangeRepresentationPossible( rRangeStr ); |
165 | 0 | } |
166 | | |
167 | | bool RangeSelectionHelper::verifyArguments( const Sequence< beans::PropertyValue > & rArguments ) |
168 | 0 | { |
169 | 0 | Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider()); |
170 | 0 | if( ! xDataProvider.is()) |
171 | 0 | return false; |
172 | | |
173 | 0 | return xDataProvider->createDataSourcePossible( rArguments ); |
174 | 0 | } |
175 | | |
176 | | } // namespace chart |
177 | | |
178 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |