| 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 |
m_xChartDocument(std::move( xChartDocument )) |
| 39 |
{} |
| 40 |
|
| 41 |
RangeSelectionHelper::~RangeSelectionHelper() |
| 42 |
{} |
| 43 |
|
| 44 |
bool RangeSelectionHelper::hasRangeSelection() |
| 45 |
{ |
| 46 |
return getRangeSelection().is(); |
| 47 |
} |
| 48 |
|
| 49 |
Reference< sheet::XRangeSelection > const & RangeSelectionHelper::getRangeSelection() |
| 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 |
{ |
| 62 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 63 |
|
| 64 |
m_xRangeSelection.clear(); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return m_xRangeSelection; |
| 69 |
} |
| 70 |
|
| 71 |
void RangeSelectionHelper::raiseRangeSelectionDocument() |
| 72 |
{ |
| 73 |
Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection()); |
| 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 |
{ |
| 94 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
bool RangeSelectionHelper::chooseRange( |
| 99 |
const OUString & aCurrentRange, |
| 100 |
const OUString & aUIString, |
| 101 |
RangeSelectionListenerParent & rListenerParent ) |
| 102 |
{ |
| 103 |
ControllerLockGuardUNO aGuard( m_xChartDocument ); |
| 104 |
|
| 105 |
bool bResult = true; |
| 106 |
raiseRangeSelectionDocument(); |
| 107 |
|
| 108 |
try |
| 109 |
{ |
| 110 |
Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection()); |
| 111 |
if( xRangeSel.is()) |
| 112 |
{ |
| 113 |
Sequence< beans::PropertyValue > aArgs{ |
| 114 |
beans::PropertyValue( |
| 115 |
u"InitialValue"_ustr, -1, uno::Any( aCurrentRange ), |
| 116 |
beans::PropertyState_DIRECT_VALUE ), |
| 117 |
beans::PropertyValue( |
| 118 |
u"Title"_ustr, -1, |
| 119 |
uno::Any( aUIString ), |
| 120 |
beans::PropertyState_DIRECT_VALUE ), |
| 121 |
beans::PropertyValue( |
| 122 |
u"CloseOnMouseRelease"_ustr, -1, uno::Any( true ), |
| 123 |
beans::PropertyState_DIRECT_VALUE ), |
| 124 |
beans::PropertyValue( |
| 125 |
u"MultiSelectionMode"_ustr, -1, uno::Any( true ), |
| 126 |
beans::PropertyState_DIRECT_VALUE ) |
| 127 |
}; |
| 128 |
if( m_xRangeSelectionListener.is() ) |
| 129 |
stopRangeListening(); |
| 130 |
m_xRangeSelectionListener.set( Reference< sheet::XRangeSelectionListener >( |
| 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 |
|
| 146 |
void RangeSelectionHelper::stopRangeListening( bool bRemoveListener /* = true */ ) |
| 147 |
{ |
| 148 |
if( bRemoveListener && |
| 149 |
m_xRangeSelectionListener.is() && |
| 150 |
m_xRangeSelection.is() ) |
| 151 |
{ |
| 152 |
m_xRangeSelection->removeRangeSelectionListener( m_xRangeSelectionListener ); |
| 153 |
} |
| 154 |
|
| 155 |
m_xRangeSelectionListener = nullptr; |
| 156 |
} |
| 157 |
|
| 158 |
bool 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 |
|
| 167 |
bool RangeSelectionHelper::verifyArguments( const Sequence< beans::PropertyValue > & rArguments ) |
| 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: */ |