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