1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RangeSelectionHelper.cxx,v $
10 * $Revision: 1.4.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "RangeSelectionHelper.hxx"
35 #include "RangeSelectionListener.hxx"
37 #include "ControllerLockGuard.hxx"
38 #include <com/sun/star/frame/XModel.hpp>
39 #include <com/sun/star/awt/XTopWindow.hpp>
40 #include <com/sun/star/text/XText.hpp>
41 #include <com/sun/star/embed/XEmbeddedObject.hpp>
42 #include <com/sun/star/embed/EmbedStates.hpp>
43 #include <com/sun/star/embed/XComponentSupplier.hpp>
44 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
45 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
46 #include <com/sun/star/sheet/XCellRangesAccess.hpp>
47 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
48 #include <rtl/ustrbuf.hxx>
50 using namespace ::com::sun::star
;
52 using ::com::sun::star::uno::Reference
;
53 using ::com::sun::star::uno::Sequence
;
54 using ::rtl::OUString
;
56 // ----------------------------------------
61 RangeSelectionHelper::RangeSelectionHelper(
62 const Reference
< chart2::XChartDocument
> & xChartDocument
) :
63 m_xChartDocument( xChartDocument
)
66 RangeSelectionHelper::~RangeSelectionHelper()
69 bool RangeSelectionHelper::hasRangeSelection()
71 return getRangeSelection().is();
74 Reference
< sheet::XRangeSelection
> RangeSelectionHelper::getRangeSelection()
76 if( !m_xRangeSelection
.is() &&
77 m_xChartDocument
.is() )
81 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
82 if( xDataProvider
.is())
83 m_xRangeSelection
.set( xDataProvider
->getRangeSelection());
85 catch( uno::Exception
& ex
)
87 ASSERT_EXCEPTION( ex
);
89 m_xRangeSelection
.clear();
93 return m_xRangeSelection
;
96 void RangeSelectionHelper::raiseRangeSelectionDocument()
98 Reference
< sheet::XRangeSelection
> xRangeSel( getRangeSelection());
103 // bring document to front
104 Reference
< frame::XController
> xCtrl( xRangeSel
, uno::UNO_QUERY
);
107 Reference
< frame::XFrame
> xFrame( xCtrl
->getFrame());
110 Reference
< awt::XTopWindow
> xWin( xFrame
->getContainerWindow(),
111 uno::UNO_QUERY_THROW
);
116 catch( uno::Exception
& ex
)
118 ASSERT_EXCEPTION( ex
);
123 bool RangeSelectionHelper::chooseRange(
124 const OUString
& aCurrentRange
,
125 const OUString
& aUIString
,
126 RangeSelectionListenerParent
& rListenerParent
)
128 ControllerLockGuard
aGuard( Reference
< frame::XModel
>(m_xChartDocument
, uno::UNO_QUERY
) );
131 raiseRangeSelectionDocument();
135 Reference
< sheet::XRangeSelection
> xRangeSel( getRangeSelection());
138 Sequence
< beans::PropertyValue
> aArgs( 4 );
139 aArgs
[0] = beans::PropertyValue(
140 C2U("InitialValue"), -1, uno::makeAny( aCurrentRange
),
141 beans::PropertyState_DIRECT_VALUE
);
142 aArgs
[1] = beans::PropertyValue(
144 uno::makeAny( aUIString
),
145 beans::PropertyState_DIRECT_VALUE
);
146 aArgs
[2] = beans::PropertyValue(
147 C2U("CloseOnMouseRelease"), -1, uno::makeAny( true ),
148 beans::PropertyState_DIRECT_VALUE
);
149 aArgs
[3] = beans::PropertyValue(
150 C2U("MultiSelectionMode"), -1, uno::makeAny( true ),
151 beans::PropertyState_DIRECT_VALUE
);
153 if( m_xRangeSelectionListener
.is() )
154 stopRangeListening();
155 m_xRangeSelectionListener
.set( Reference
< sheet::XRangeSelectionListener
>(
156 new RangeSelectionListener( rListenerParent
, aCurrentRange
, Reference
< frame::XModel
>(m_xChartDocument
, uno::UNO_QUERY
) )));
158 xRangeSel
->addRangeSelectionListener( m_xRangeSelectionListener
);
159 xRangeSel
->startRangeSelection( aArgs
);
162 catch( uno::Exception
& ex
)
165 ASSERT_EXCEPTION( ex
);
171 void RangeSelectionHelper::stopRangeListening( bool bRemoveListener
/* = true */ )
173 if( bRemoveListener
&&
174 m_xRangeSelectionListener
.is() &&
175 m_xRangeSelection
.is() )
177 m_xRangeSelection
->removeRangeSelectionListener( m_xRangeSelectionListener
);
180 m_xRangeSelectionListener
= 0;
183 bool RangeSelectionHelper::verifyCellRange( const OUString
& rRangeStr
)
185 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
186 if( ! xDataProvider
.is())
189 return xDataProvider
->createDataSequenceByRangeRepresentationPossible( rRangeStr
);
192 bool RangeSelectionHelper::verifyArguments( const Sequence
< beans::PropertyValue
> & rArguments
)
194 Reference
< chart2::data::XDataProvider
> xDataProvider( m_xChartDocument
->getDataProvider());
195 if( ! xDataProvider
.is())
198 return xDataProvider
->createDataSourcePossible( rArguments
);