| 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 <sal/config.h> |
| 21 |
|
| 22 |
#include <string_view> |
| 23 |
|
| 24 |
#include <ChartController.hxx> |
| 25 |
#include <ChartView.hxx> |
| 26 |
#include <PositionAndSizeHelper.hxx> |
| 27 |
#include <ObjectIdentifier.hxx> |
| 28 |
#include <ChartWindow.hxx> |
| 29 |
#include <ResId.hxx> |
| 30 |
#include <ChartModel.hxx> |
| 31 |
#include <ChartType.hxx> |
| 32 |
#include <DiagramHelper.hxx> |
| 33 |
#include <Diagram.hxx> |
| 34 |
#include <TitleHelper.hxx> |
| 35 |
#include "UndoGuard.hxx" |
| 36 |
#include <ControllerLockGuard.hxx> |
| 37 |
#include <ObjectNameProvider.hxx> |
| 38 |
#include <strings.hrc> |
| 39 |
#include "DragMethod_PieSegment.hxx" |
| 40 |
#include "DragMethod_RotateDiagram.hxx" |
| 41 |
#include <ObjectHierarchy.hxx> |
| 42 |
#include <RelativePositionHelper.hxx> |
| 43 |
#include <chartview/DrawModelWrapper.hxx> |
| 44 |
#include <RegressionCurveHelper.hxx> |
| 45 |
#include <RegressionCurveModel.hxx> |
| 46 |
#include <StatisticsHelper.hxx> |
| 47 |
#include <DataSeries.hxx> |
| 48 |
#include <DataSeriesProperties.hxx> |
| 49 |
#include <Axis.hxx> |
| 50 |
#include <AxisHelper.hxx> |
| 51 |
#include <LegendHelper.hxx> |
| 52 |
#include <servicenames_charttypes.hxx> |
| 53 |
#include "DrawCommandDispatch.hxx" |
| 54 |
#include <PopupRequest.hxx> |
| 55 |
#include <ControllerCommandDispatch.hxx> |
| 56 |
|
| 57 |
#include <com/sun/star/chart2/RelativePosition.hpp> |
| 58 |
#include <com/sun/star/chart2/RelativeSize.hpp> |
| 59 |
|
| 60 |
#include <com/sun/star/awt/PopupMenuDirection.hpp> |
| 61 |
#include <com/sun/star/frame/DispatchHelper.hpp> |
| 62 |
#include <com/sun/star/frame/FrameSearchFlag.hpp> |
| 63 |
#include <com/sun/star/frame/XPopupMenuController.hpp> |
| 64 |
#include <com/sun/star/awt/Rectangle.hpp> |
| 65 |
|
| 66 |
#include <chart2/AbstractPivotTableDataProvider.hxx> |
| 67 |
#include <comphelper/lok.hxx> |
| 68 |
#include <comphelper/propertysequence.hxx> |
| 69 |
#include <comphelper/propertyvalue.hxx> |
| 70 |
|
| 71 |
#include <sfx2/viewsh.hxx> |
| 72 |
#include <svx/ActionDescriptionProvider.hxx> |
| 73 |
#include <svx/obj3d.hxx> |
| 74 |
#include <svx/scene3d.hxx> |
| 75 |
#include <svx/svddrgmt.hxx> |
| 76 |
#include <vcl/commandevent.hxx> |
| 77 |
#include <vcl/event.hxx> |
| 78 |
#include <vcl/svapp.hxx> |
| 79 |
#include <vcl/settings.hxx> |
| 80 |
#include <vcl/weld.hxx> |
| 81 |
#include <vcl/ptrstyle.hxx> |
| 82 |
#include <svtools/acceleratorexecute.hxx> |
| 83 |
#include <comphelper/diagnose_ex.hxx> |
| 84 |
#include <toolkit/awt/vclxmenu.hxx> |
| 85 |
#include <sal/log.hxx> |
| 86 |
#include <o3tl/string_view.hxx> |
| 87 |
|
| 88 |
#include <boost/property_tree/json_parser.hpp> |
| 89 |
#include <sfx2/dispatch.hxx> |
| 90 |
#include <LibreOfficeKit/LibreOfficeKitEnums.h> |
| 91 |
|
| 92 |
#define DRGPIX 2 // Drag MinMove in Pixel |
| 93 |
|
| 94 |
using namespace ::com::sun::star; |
| 95 |
using namespace ::com::sun::star::chart2; |
| 96 |
using namespace ::chart::DataSeriesProperties; |
| 97 |
using ::com::sun::star::uno::Reference; |
| 98 |
|
| 99 |
namespace chart |
| 100 |
{ |
| 101 |
|
| 102 |
namespace |
| 103 |
{ |
| 104 |
bool lcl_GrowAndShiftLogic( |
| 105 |
RelativePosition & rInOutRelPos, |
| 106 |
RelativeSize & rInOutRelSize, |
| 107 |
const awt::Size & rRefSize, |
| 108 |
double fGrowLogicX, |
| 109 |
double fGrowLogicY ) |
| 110 |
{ |
| 111 |
if( rRefSize.Width == 0 || |
| 112 |
rRefSize.Height == 0 ) |
| 113 |
return false; |
| 114 |
|
| 115 |
double fRelativeGrowX = fGrowLogicX / rRefSize.Width; |
| 116 |
double fRelativeGrowY = fGrowLogicY / rRefSize.Height; |
| 117 |
|
| 118 |
return ::chart::RelativePositionHelper::centerGrow( |
| 119 |
rInOutRelPos, rInOutRelSize, |
| 120 |
fRelativeGrowX, fRelativeGrowY ); |
| 121 |
} |
| 122 |
|
| 123 |
bool lcl_MoveObjectLogic( |
| 124 |
RelativePosition & rInOutRelPos, |
| 125 |
RelativeSize const & rObjectSize, |
| 126 |
const awt::Size & rRefSize, |
| 127 |
double fShiftLogicX, |
| 128 |
double fShiftLogicY ) |
| 129 |
{ |
| 130 |
if( rRefSize.Width == 0 || |
| 131 |
rRefSize.Height == 0 ) |
| 132 |
return false; |
| 133 |
|
| 134 |
double fRelativeShiftX = fShiftLogicX / rRefSize.Width; |
| 135 |
double fRelativeShiftY = fShiftLogicY / rRefSize.Height; |
| 136 |
|
| 137 |
return ::chart::RelativePositionHelper::moveObject( |
| 138 |
rInOutRelPos, rObjectSize, |
| 139 |
fRelativeShiftX, fRelativeShiftY ); |
| 140 |
} |
| 141 |
|
| 142 |
void lcl_insertMenuCommand( |
| 143 |
const uno::Reference< awt::XPopupMenu > & xMenu, |
| 144 |
sal_Int16 nId, const OUString & rCommand ) |
| 145 |
{ |
| 146 |
xMenu->insertItem( nId, u""_ustr, 0, -1 ); |
| 147 |
xMenu->setCommand( nId, rCommand ); |
| 148 |
} |
| 149 |
|
| 150 |
OUString lcl_getFormatCommandForObjectCID( std::u16string_view rCID ) |
| 151 |
{ |
| 152 |
OUString aDispatchCommand( u".uno:FormatSelection"_ustr ); |
| 153 |
|
| 154 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( rCID ); |
| 155 |
|
| 156 |
switch(eObjectType) |
| 157 |
{ |
| 158 |
case OBJECTTYPE_DIAGRAM: |
| 159 |
case OBJECTTYPE_DIAGRAM_WALL: |
| 160 |
aDispatchCommand = ".uno:FormatWall"; |
| 161 |
break; |
| 162 |
case OBJECTTYPE_DIAGRAM_FLOOR: |
| 163 |
aDispatchCommand = ".uno:FormatFloor"; |
| 164 |
break; |
| 165 |
case OBJECTTYPE_PAGE: |
| 166 |
aDispatchCommand = ".uno:FormatChartArea"; |
| 167 |
break; |
| 168 |
case OBJECTTYPE_LEGEND: |
| 169 |
aDispatchCommand = ".uno:FormatLegend"; |
| 170 |
break; |
| 171 |
case OBJECTTYPE_TITLE: |
| 172 |
aDispatchCommand = ".uno:FormatTitle"; |
| 173 |
break; |
| 174 |
case OBJECTTYPE_LEGEND_ENTRY: |
| 175 |
case OBJECTTYPE_DATA_SERIES: |
| 176 |
aDispatchCommand = ".uno:FormatDataSeries"; |
| 177 |
break; |
| 178 |
case OBJECTTYPE_AXIS: |
| 179 |
case OBJECTTYPE_AXIS_UNITLABEL: |
| 180 |
aDispatchCommand = ".uno:FormatAxis"; |
| 181 |
break; |
| 182 |
case OBJECTTYPE_GRID: |
| 183 |
aDispatchCommand = ".uno:FormatMajorGrid"; |
| 184 |
break; |
| 185 |
case OBJECTTYPE_SUBGRID: |
| 186 |
aDispatchCommand = ".uno:FormatMinorGrid"; |
| 187 |
break; |
| 188 |
case OBJECTTYPE_DATA_LABELS: |
| 189 |
aDispatchCommand = ".uno:FormatDataLabels"; |
| 190 |
break; |
| 191 |
case OBJECTTYPE_DATA_LABEL: |
| 192 |
aDispatchCommand = ".uno:FormatDataLabel"; |
| 193 |
break; |
| 194 |
case OBJECTTYPE_DATA_POINT: |
| 195 |
aDispatchCommand = ".uno:FormatDataPoint"; |
| 196 |
break; |
| 197 |
case OBJECTTYPE_DATA_AVERAGE_LINE: |
| 198 |
aDispatchCommand = ".uno:FormatMeanValue"; |
| 199 |
break; |
| 200 |
case OBJECTTYPE_DATA_ERRORS_X: |
| 201 |
aDispatchCommand = ".uno:FormatXErrorBars"; |
| 202 |
break; |
| 203 |
case OBJECTTYPE_DATA_ERRORS_Y: |
| 204 |
aDispatchCommand = ".uno:FormatYErrorBars"; |
| 205 |
break; |
| 206 |
case OBJECTTYPE_DATA_ERRORS_Z: |
| 207 |
aDispatchCommand = ".uno:FormatZErrorBars"; |
| 208 |
break; |
| 209 |
case OBJECTTYPE_DATA_CURVE: |
| 210 |
aDispatchCommand = ".uno:FormatTrendline"; |
| 211 |
break; |
| 212 |
case OBJECTTYPE_DATA_CURVE_EQUATION: |
| 213 |
aDispatchCommand = ".uno:FormatTrendlineEquation"; |
| 214 |
break; |
| 215 |
case OBJECTTYPE_DATA_STOCK_RANGE: |
| 216 |
aDispatchCommand = ".uno:FormatSelection"; |
| 217 |
break; |
| 218 |
case OBJECTTYPE_DATA_STOCK_LOSS: |
| 219 |
aDispatchCommand = ".uno:FormatStockLoss"; |
| 220 |
break; |
| 221 |
case OBJECTTYPE_DATA_STOCK_GAIN: |
| 222 |
aDispatchCommand = ".uno:FormatStockGain"; |
| 223 |
break; |
| 224 |
default: //OBJECTTYPE_UNKNOWN |
| 225 |
break; |
| 226 |
} |
| 227 |
return aDispatchCommand; |
| 228 |
} |
| 229 |
|
| 230 |
} // anonymous namespace |
| 231 |
|
| 232 |
// awt::XWindow |
| 233 |
void SAL_CALL ChartController::setPosSize( |
| 234 |
sal_Int32 X, |
| 235 |
sal_Int32 Y, |
| 236 |
sal_Int32 Width, |
| 237 |
sal_Int32 Height, |
| 238 |
sal_Int16 Flags ) |
| 239 |
{ |
| 240 |
SolarMutexGuard aGuard; |
| 241 |
auto pChartWindow(GetChartWindow()); |
| 242 |
|
| 243 |
if(!(m_xViewWindow.is() && pChartWindow)) |
| 244 |
return; |
| 245 |
|
| 246 |
Size aLogicSize = pChartWindow->PixelToLogic( Size( Width, Height ), MapMode( MapUnit::Map100thMM ) ); |
| 247 |
|
| 248 |
//todo: for standalone chart: detect whether we are standalone |
| 249 |
//change map mode to fit new size |
| 250 |
awt::Size aModelPageSize = getChartModel()->getPageSize(); |
| 251 |
sal_Int32 nScaleXNumerator = aLogicSize.Width(); |
| 252 |
sal_Int32 nScaleXDenominator = aModelPageSize.Width; |
| 253 |
sal_Int32 nScaleYNumerator = aLogicSize.Height(); |
| 254 |
sal_Int32 nScaleYDenominator = aModelPageSize.Height; |
| 255 |
MapMode aNewMapMode( |
| 256 |
MapUnit::Map100thMM, |
| 257 |
Point(0,0), |
| 258 |
Fraction(nScaleXNumerator, nScaleXDenominator), |
| 259 |
Fraction(nScaleYNumerator, nScaleYDenominator) ); |
| 260 |
pChartWindow->SetMapMode(aNewMapMode); |
| 261 |
pChartWindow->setPosSizePixel( X, Y, Width, Height, static_cast<PosSizeFlags>(Flags) ); |
| 262 |
|
| 263 |
//#i75867# poor quality of ole's alternative view with 3D scenes and zoomfactors besides 100% |
| 264 |
if( m_xChartView.is() ) |
| 265 |
{ |
| 266 |
auto aZoomFactors(::comphelper::InitPropertySequence({ |
| 267 |
{ "ScaleXNumerator", uno::Any( nScaleXNumerator ) }, |
| 268 |
{ "ScaleXDenominator", uno::Any( nScaleXDenominator ) }, |
| 269 |
{ "ScaleYNumerator", uno::Any( nScaleYNumerator ) }, |
| 270 |
{ "ScaleYDenominator", uno::Any( nScaleYDenominator ) } |
| 271 |
})); |
| 272 |
m_xChartView->setPropertyValue( u"ZoomFactors"_ustr, uno::Any( aZoomFactors )); |
| 273 |
} |
| 274 |
|
| 275 |
//a correct work area is at least necessary for correct values in the position and size dialog and for dragging area |
| 276 |
if(m_pDrawViewWrapper) |
| 277 |
{ |
| 278 |
tools::Rectangle aRect(Point(0,0), pChartWindow->GetOutDev()->GetOutputSize()); |
| 279 |
m_pDrawViewWrapper->SetWorkArea( aRect ); |
| 280 |
} |
| 281 |
pChartWindow->Invalidate(); |
| 282 |
} |
| 283 |
|
| 284 |
awt::Rectangle SAL_CALL ChartController::getPosSize() |
| 285 |
{ |
| 286 |
awt::Rectangle aRet(0, 0, 0, 0); |
| 287 |
|
| 288 |
if (m_xViewWindow.is()) |
| 289 |
aRet = m_xViewWindow->getPosSize(); |
| 290 |
|
| 291 |
return aRet; |
| 292 |
} |
| 293 |
|
| 294 |
void SAL_CALL ChartController::setVisible( sal_Bool Visible ) |
| 295 |
{ |
| 296 |
if (m_xViewWindow.is()) |
| 297 |
m_xViewWindow->setVisible(Visible); |
| 298 |
} |
| 299 |
|
| 300 |
void SAL_CALL ChartController::setEnable( sal_Bool Enable ) |
| 301 |
{ |
| 302 |
if (m_xViewWindow.is()) |
| 303 |
m_xViewWindow->setEnable(Enable); |
| 304 |
} |
| 305 |
|
| 306 |
void SAL_CALL ChartController::setFocus() |
| 307 |
{ |
| 308 |
if (m_xViewWindow.is()) |
| 309 |
m_xViewWindow->setFocus(); |
| 310 |
} |
| 311 |
|
| 312 |
void SAL_CALL ChartController::addWindowListener( |
| 313 |
const uno::Reference< awt::XWindowListener >& xListener ) |
| 314 |
{ |
| 315 |
if (m_xViewWindow.is()) |
| 316 |
m_xViewWindow->addWindowListener(xListener); |
| 317 |
} |
| 318 |
|
| 319 |
void SAL_CALL ChartController::removeWindowListener( |
| 320 |
const uno::Reference< awt::XWindowListener >& xListener ) |
| 321 |
{ |
| 322 |
if (m_xViewWindow.is()) |
| 323 |
m_xViewWindow->removeWindowListener(xListener); |
| 324 |
} |
| 325 |
|
| 326 |
void SAL_CALL ChartController::addFocusListener( |
| 327 |
const uno::Reference< awt::XFocusListener >& xListener ) |
| 328 |
{ |
| 329 |
if (m_xViewWindow.is()) |
| 330 |
m_xViewWindow->addFocusListener(xListener); |
| 331 |
} |
| 332 |
|
| 333 |
void SAL_CALL ChartController::removeFocusListener( |
| 334 |
const uno::Reference< awt::XFocusListener >& xListener ) |
| 335 |
{ |
| 336 |
if (m_xViewWindow.is()) |
| 337 |
m_xViewWindow->removeFocusListener(xListener); |
| 338 |
} |
| 339 |
|
| 340 |
void SAL_CALL ChartController::addKeyListener( |
| 341 |
const uno::Reference< awt::XKeyListener >& xListener ) |
| 342 |
{ |
| 343 |
if (m_xViewWindow.is()) |
| 344 |
m_xViewWindow->addKeyListener(xListener); |
| 345 |
} |
| 346 |
|
| 347 |
void SAL_CALL ChartController::removeKeyListener( |
| 348 |
const uno::Reference< awt::XKeyListener >& xListener ) |
| 349 |
{ |
| 350 |
if (m_xViewWindow.is()) |
| 351 |
m_xViewWindow->removeKeyListener(xListener); |
| 352 |
} |
| 353 |
|
| 354 |
void SAL_CALL ChartController::addMouseListener( |
| 355 |
const uno::Reference< awt::XMouseListener >& xListener ) |
| 356 |
{ |
| 357 |
if (m_xViewWindow.is()) |
| 358 |
m_xViewWindow->addMouseListener(xListener); |
| 359 |
} |
| 360 |
|
| 361 |
void SAL_CALL ChartController::removeMouseListener( |
| 362 |
const uno::Reference< awt::XMouseListener >& xListener ) |
| 363 |
{ |
| 364 |
if (m_xViewWindow.is()) |
| 365 |
m_xViewWindow->removeMouseListener(xListener); |
| 366 |
} |
| 367 |
|
| 368 |
void SAL_CALL ChartController::addMouseMotionListener( |
| 369 |
const uno::Reference< awt::XMouseMotionListener >& xListener ) |
| 370 |
{ |
| 371 |
if (m_xViewWindow.is()) |
| 372 |
m_xViewWindow->addMouseMotionListener(xListener); |
| 373 |
} |
| 374 |
|
| 375 |
void SAL_CALL ChartController::removeMouseMotionListener( |
| 376 |
const uno::Reference< awt::XMouseMotionListener >& xListener ) |
| 377 |
{ |
| 378 |
if (m_xViewWindow.is()) |
| 379 |
m_xViewWindow->removeMouseMotionListener(xListener); |
| 380 |
} |
| 381 |
|
| 382 |
void SAL_CALL ChartController::addPaintListener( |
| 383 |
const uno::Reference< awt::XPaintListener >& xListener ) |
| 384 |
{ |
| 385 |
if (m_xViewWindow.is()) |
| 386 |
m_xViewWindow->addPaintListener(xListener); |
| 387 |
} |
| 388 |
|
| 389 |
void SAL_CALL ChartController::removePaintListener( |
| 390 |
const uno::Reference< awt::XPaintListener >& xListener ) |
| 391 |
{ |
| 392 |
if (m_xViewWindow.is()) |
| 393 |
m_xViewWindow->removePaintListener(xListener); |
| 394 |
} |
| 395 |
|
| 396 |
// impl vcl window controller methods |
| 397 |
void ChartController::PrePaint() |
| 398 |
{ |
| 399 |
// forward VCLs PrePaint window event to DrawingLayer |
| 400 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 401 |
|
| 402 |
if (pDrawViewWrapper) |
| 403 |
{ |
| 404 |
pDrawViewWrapper->PrePaint(); |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
void ChartController::execute_Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) |
| 409 |
{ |
| 410 |
try |
| 411 |
{ |
| 412 |
rtl::Reference<ChartModel> xModel(getChartModel()); |
| 413 |
//OSL_ENSURE( xModel.is(), "ChartController::execute_Paint: have no model to paint"); |
| 414 |
if (!xModel.is()) |
| 415 |
return; |
| 416 |
|
| 417 |
//better performance for big data |
| 418 |
if (m_xChartView.is()) |
| 419 |
{ |
| 420 |
awt::Size aResolution(1000, 1000); |
| 421 |
{ |
| 422 |
SolarMutexGuard aGuard; |
| 423 |
auto pChartWindow(GetChartWindow()); |
| 424 |
if (pChartWindow) |
| 425 |
{ |
| 426 |
aResolution.Width = pChartWindow->GetSizePixel().Width(); |
| 427 |
aResolution.Height = pChartWindow->GetSizePixel().Height(); |
| 428 |
} |
| 429 |
} |
| 430 |
m_xChartView->setPropertyValue( u"Resolution"_ustr, uno::Any( aResolution )); |
| 431 |
} |
| 432 |
|
| 433 |
if (m_xChartView.is()) |
| 434 |
m_xChartView->update(); |
| 435 |
|
| 436 |
{ |
| 437 |
SolarMutexGuard aGuard; |
| 438 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 439 |
if (pDrawViewWrapper) |
| 440 |
pDrawViewWrapper->CompleteRedraw(&rRenderContext, vcl::Region(rRect)); |
| 441 |
} |
| 442 |
} |
| 443 |
catch( const uno::Exception & ) |
| 444 |
{ |
| 445 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 446 |
} |
| 447 |
catch( ... ) |
| 448 |
{ |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
static bool isDoubleClick( const MouseEvent& rMEvt ) |
| 453 |
{ |
| 454 |
return rMEvt.GetClicks() == 2 && rMEvt.IsLeft() && |
| 455 |
!rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift(); |
| 456 |
} |
| 457 |
|
| 458 |
void ChartController::startDoubleClickWaiting() |
| 459 |
{ |
| 460 |
SolarMutexGuard aGuard; |
| 461 |
|
| 462 |
m_bWaitingForDoubleClick = true; |
| 463 |
|
| 464 |
sal_uInt64 nDblClkTime = 500; |
| 465 |
auto pChartWindow(GetChartWindow()); |
| 466 |
if( pChartWindow ) |
| 467 |
{ |
| 468 |
const MouseSettings& rMSettings = pChartWindow->GetSettings().GetMouseSettings(); |
| 469 |
nDblClkTime = rMSettings.GetDoubleClickTime(); |
| 470 |
} |
| 471 |
m_aDoubleClickTimer.SetTimeout( nDblClkTime ); |
| 472 |
m_aDoubleClickTimer.Start(); |
| 473 |
} |
| 474 |
|
| 475 |
void ChartController::stopDoubleClickWaiting() |
| 476 |
{ |
| 477 |
m_aDoubleClickTimer.Stop(); |
| 478 |
m_bWaitingForDoubleClick = false; |
| 479 |
} |
| 480 |
|
| 481 |
IMPL_LINK_NOARG(ChartController, DoubleClickWaitingHdl, Timer *, void) |
| 482 |
{ |
| 483 |
m_bWaitingForDoubleClick = false; |
| 484 |
|
| 485 |
if( m_bWaitingForMouseUp || !m_aSelection.maybeSwitchSelectionAfterSingleClickWasEnsured() ) |
| 486 |
return; |
| 487 |
|
| 488 |
impl_selectObjectAndNotiy(); |
| 489 |
SolarMutexGuard aGuard; |
| 490 |
auto pChartWindow(GetChartWindow()); |
| 491 |
if( pChartWindow ) |
| 492 |
{ |
| 493 |
vcl::Window::PointerState aPointerState( pChartWindow->GetPointerState() ); |
| 494 |
MouseEvent aMouseEvent( |
| 495 |
aPointerState.maPos, |
| 496 |
1/*nClicks*/, |
| 497 |
MouseEventModifiers::NONE, |
| 498 |
static_cast< sal_uInt16 >( aPointerState.mnState )/*nButtons*/, |
| 499 |
0/*nModifier*/ ); |
| 500 |
impl_SetMousePointer( aMouseEvent ); |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
void ChartController::execute_MouseButtonDown( const MouseEvent& rMEvt ) |
| 505 |
{ |
| 506 |
SolarMutexGuard aGuard; |
| 507 |
|
| 508 |
m_bWaitingForMouseUp = true; |
| 509 |
m_bFieldButtonDown = false; |
| 510 |
|
| 511 |
if( isDoubleClick(rMEvt) ) |
| 512 |
stopDoubleClickWaiting(); |
| 513 |
else |
| 514 |
startDoubleClickWaiting(); |
| 515 |
|
| 516 |
m_aSelection.remindSelectionBeforeMouseDown(); |
| 517 |
|
| 518 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 519 |
auto pChartWindow(GetChartWindow()); |
| 520 |
if(!pChartWindow || !pDrawViewWrapper ) |
| 521 |
return; |
| 522 |
|
| 523 |
Point aMPos = pChartWindow->PixelToLogic(rMEvt.GetPosPixel()); |
| 524 |
|
| 525 |
// Check if button was clicked |
| 526 |
SdrObject* pObject = pDrawViewWrapper->getHitObject(aMPos); |
| 527 |
if (pObject) |
| 528 |
{ |
| 529 |
OUString aCID = pObject->GetName(); |
| 530 |
if (aCID.startsWith("FieldButton")) |
| 531 |
{ |
| 532 |
m_bFieldButtonDown = true; |
| 533 |
return; // Don't take any action if button was clicked |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
if ( rMEvt.GetButtons() == MOUSE_LEFT ) |
| 538 |
{ |
| 539 |
pChartWindow->GrabFocus(); |
| 540 |
pChartWindow->CaptureMouse(); |
| 541 |
} |
| 542 |
|
| 543 |
if( pDrawViewWrapper->IsTextEdit() ) |
| 544 |
{ |
| 545 |
SdrViewEvent aVEvt; |
| 546 |
if ( pDrawViewWrapper->IsTextEditHit( aMPos ) || |
| 547 |
// #i12587# support for shapes in chart |
| 548 |
( rMEvt.IsRight() && pDrawViewWrapper->PickAnything( rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt ) == SdrHitKind::MarkedObject ) ) |
| 549 |
{ |
| 550 |
pDrawViewWrapper->MouseButtonDown(rMEvt, pChartWindow->GetOutDev()); |
| 551 |
return; |
| 552 |
} |
| 553 |
else |
| 554 |
{ |
| 555 |
EndTextEdit(); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
//abort running action |
| 560 |
if( pDrawViewWrapper->IsAction() ) |
| 561 |
{ |
| 562 |
if( rMEvt.IsRight() ) |
| 563 |
pDrawViewWrapper->BckAction(); |
| 564 |
return; |
| 565 |
} |
| 566 |
|
| 567 |
if( isDoubleClick(rMEvt) ) //do not change selection if double click |
| 568 |
return;//double click is handled further in mousebutton up |
| 569 |
|
| 570 |
SdrHdl* pHitSelectionHdl = nullptr; |
| 571 |
//switch from move to resize if handle is hit on a resizable object |
| 572 |
if( m_aSelection.isResizeableObjectSelected() ) |
| 573 |
pHitSelectionHdl = pDrawViewWrapper->PickHandle( aMPos ); |
| 574 |
//only change selection if no selection handles are hit |
| 575 |
if( !pHitSelectionHdl ) |
| 576 |
{ |
| 577 |
// #i12587# support for shapes in chart |
| 578 |
if ( m_eDrawMode == CHARTDRAW_INSERT && |
| 579 |
( !pDrawViewWrapper->IsMarkedHit( aMPos ) || !m_aSelection.isDragableObjectSelected() ) ) |
| 580 |
{ |
| 581 |
if ( m_aSelection.hasSelection() ) |
| 582 |
{ |
| 583 |
m_aSelection.clearSelection(); |
| 584 |
} |
| 585 |
if ( !pDrawViewWrapper->IsAction() ) |
| 586 |
{ |
| 587 |
if ( pDrawViewWrapper->GetCurrentObjIdentifier() == SdrObjKind::Caption ) |
| 588 |
{ |
| 589 |
Size aCaptionSize( 2268, 1134 ); |
| 590 |
pDrawViewWrapper->BegCreateCaptionObj( aMPos, aCaptionSize ); |
| 591 |
} |
| 592 |
else |
| 593 |
{ |
| 594 |
pDrawViewWrapper->BegCreateObj( aMPos); |
| 595 |
} |
| 596 |
SdrObject* pObj = pDrawViewWrapper->GetCreateObj(); |
| 597 |
DrawCommandDispatch* pDrawCommandDispatch = m_aDispatchContainer.getDrawCommandDispatch(); |
| 598 |
if ( pObj && m_pDrawModelWrapper && pDrawCommandDispatch ) |
| 599 |
{ |
| 600 |
SfxItemSet aSet( m_pDrawModelWrapper->GetItemPool() ); |
| 601 |
pDrawCommandDispatch->setAttributes( pObj ); |
| 602 |
pDrawCommandDispatch->setLineEnds( aSet ); |
| 603 |
pObj->SetMergedItemSet( aSet ); |
| 604 |
} |
| 605 |
} |
| 606 |
impl_SetMousePointer( rMEvt ); |
| 607 |
return; |
| 608 |
} |
| 609 |
|
| 610 |
m_aSelection.adaptSelectionToNewPos( |
| 611 |
aMPos, |
| 612 |
pDrawViewWrapper, |
| 613 |
rMEvt.IsRight(), |
| 614 |
m_bWaitingForDoubleClick ); |
| 615 |
|
| 616 |
if( !m_aSelection.isRotateableObjectSelected( getChartModel() ) ) |
| 617 |
{ |
| 618 |
m_eDragMode = SdrDragMode::Move; |
| 619 |
pDrawViewWrapper->SetDragMode(m_eDragMode); |
| 620 |
} |
| 621 |
|
| 622 |
m_aSelection.applySelection(pDrawViewWrapper); |
| 623 |
} |
| 624 |
if( m_aSelection.isDragableObjectSelected() |
| 625 |
&& !rMEvt.IsRight() ) |
| 626 |
{ |
| 627 |
//start drag |
| 628 |
sal_uInt16 nDrgLog = static_cast<sal_uInt16>(pChartWindow->PixelToLogic(Size(DRGPIX,0)).Width()); |
| 629 |
SdrDragMethod* pDragMethod = nullptr; |
| 630 |
|
| 631 |
//change selection to 3D scene if rotate mode |
| 632 |
SdrDragMode eDragMode = pDrawViewWrapper->GetDragMode(); |
| 633 |
if( eDragMode==SdrDragMode::Rotate ) |
| 634 |
{ |
| 635 |
E3dScene* pScene = SelectionHelper::getSceneToRotate( pDrawViewWrapper->getNamedSdrObject( m_aSelection.getSelectedCID() ) ); |
| 636 |
if( pScene ) |
| 637 |
{ |
| 638 |
DragMethod_RotateDiagram::RotationDirection eRotationDirection(DragMethod_RotateDiagram::ROTATIONDIRECTION_FREE); |
| 639 |
if(pHitSelectionHdl) |
| 640 |
{ |
| 641 |
SdrHdlKind eKind = pHitSelectionHdl->GetKind(); |
| 642 |
if( eKind==SdrHdlKind::Upper || eKind==SdrHdlKind::Lower ) |
| 643 |
eRotationDirection = DragMethod_RotateDiagram::ROTATIONDIRECTION_X; |
| 644 |
else if( eKind==SdrHdlKind::Left || eKind==SdrHdlKind::Right ) |
| 645 |
eRotationDirection = DragMethod_RotateDiagram::ROTATIONDIRECTION_Y; |
| 646 |
else if( eKind==SdrHdlKind::UpperLeft || eKind==SdrHdlKind::UpperRight || eKind==SdrHdlKind::LowerLeft || eKind==SdrHdlKind::LowerRight ) |
| 647 |
eRotationDirection = DragMethod_RotateDiagram::ROTATIONDIRECTION_Z; |
| 648 |
} |
| 649 |
pDragMethod = new DragMethod_RotateDiagram( *pDrawViewWrapper, m_aSelection.getSelectedCID(), getChartModel(), eRotationDirection ); |
| 650 |
} |
| 651 |
} |
| 652 |
else |
| 653 |
{ |
| 654 |
std::u16string_view aDragMethodServiceName( ObjectIdentifier::getDragMethodServiceName( m_aSelection.getSelectedCID() ) ); |
| 655 |
if( aDragMethodServiceName == ObjectIdentifier::getPieSegmentDragMethodServiceName() ) |
| 656 |
pDragMethod = new DragMethod_PieSegment( *pDrawViewWrapper, m_aSelection.getSelectedCID(), getChartModel() ); |
| 657 |
} |
| 658 |
pDrawViewWrapper->SdrView::BegDragObj(aMPos, nullptr, pHitSelectionHdl, nDrgLog, pDragMethod); |
| 659 |
} |
| 660 |
|
| 661 |
impl_SetMousePointer( rMEvt ); |
| 662 |
} |
| 663 |
|
| 664 |
void ChartController::execute_MouseMove( const MouseEvent& rMEvt ) |
| 665 |
{ |
| 666 |
SolarMutexGuard aGuard; |
| 667 |
|
| 668 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 669 |
auto pChartWindow(GetChartWindow()); |
| 670 |
if(!pChartWindow || !pDrawViewWrapper) |
| 671 |
return; |
| 672 |
|
| 673 |
if( m_pDrawViewWrapper->IsTextEdit() ) |
| 674 |
{ |
| 675 |
if( m_pDrawViewWrapper->MouseMove(rMEvt,pChartWindow->GetOutDev()) ) |
| 676 |
return; |
| 677 |
} |
| 678 |
|
| 679 |
if(pDrawViewWrapper->IsAction()) |
| 680 |
{ |
| 681 |
pDrawViewWrapper->MovAction( pChartWindow->PixelToLogic( rMEvt.GetPosPixel() ) ); |
| 682 |
} |
| 683 |
|
| 684 |
impl_SetMousePointer( rMEvt ); |
| 685 |
} |
| 686 |
|
| 687 |
void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) |
| 688 |
{ |
| 689 |
ControllerLockGuardUNO aCLGuard( getChartModel() ); |
| 690 |
bool bMouseUpWithoutMouseDown = !m_bWaitingForMouseUp; |
| 691 |
m_bWaitingForMouseUp = false; |
| 692 |
bool bNotifySelectionChange = false; |
| 693 |
bool bEditText = false; |
| 694 |
{ |
| 695 |
SolarMutexGuard aGuard; |
| 696 |
|
| 697 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 698 |
auto pChartWindow(GetChartWindow()); |
| 699 |
if(!pChartWindow || !pDrawViewWrapper) |
| 700 |
return; |
| 701 |
|
| 702 |
Point aMPos = pChartWindow->PixelToLogic(rMEvt.GetPosPixel()); |
| 703 |
|
| 704 |
// Check if button was clicked |
| 705 |
if (m_bFieldButtonDown) |
| 706 |
{ |
| 707 |
m_bFieldButtonDown = false; |
| 708 |
SdrObject* pObject = pDrawViewWrapper->getHitObject(aMPos); |
| 709 |
if (pObject) |
| 710 |
{ |
| 711 |
OUString aCID = pObject->GetName(); |
| 712 |
if (aCID.startsWith("FieldButton")) |
| 713 |
{ |
| 714 |
sendPopupRequest(aCID, pObject->GetCurrentBoundRect()); |
| 715 |
return; |
| 716 |
} |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
if(pDrawViewWrapper->IsTextEdit()) |
| 721 |
{ |
| 722 |
if( pDrawViewWrapper->MouseButtonUp(rMEvt,pChartWindow->GetOutDev()) ) |
| 723 |
return; |
| 724 |
} |
| 725 |
|
| 726 |
// #i12587# support for shapes in chart |
| 727 |
if ( m_eDrawMode == CHARTDRAW_INSERT && pDrawViewWrapper->IsCreateObj() ) |
| 728 |
{ |
| 729 |
pDrawViewWrapper->EndCreateObj( SdrCreateCmd::ForceEnd ); |
| 730 |
{ |
| 731 |
HiddenUndoContext aUndoContext( m_xUndoManager ); |
| 732 |
// don't want the positioning Undo action to appear in the UI |
| 733 |
impl_switchDiagramPositioningToExcludingPositioning(); |
| 734 |
} |
| 735 |
if ( pDrawViewWrapper->GetMarkedObjectList().GetMarkCount() != 0 ) |
| 736 |
{ |
| 737 |
if ( pDrawViewWrapper->GetCurrentObjIdentifier() == SdrObjKind::Text ) |
| 738 |
{ |
| 739 |
executeDispatch_EditText(); |
| 740 |
} |
| 741 |
else |
| 742 |
{ |
| 743 |
SdrObject* pObj = pDrawViewWrapper->getSelectedObject(); |
| 744 |
if ( pObj ) |
| 745 |
{ |
| 746 |
uno::Reference< drawing::XShape > xShape( pObj->getUnoShape(), uno::UNO_QUERY ); |
| 747 |
if ( xShape.is() ) |
| 748 |
{ |
| 749 |
m_aSelection.setSelection( xShape ); |
| 750 |
m_aSelection.applySelection( pDrawViewWrapper ); |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
} |
| 755 |
else |
| 756 |
{ |
| 757 |
m_aSelection.adaptSelectionToNewPos( aMPos, pDrawViewWrapper, rMEvt.IsRight(), m_bWaitingForDoubleClick ); |
| 758 |
m_aSelection.applySelection( pDrawViewWrapper ); |
| 759 |
setDrawMode( CHARTDRAW_SELECT ); |
| 760 |
} |
| 761 |
} |
| 762 |
else if ( pDrawViewWrapper->IsDragObj() ) |
| 763 |
{ |
| 764 |
bool bDraggingDone = false; |
| 765 |
SdrDragMethod* pDragMethod = pDrawViewWrapper->SdrView::GetDragMethod(); |
| 766 |
bool bIsMoveOnly = pDragMethod && pDragMethod->getMoveOnly(); |
| 767 |
DragMethod_Base* pChartDragMethod = dynamic_cast< DragMethod_Base* >(pDragMethod); |
| 768 |
if( pChartDragMethod ) |
| 769 |
{ |
| 770 |
UndoGuard aUndoGuard( pChartDragMethod->getUndoDescription(), |
| 771 |
m_xUndoManager ); |
| 772 |
|
| 773 |
if( pDrawViewWrapper->EndDragObj() ) |
| 774 |
{ |
| 775 |
bDraggingDone = true; |
| 776 |
aUndoGuard.commit(); |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
if( !bDraggingDone && pDrawViewWrapper->EndDragObj() ) |
| 781 |
{ |
| 782 |
try |
| 783 |
{ |
| 784 |
//end move or size |
| 785 |
SdrObject* pObj = pDrawViewWrapper->getSelectedObject(); |
| 786 |
if( pObj ) |
| 787 |
{ |
| 788 |
tools::Rectangle aObjectRect = pObj->GetSnapRect(); |
| 789 |
tools::Rectangle aOldObjectRect = pObj->GetLastBoundRect(); |
| 790 |
awt::Size aPageSize( getChartModel()->getPageSize() ); |
| 791 |
tools::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height ); |
| 792 |
|
| 793 |
const E3dObject* pE3dObject(DynCastE3dObject(pObj)); |
| 794 |
if(nullptr != pE3dObject) |
| 795 |
{ |
| 796 |
E3dScene* pScene(pE3dObject->getRootE3dSceneFromE3dObject()); |
| 797 |
if(nullptr != pScene) |
| 798 |
{ |
| 799 |
aObjectRect = pScene->GetSnapRect(); |
| 800 |
} |
| 801 |
} |
| 802 |
|
| 803 |
ActionDescriptionProvider::ActionType eActionType(ActionDescriptionProvider::ActionType::Move); |
| 804 |
if( !bIsMoveOnly && m_aSelection.isResizeableObjectSelected() ) |
| 805 |
eActionType = ActionDescriptionProvider::ActionType::Resize; |
| 806 |
|
| 807 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( m_aSelection.getSelectedCID() ); |
| 808 |
|
| 809 |
UndoGuard aUndoGuard( |
| 810 |
ActionDescriptionProvider::createDescription( eActionType, ObjectNameProvider::getName( eObjectType)), |
| 811 |
m_xUndoManager ); |
| 812 |
|
| 813 |
bool bChanged = false; |
| 814 |
rtl::Reference< ChartModel > xModel = getChartModel(); |
| 815 |
if ( eObjectType == OBJECTTYPE_LEGEND ) |
| 816 |
bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning( *xModel, false , true ); |
| 817 |
|
| 818 |
bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID() |
| 819 |
, xModel |
| 820 |
, awt::Rectangle(aObjectRect.Left(),aObjectRect.Top(),aObjectRect.getOpenWidth(),aObjectRect.getOpenHeight()) |
| 821 |
, awt::Rectangle(aOldObjectRect.Left(), aOldObjectRect.Top(), 0, 0) |
| 822 |
, awt::Rectangle(aPageRect.Left(),aPageRect.Top(),aPageRect.getOpenWidth(),aPageRect.getOpenHeight()) ); |
| 823 |
|
| 824 |
if( bMoved || bChanged ) |
| 825 |
{ |
| 826 |
bDraggingDone = true; |
| 827 |
aUndoGuard.commit(); |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
catch( const uno::Exception & ) |
| 832 |
{ |
| 833 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 834 |
} |
| 835 |
//all wanted model changes will take effect |
| 836 |
//and all unwanted view modifications are cleaned |
| 837 |
} |
| 838 |
|
| 839 |
if( !bDraggingDone ) //mouse wasn't moved while dragging |
| 840 |
{ |
| 841 |
bool bClickedTwiceOnDragableObject = SelectionHelper::isDragableObjectHitTwice( aMPos, m_aSelection.getSelectedCID(), *pDrawViewWrapper ); |
| 842 |
bool bIsRotateable = m_aSelection.isRotateableObjectSelected( getChartModel() ); |
| 843 |
|
| 844 |
//toggle between move and rotate |
| 845 |
if( bIsRotateable && bClickedTwiceOnDragableObject && m_eDragMode==SdrDragMode::Move ) |
| 846 |
m_eDragMode=SdrDragMode::Rotate; |
| 847 |
else |
| 848 |
m_eDragMode=SdrDragMode::Move; |
| 849 |
|
| 850 |
pDrawViewWrapper->SetDragMode(m_eDragMode); |
| 851 |
|
| 852 |
if( !m_bWaitingForDoubleClick && m_aSelection.maybeSwitchSelectionAfterSingleClickWasEnsured() ) |
| 853 |
{ |
| 854 |
impl_selectObjectAndNotiy(); |
| 855 |
} |
| 856 |
} |
| 857 |
else |
| 858 |
m_aSelection.resetPossibleSelectionAfterSingleClickWasEnsured(); |
| 859 |
} |
| 860 |
|
| 861 |
//@todo ForcePointer(&rMEvt); |
| 862 |
pChartWindow->ReleaseMouse(); |
| 863 |
|
| 864 |
// In tiled rendering drag mode could be not yet over on the call |
| 865 |
// that should handle the double-click, so better to perform this check |
| 866 |
// always. |
| 867 |
if( isDoubleClick(rMEvt) && !bMouseUpWithoutMouseDown /*#i106966#*/ ) |
| 868 |
{ |
| 869 |
Point aMousePixel = rMEvt.GetPosPixel(); |
| 870 |
execute_DoubleClick( &aMousePixel, bEditText ); |
| 871 |
} |
| 872 |
|
| 873 |
if( m_aSelection.isSelectionDifferentFromBeforeMouseDown() ) |
| 874 |
bNotifySelectionChange = true; |
| 875 |
} |
| 876 |
|
| 877 |
impl_SetMousePointer( rMEvt ); |
| 878 |
|
| 879 |
if(bNotifySelectionChange || bEditText) |
| 880 |
impl_notifySelectionChangeListeners(); |
| 881 |
} |
| 882 |
|
| 883 |
void ChartController::execute_DoubleClick( const Point* pMousePixel, bool &bEditText ) |
| 884 |
{ |
| 885 |
const SfxViewShell* pViewShell = SfxViewShell::Current(); |
| 886 |
bool notAllowed = pViewShell && (pViewShell->isLOKMobilePhone() || pViewShell->IsLokReadOnlyView()); |
| 887 |
if (notAllowed) |
| 888 |
return; |
| 889 |
|
| 890 |
if ( m_aSelection.hasSelection() ) |
| 891 |
{ |
| 892 |
OUString aCID( m_aSelection.getSelectedCID() ); |
| 893 |
if ( !aCID.isEmpty() ) |
| 894 |
{ |
| 895 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID ); |
| 896 |
if ( eObjectType == OBJECTTYPE_TITLE ) |
| 897 |
{ |
| 898 |
bEditText = true; |
| 899 |
} |
| 900 |
} |
| 901 |
else |
| 902 |
{ |
| 903 |
// #i12587# support for shapes in chart |
| 904 |
SdrObject* pObj = DrawViewWrapper::getSdrObject( m_aSelection.getSelectedAdditionalShape() ); |
| 905 |
if ( DynCastSdrTextObj(pObj) != nullptr ) |
| 906 |
{ |
| 907 |
bEditText = true; |
| 908 |
} |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
if ( bEditText ) |
| 913 |
{ |
| 914 |
executeDispatch_EditText( pMousePixel ); |
| 915 |
} |
| 916 |
else |
| 917 |
{ |
| 918 |
executeDispatch_ObjectProperties(); |
| 919 |
} |
| 920 |
} |
| 921 |
|
| 922 |
void ChartController::execute_Resize() |
| 923 |
{ |
| 924 |
SolarMutexGuard aGuard; |
| 925 |
auto pChartWindow(GetChartWindow()); |
| 926 |
if(pChartWindow) |
| 927 |
pChartWindow->Invalidate(); |
| 928 |
} |
| 929 |
|
| 930 |
void ChartController::execute_Command( const CommandEvent& rCEvt ) |
| 931 |
{ |
| 932 |
SolarMutexGuard aGuard; |
| 933 |
auto pChartWindow(GetChartWindow()); |
| 934 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 935 |
if(!pChartWindow || !pDrawViewWrapper) |
| 936 |
return; |
| 937 |
bool bIsAction = m_pDrawViewWrapper->IsAction(); |
| 938 |
|
| 939 |
// pop-up menu |
| 940 |
if(rCEvt.GetCommand() == CommandEventId::ContextMenu && !bIsAction) |
| 941 |
{ |
| 942 |
pChartWindow->ReleaseMouse(); |
| 943 |
|
| 944 |
if( m_aSelection.isSelectionDifferentFromBeforeMouseDown() ) |
| 945 |
impl_notifySelectionChangeListeners(); |
| 946 |
|
| 947 |
rtl::Reference< VCLXPopupMenu > xPopupMenu = new VCLXPopupMenu(); |
| 948 |
|
| 949 |
Point aPos( rCEvt.GetMousePosPixel() ); |
| 950 |
if( !rCEvt.IsMouseEvent() ) |
| 951 |
{ |
| 952 |
aPos = pChartWindow->GetPointerState().maPos; |
| 953 |
} |
| 954 |
|
| 955 |
OUString aMenuName; |
| 956 |
if ( isShapeContext() ) |
| 957 |
// #i12587# support for shapes in chart |
| 958 |
aMenuName = m_pDrawViewWrapper->IsTextEdit() ? std::u16string_view( u"drawtext" ) : std::u16string_view( u"draw" ); |
| 959 |
else |
| 960 |
{ |
| 961 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( m_aSelection.getSelectedCID() ); |
| 962 |
|
| 963 |
// todo: the context menu should be specified by an xml file in uiconfig |
| 964 |
sal_Int16 nUniqueId = 1; |
| 965 |
if (eObjectType != OBJECTTYPE_DATA_TABLE) |
| 966 |
{ |
| 967 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:Cut"_ustr ); |
| 968 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:Copy"_ustr ); |
| 969 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:Paste"_ustr ); |
| 970 |
xPopupMenu->insertSeparator( -1 ); |
| 971 |
} |
| 972 |
|
| 973 |
rtl::Reference< Diagram > xDiagram = getFirstDiagram(); |
| 974 |
|
| 975 |
OUString aFormatCommand( lcl_getFormatCommandForObjectCID( m_aSelection.getSelectedCID() ) ); |
| 976 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, aFormatCommand ); |
| 977 |
if (eObjectType == OBJECTTYPE_TITLE && m_pDrawViewWrapper->IsTextEdit()) |
| 978 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FontDialog"_ustr ); |
| 979 |
|
| 980 |
//some commands for dataseries and points: |
| 981 |
|
| 982 |
if( eObjectType == OBJECTTYPE_DATA_SERIES || eObjectType == OBJECTTYPE_DATA_POINT ) |
| 983 |
{ |
| 984 |
bool bIsPoint = ( eObjectType == OBJECTTYPE_DATA_POINT ); |
| 985 |
rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); |
| 986 |
rtl::Reference< RegressionCurveModel > xTrendline = RegressionCurveHelper::getFirstCurveNotMeanValueLine( xSeries ); |
| 987 |
bool bHasEquation = RegressionCurveHelper::hasEquation( xTrendline ); |
| 988 |
rtl::Reference< RegressionCurveModel > xMeanValue = RegressionCurveHelper::getMeanValueLine( xSeries ); |
| 989 |
bool bHasYErrorBars = StatisticsHelper::hasErrorBars( xSeries ); |
| 990 |
bool bHasXErrorBars = StatisticsHelper::hasErrorBars( xSeries, false ); |
| 991 |
bool bHasDataLabelsAtSeries = xSeries->hasDataLabelsAtSeries(); |
| 992 |
bool bHasDataLabelsAtPoints = xSeries->hasDataLabelsAtPoints(); |
| 993 |
bool bHasDataLabelAtPoint = false; |
| 994 |
sal_Int32 nPointIndex = -1; |
| 995 |
if( bIsPoint ) |
| 996 |
{ |
| 997 |
nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() ); |
| 998 |
bHasDataLabelAtPoint = xSeries->hasDataLabelAtPoint( nPointIndex ); |
| 999 |
} |
| 1000 |
bool bSelectedPointIsFormatted = false; |
| 1001 |
bool bHasFormattedDataPointsOtherThanSelected = false; |
| 1002 |
|
| 1003 |
if( xSeries.is() ) |
| 1004 |
{ |
| 1005 |
uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; |
| 1006 |
// "AttributedDataPoints" |
| 1007 |
if( xSeries->getFastPropertyValue( PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) >>= aAttributedDataPointIndexList ) |
| 1008 |
{ |
| 1009 |
if( aAttributedDataPointIndexList.hasElements() ) |
| 1010 |
{ |
| 1011 |
if( bIsPoint ) |
| 1012 |
{ |
| 1013 |
auto aIt = std::find( aAttributedDataPointIndexList.begin(), aAttributedDataPointIndexList.end(), nPointIndex ); |
| 1014 |
if (aIt != aAttributedDataPointIndexList.end()) |
| 1015 |
bSelectedPointIsFormatted = true; |
| 1016 |
else |
| 1017 |
bHasFormattedDataPointsOtherThanSelected = true; |
| 1018 |
} |
| 1019 |
else |
| 1020 |
bHasFormattedDataPointsOtherThanSelected = true; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
} |
| 1024 |
|
| 1025 |
if( bIsPoint ) |
| 1026 |
{ |
| 1027 |
if( bHasDataLabelAtPoint ) |
| 1028 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatDataLabel"_ustr ); |
| 1029 |
if( !bHasDataLabelAtPoint ) |
| 1030 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertDataLabel"_ustr ); |
| 1031 |
else |
| 1032 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteDataLabel"_ustr ); |
| 1033 |
if( bSelectedPointIsFormatted ) |
| 1034 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:ResetDataPoint"_ustr ); |
| 1035 |
|
| 1036 |
xPopupMenu->insertSeparator( -1 ); |
| 1037 |
|
| 1038 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatDataSeries"_ustr ); |
| 1039 |
} |
| 1040 |
|
| 1041 |
rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xSeries ) ); |
| 1042 |
if( xChartType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ) |
| 1043 |
{ |
| 1044 |
try |
| 1045 |
{ |
| 1046 |
bool bJapaneseStyle = false; |
| 1047 |
xChartType->getPropertyValue( u"Japanese"_ustr ) >>= bJapaneseStyle; |
| 1048 |
|
| 1049 |
if( bJapaneseStyle ) |
| 1050 |
{ |
| 1051 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatStockLoss"_ustr ); |
| 1052 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatStockGain"_ustr ); |
| 1053 |
} |
| 1054 |
} |
| 1055 |
catch( const uno::Exception & ) |
| 1056 |
{ |
| 1057 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
if( bHasDataLabelsAtSeries ) |
| 1062 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatDataLabels"_ustr ); |
| 1063 |
if( bHasEquation ) |
| 1064 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatTrendlineEquation"_ustr ); |
| 1065 |
if( xMeanValue.is() ) |
| 1066 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatMeanValue"_ustr ); |
| 1067 |
if( bHasXErrorBars ) |
| 1068 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatXErrorBars"_ustr ); |
| 1069 |
if( bHasYErrorBars ) |
| 1070 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatYErrorBars"_ustr ); |
| 1071 |
|
| 1072 |
xPopupMenu->insertSeparator( -1 ); |
| 1073 |
|
| 1074 |
if( !bHasDataLabelsAtSeries ) |
| 1075 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertDataLabels"_ustr ); |
| 1076 |
|
| 1077 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertTrendline"_ustr ); |
| 1078 |
|
| 1079 |
if( !xMeanValue.is() ) |
| 1080 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertMeanValue"_ustr ); |
| 1081 |
if( !bHasXErrorBars ) |
| 1082 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertXErrorBars"_ustr ); |
| 1083 |
if( !bHasYErrorBars ) |
| 1084 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertYErrorBars"_ustr ); |
| 1085 |
if( bHasDataLabelsAtSeries || ( bHasDataLabelsAtPoints && bHasFormattedDataPointsOtherThanSelected ) ) |
| 1086 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteDataLabels"_ustr ); |
| 1087 |
if( bHasEquation ) |
| 1088 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteTrendlineEquation"_ustr ); |
| 1089 |
if( xMeanValue.is() ) |
| 1090 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteMeanValue"_ustr ); |
| 1091 |
if( bHasXErrorBars ) |
| 1092 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteXErrorBars"_ustr ); |
| 1093 |
if( bHasYErrorBars ) |
| 1094 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteYErrorBars"_ustr ); |
| 1095 |
|
| 1096 |
if( bHasFormattedDataPointsOtherThanSelected ) |
| 1097 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:ResetAllDataPoints"_ustr ); |
| 1098 |
|
| 1099 |
xPopupMenu->insertSeparator( -1 ); |
| 1100 |
|
| 1101 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId, u".uno:ArrangeRow"_ustr ); |
| 1102 |
rtl::Reference< VCLXPopupMenu > xArrangePopupMenu = new VCLXPopupMenu(); |
| 1103 |
sal_Int16 nSubId = nUniqueId + 1; |
| 1104 |
lcl_insertMenuCommand( xArrangePopupMenu, nSubId++, u".uno:Forward"_ustr ); |
| 1105 |
lcl_insertMenuCommand( xArrangePopupMenu, nSubId, u".uno:Backward"_ustr ); |
| 1106 |
xPopupMenu->setPopupMenu( nUniqueId, xArrangePopupMenu ); |
| 1107 |
nUniqueId = nSubId; |
| 1108 |
++nUniqueId; |
| 1109 |
} |
| 1110 |
else if( eObjectType == OBJECTTYPE_DATA_CURVE ) |
| 1111 |
{ |
| 1112 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteTrendline"_ustr ); |
| 1113 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatTrendlineEquation"_ustr ); |
| 1114 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertTrendlineEquation"_ustr ); |
| 1115 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertTrendlineEquationAndR2"_ustr ); |
| 1116 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertR2Value"_ustr ); |
| 1117 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteTrendlineEquation"_ustr ); |
| 1118 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteR2Value"_ustr ); |
| 1119 |
} |
| 1120 |
else if( eObjectType == OBJECTTYPE_DATA_CURVE_EQUATION ) |
| 1121 |
{ |
| 1122 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertR2Value"_ustr ); |
| 1123 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteR2Value"_ustr ); |
| 1124 |
} |
| 1125 |
|
| 1126 |
//some commands for axes: and grids |
| 1127 |
|
| 1128 |
else if( eObjectType == OBJECTTYPE_AXIS || eObjectType == OBJECTTYPE_GRID || eObjectType == OBJECTTYPE_SUBGRID ) |
| 1129 |
{ |
| 1130 |
rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); |
| 1131 |
if( xAxis.is() && xDiagram.is() ) |
| 1132 |
{ |
| 1133 |
sal_Int32 nDimensionIndex = -1; |
| 1134 |
sal_Int32 nCooSysIndex = -1; |
| 1135 |
sal_Int32 nAxisIndex = -1; |
| 1136 |
AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex ); |
| 1137 |
bool bIsSecondaryAxis = nAxisIndex!=0; |
| 1138 |
bool bIsAxisVisible = AxisHelper::isAxisVisible( xAxis ); |
| 1139 |
bool bIsMajorGridVisible = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, true /*bMainGrid*/, xDiagram ); |
| 1140 |
bool bIsMinorGridVisible = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, false /*bMainGrid*/, xDiagram ); |
| 1141 |
bool bHasTitle = !TitleHelper::getCompleteString( xAxis->getTitleObject2() ).isEmpty(); |
| 1142 |
|
| 1143 |
if( eObjectType != OBJECTTYPE_AXIS && bIsAxisVisible ) |
| 1144 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatAxis"_ustr ); |
| 1145 |
if( eObjectType != OBJECTTYPE_GRID && bIsMajorGridVisible && !bIsSecondaryAxis ) |
| 1146 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatMajorGrid"_ustr ); |
| 1147 |
if( eObjectType != OBJECTTYPE_SUBGRID && bIsMinorGridVisible && !bIsSecondaryAxis ) |
| 1148 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatMinorGrid"_ustr ); |
| 1149 |
|
| 1150 |
xPopupMenu->insertSeparator( -1 ); |
| 1151 |
|
| 1152 |
if( eObjectType != OBJECTTYPE_AXIS && !bIsAxisVisible ) |
| 1153 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertAxis"_ustr ); |
| 1154 |
if( eObjectType != OBJECTTYPE_GRID && !bIsMajorGridVisible && !bIsSecondaryAxis ) |
| 1155 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertMajorGrid"_ustr ); |
| 1156 |
if( eObjectType != OBJECTTYPE_SUBGRID && !bIsMinorGridVisible && !bIsSecondaryAxis ) |
| 1157 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertMinorGrid"_ustr ); |
| 1158 |
if( !bHasTitle ) |
| 1159 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertAxisTitle"_ustr ); |
| 1160 |
|
| 1161 |
if( bIsAxisVisible ) |
| 1162 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteAxis"_ustr ); |
| 1163 |
if( bIsMajorGridVisible && !bIsSecondaryAxis ) |
| 1164 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteMajorGrid"_ustr ); |
| 1165 |
if( bIsMinorGridVisible && !bIsSecondaryAxis ) |
| 1166 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteMinorGrid"_ustr ); |
| 1167 |
if (bIsAxisVisible) |
| 1168 |
lcl_insertMenuCommand(xPopupMenu, nUniqueId++, u".uno:InsertDataTable"_ustr); |
| 1169 |
} |
| 1170 |
} |
| 1171 |
else if (eObjectType == OBJECTTYPE_DATA_TABLE) |
| 1172 |
{ |
| 1173 |
lcl_insertMenuCommand(xPopupMenu, nUniqueId++, u".uno:DeleteDataTable"_ustr); |
| 1174 |
} |
| 1175 |
|
| 1176 |
if( eObjectType == OBJECTTYPE_DATA_STOCK_LOSS ) |
| 1177 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatStockGain"_ustr ); |
| 1178 |
else if( eObjectType == OBJECTTYPE_DATA_STOCK_GAIN ) |
| 1179 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:FormatStockLoss"_ustr ); |
| 1180 |
|
| 1181 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:TransformDialog"_ustr ); |
| 1182 |
|
| 1183 |
if( eObjectType == OBJECTTYPE_PAGE || eObjectType == OBJECTTYPE_DIAGRAM |
| 1184 |
|| eObjectType == OBJECTTYPE_DIAGRAM_WALL |
| 1185 |
|| eObjectType == OBJECTTYPE_DIAGRAM_FLOOR |
| 1186 |
|| eObjectType == OBJECTTYPE_UNKNOWN ) |
| 1187 |
{ |
| 1188 |
if( eObjectType != OBJECTTYPE_UNKNOWN ) |
| 1189 |
xPopupMenu->insertSeparator( -1 ); |
| 1190 |
bool bHasLegend = LegendHelper::hasLegend( xDiagram ); |
| 1191 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertTitles"_ustr ); |
| 1192 |
if( !bHasLegend ) |
| 1193 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertLegend"_ustr ); |
| 1194 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:InsertRemoveAxes"_ustr ); |
| 1195 |
if( bHasLegend ) |
| 1196 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DeleteLegend"_ustr ); |
| 1197 |
} |
| 1198 |
|
| 1199 |
xPopupMenu->insertSeparator( -1 ); |
| 1200 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DiagramType"_ustr ); |
| 1201 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DataRanges"_ustr ); |
| 1202 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:DiagramData"_ustr ); |
| 1203 |
lcl_insertMenuCommand( xPopupMenu, nUniqueId++, u".uno:View3D"_ustr ); |
| 1204 |
} |
| 1205 |
|
| 1206 |
css::uno::Sequence< css::uno::Any > aArgs{ |
| 1207 |
css::uno::Any(comphelper::makePropertyValue( u"IsContextMenu"_ustr, true )), |
| 1208 |
css::uno::Any(comphelper::makePropertyValue( u"Frame"_ustr, m_xFrame )), |
| 1209 |
css::uno::Any(comphelper::makePropertyValue( u"Value"_ustr, aMenuName )) |
| 1210 |
}; |
| 1211 |
|
| 1212 |
css::uno::Reference< css::frame::XPopupMenuController > xPopupController( |
| 1213 |
m_xCC->getServiceManager()->createInstanceWithArgumentsAndContext( |
| 1214 |
u"com.sun.star.comp.framework.ResourceMenuController"_ustr, aArgs, m_xCC ), css::uno::UNO_QUERY ); |
| 1215 |
|
| 1216 |
if ( !xPopupController.is() || !xPopupMenu.is() ) |
| 1217 |
return; |
| 1218 |
|
| 1219 |
xPopupController->setPopupMenu( xPopupMenu ); |
| 1220 |
|
| 1221 |
if (comphelper::LibreOfficeKit::isActive()) |
| 1222 |
{ |
| 1223 |
if (SfxViewShell* pViewShell = SfxViewShell::Current()) |
| 1224 |
{ |
| 1225 |
const ControllerCommandDispatch* pCommandDispatch = m_aDispatchContainer.getChartDispatcher(); |
| 1226 |
if (pCommandDispatch) |
| 1227 |
{ |
| 1228 |
for (int nPos = 0, nCount = xPopupMenu->getItemCount(); nPos < nCount; ++nPos) |
| 1229 |
{ |
| 1230 |
auto nItemId = xPopupMenu->getItemId(nPos); |
| 1231 |
OUString aCommandURL = xPopupMenu->getCommand(nItemId); |
| 1232 |
if (!pCommandDispatch->commandAvailable(aCommandURL)) |
| 1233 |
xPopupMenu->enableItem(nItemId, false); |
| 1234 |
} |
| 1235 |
} |
| 1236 |
|
| 1237 |
boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(xPopupMenu); |
| 1238 |
boost::property_tree::ptree aRoot; |
| 1239 |
aRoot.add_child("menu", aMenu); |
| 1240 |
|
| 1241 |
std::stringstream aStream; |
| 1242 |
boost::property_tree::write_json(aStream, aRoot, true); |
| 1243 |
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, OString(aStream.str())); |
| 1244 |
} |
| 1245 |
} |
| 1246 |
else |
| 1247 |
{ |
| 1248 |
xPopupMenu->execute( css::uno::Reference< css::awt::XWindowPeer >( m_xFrame->getContainerWindow(), css::uno::UNO_QUERY ), |
| 1249 |
css::awt::Rectangle( aPos.X(), aPos.Y(), 0, 0 ), |
| 1250 |
css::awt::PopupMenuDirection::EXECUTE_DEFAULT ); |
| 1251 |
} |
| 1252 |
|
| 1253 |
css::uno::Reference< css::lang::XComponent > xComponent( xPopupController, css::uno::UNO_QUERY ); |
| 1254 |
if ( xComponent.is() ) |
| 1255 |
xComponent->dispose(); |
| 1256 |
} |
| 1257 |
else if( ( rCEvt.GetCommand() == CommandEventId::StartExtTextInput ) || |
| 1258 |
( rCEvt.GetCommand() == CommandEventId::ExtTextInput ) || |
| 1259 |
( rCEvt.GetCommand() == CommandEventId::EndExtTextInput ) || |
| 1260 |
( rCEvt.GetCommand() == CommandEventId::InputContextChange ) ) |
| 1261 |
{ |
| 1262 |
//#i84417# enable editing with IME |
| 1263 |
m_pDrawViewWrapper->Command( rCEvt, pChartWindow ); |
| 1264 |
} |
| 1265 |
} |
| 1266 |
|
| 1267 |
bool ChartController::execute_KeyInput( const KeyEvent& rKEvt ) |
| 1268 |
{ |
| 1269 |
SolarMutexGuard aGuard; |
| 1270 |
bool bReturn=false; |
| 1271 |
|
| 1272 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 1273 |
auto pChartWindow(GetChartWindow()); |
| 1274 |
if (!pChartWindow || !pDrawViewWrapper) |
| 1275 |
return bReturn; |
| 1276 |
|
| 1277 |
// handle accelerators |
| 1278 |
if (!m_apAccelExecute && m_xFrame.is() && m_xCC.is()) |
| 1279 |
{ |
| 1280 |
m_apAccelExecute = ::svt::AcceleratorExecute::createAcceleratorHelper(); |
| 1281 |
OSL_ASSERT(m_apAccelExecute); |
| 1282 |
if (m_apAccelExecute) |
| 1283 |
m_apAccelExecute->init( m_xCC, m_xFrame ); |
| 1284 |
} |
| 1285 |
|
| 1286 |
vcl::KeyCode aKeyCode( rKEvt.GetKeyCode()); |
| 1287 |
sal_uInt16 nCode = aKeyCode.GetCode(); |
| 1288 |
bool bAlternate = aKeyCode.IsMod2(); |
| 1289 |
bool bCtrl = aKeyCode.IsMod1(); |
| 1290 |
|
| 1291 |
if (m_apAccelExecute) |
| 1292 |
bReturn = m_apAccelExecute->execute( aKeyCode ); |
| 1293 |
if( bReturn ) |
| 1294 |
return bReturn; |
| 1295 |
|
| 1296 |
if( pDrawViewWrapper->IsTextEdit() ) |
| 1297 |
{ |
| 1298 |
if( pDrawViewWrapper->KeyInput(rKEvt, pChartWindow) ) |
| 1299 |
{ |
| 1300 |
bReturn = true; |
| 1301 |
if( nCode == KEY_ESCAPE ) |
| 1302 |
{ |
| 1303 |
EndTextEdit(); |
| 1304 |
} |
| 1305 |
} |
| 1306 |
} |
| 1307 |
|
| 1308 |
// keyboard accessibility |
| 1309 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( m_aSelection.getSelectedCID() ); |
| 1310 |
if( ! bReturn ) |
| 1311 |
{ |
| 1312 |
// Navigation (Tab/F3/Home/End) |
| 1313 |
rtl::Reference<::chart::ChartModel> xChartDoc( getChartModel() ); |
| 1314 |
ObjectKeyNavigation aObjNav( m_aSelection.getSelectedOID(), xChartDoc, m_xChartView.get() ); |
| 1315 |
awt::KeyEvent aKeyEvent( ::svt::AcceleratorExecute::st_VCLKey2AWTKey( aKeyCode )); |
| 1316 |
bReturn = aObjNav.handleKeyEvent( aKeyEvent ); |
| 1317 |
if( bReturn ) |
| 1318 |
{ |
| 1319 |
const ObjectIdentifier& aNewOID = aObjNav.getCurrentSelection(); |
| 1320 |
uno::Any aNewSelection; |
| 1321 |
if ( aNewOID.isValid() && !ObjectHierarchy::isRootNode( aNewOID ) ) |
| 1322 |
{ |
| 1323 |
aNewSelection = aNewOID.getAny(); |
| 1324 |
} |
| 1325 |
if ( m_eDragMode == SdrDragMode::Rotate && !SelectionHelper::isRotateableObject( aNewOID.getObjectCID(), getChartModel() ) ) |
| 1326 |
{ |
| 1327 |
m_eDragMode = SdrDragMode::Move; |
| 1328 |
} |
| 1329 |
bReturn = select( aNewSelection ); |
| 1330 |
} |
| 1331 |
} |
| 1332 |
|
| 1333 |
// Position and Size (+/-/arrow-keys) or pie segment dragging |
| 1334 |
if( ! bReturn ) |
| 1335 |
{ |
| 1336 |
// pie segment dragging |
| 1337 |
// note: could also be done for data series |
| 1338 |
if( eObjectType == OBJECTTYPE_DATA_POINT && |
| 1339 |
ObjectIdentifier::getDragMethodServiceName( m_aSelection.getSelectedCID() ) == |
| 1340 |
ObjectIdentifier::getPieSegmentDragMethodServiceName()) |
| 1341 |
{ |
| 1342 |
bool bDrag = false; |
| 1343 |
bool bDragInside = false; |
| 1344 |
if( nCode == KEY_ADD || |
| 1345 |
nCode == KEY_SUBTRACT ) |
| 1346 |
{ |
| 1347 |
bDrag = true; |
| 1348 |
bDragInside = ( nCode == KEY_SUBTRACT ); |
| 1349 |
} |
| 1350 |
else if( |
| 1351 |
nCode == KEY_LEFT || |
| 1352 |
nCode == KEY_RIGHT || |
| 1353 |
nCode == KEY_UP || |
| 1354 |
nCode == KEY_DOWN ) |
| 1355 |
{ |
| 1356 |
bDrag = true; |
| 1357 |
std::u16string_view aParameter( ObjectIdentifier::getDragParameterString( m_aSelection.getSelectedCID() )); |
| 1358 |
sal_Int32 nOffsetPercentDummy( 0 ); |
| 1359 |
awt::Point aMinimumPosition( 0, 0 ); |
| 1360 |
awt::Point aMaximumPosition( 0, 0 ); |
| 1361 |
ObjectIdentifier::parsePieSegmentDragParameterString( |
| 1362 |
aParameter, nOffsetPercentDummy, aMinimumPosition, aMaximumPosition ); |
| 1363 |
aMaximumPosition.Y -= aMinimumPosition.Y; |
| 1364 |
aMaximumPosition.X -= aMinimumPosition.X; |
| 1365 |
|
| 1366 |
bDragInside = |
| 1367 |
(nCode == KEY_RIGHT && (aMaximumPosition.X < 0)) || |
| 1368 |
(nCode == KEY_LEFT && (aMaximumPosition.X > 0)) || |
| 1369 |
(nCode == KEY_DOWN && (aMaximumPosition.Y < 0)) || |
| 1370 |
(nCode == KEY_UP && (aMaximumPosition.Y > 0)); |
| 1371 |
} |
| 1372 |
|
| 1373 |
if( bDrag ) |
| 1374 |
{ |
| 1375 |
double fAmount = bAlternate ? 0.01 : 0.05; |
| 1376 |
if( bDragInside ) |
| 1377 |
fAmount *= -1.0; |
| 1378 |
|
| 1379 |
bReturn = impl_DragDataPoint( m_aSelection.getSelectedCID(), fAmount ); |
| 1380 |
} |
| 1381 |
} |
| 1382 |
else |
| 1383 |
{ |
| 1384 |
// size |
| 1385 |
if( nCode == KEY_ADD || |
| 1386 |
nCode == KEY_SUBTRACT ) |
| 1387 |
{ |
| 1388 |
if( eObjectType == OBJECTTYPE_DIAGRAM ) |
| 1389 |
{ |
| 1390 |
// default 1 mm in each direction |
| 1391 |
double fGrowAmountX = 200.0; |
| 1392 |
double fGrowAmountY = 200.0; |
| 1393 |
if (bAlternate) |
| 1394 |
{ |
| 1395 |
// together with Alt-key: 1 px in each direction |
| 1396 |
Size aPixelSize = pChartWindow->PixelToLogic( Size( 2, 2 )); |
| 1397 |
fGrowAmountX = static_cast< double >( aPixelSize.Width()); |
| 1398 |
fGrowAmountY = static_cast< double >( aPixelSize.Height()); |
| 1399 |
} |
| 1400 |
if( nCode == KEY_SUBTRACT ) |
| 1401 |
{ |
| 1402 |
fGrowAmountX = -fGrowAmountX; |
| 1403 |
fGrowAmountY = -fGrowAmountY; |
| 1404 |
} |
| 1405 |
bReturn = impl_moveOrResizeObject( |
| 1406 |
m_aSelection.getSelectedCID(), CENTERED_RESIZE_OBJECT, fGrowAmountX, fGrowAmountY ); |
| 1407 |
} |
| 1408 |
} |
| 1409 |
// position |
| 1410 |
else if( nCode == KEY_LEFT || |
| 1411 |
nCode == KEY_RIGHT || |
| 1412 |
nCode == KEY_UP || |
| 1413 |
nCode == KEY_DOWN ) |
| 1414 |
{ |
| 1415 |
if( m_aSelection.isDragableObjectSelected() ) |
| 1416 |
{ |
| 1417 |
// default 1 mm |
| 1418 |
double fShiftAmountX = 100.0; |
| 1419 |
double fShiftAmountY = 100.0; |
| 1420 |
if (bAlternate) |
| 1421 |
{ |
| 1422 |
// together with Alt-key: 1 px |
| 1423 |
Size aPixelSize = pChartWindow->PixelToLogic( Size( 1, 1 )); |
| 1424 |
fShiftAmountX = static_cast< double >( aPixelSize.Width()); |
| 1425 |
fShiftAmountY = static_cast< double >( aPixelSize.Height()); |
| 1426 |
} |
| 1427 |
switch( nCode ) |
| 1428 |
{ |
| 1429 |
case KEY_LEFT: |
| 1430 |
fShiftAmountX = -fShiftAmountX; |
| 1431 |
fShiftAmountY = 0.0; |
| 1432 |
break; |
| 1433 |
case KEY_RIGHT: |
| 1434 |
fShiftAmountY = 0.0; |
| 1435 |
break; |
| 1436 |
case KEY_UP: |
| 1437 |
fShiftAmountX = 0.0; |
| 1438 |
fShiftAmountY = -fShiftAmountY; |
| 1439 |
break; |
| 1440 |
case KEY_DOWN: |
| 1441 |
fShiftAmountX = 0.0; |
| 1442 |
break; |
| 1443 |
} |
| 1444 |
if( !m_aSelection.getSelectedCID().isEmpty() ) |
| 1445 |
{ |
| 1446 |
//move chart objects |
| 1447 |
if (eObjectType == OBJECTTYPE_DATA_LABEL) |
| 1448 |
{ |
| 1449 |
SdrObject* pObj = pDrawViewWrapper->getSelectedObject(); |
| 1450 |
if (pObj) |
| 1451 |
{ |
| 1452 |
tools::Rectangle aRect = pObj->GetSnapRect(); |
| 1453 |
awt::Size aPageSize(getChartModel()->getPageSize()); |
| 1454 |
if ((fShiftAmountX > 0.0 && (aRect.Right() + fShiftAmountX > aPageSize.Width)) || |
| 1455 |
(fShiftAmountX < 0.0 && (aRect.Left() + fShiftAmountX < 0)) || |
| 1456 |
(fShiftAmountY > 0.0 && (aRect.Bottom() + fShiftAmountY > aPageSize.Height)) || |
| 1457 |
(fShiftAmountY < 0.0 && (aRect.Top() + fShiftAmountY < 0))) |
| 1458 |
bReturn = false; |
| 1459 |
else |
| 1460 |
bReturn = PositionAndSizeHelper::moveObject( |
| 1461 |
m_aSelection.getSelectedCID(), getChartModel(), |
| 1462 |
awt::Rectangle(aRect.Left() + fShiftAmountX, aRect.Top() + fShiftAmountY, aRect.getOpenWidth(), aRect.getOpenHeight()), |
| 1463 |
awt::Rectangle(aRect.Left(), aRect.Top(), 0, 0), |
| 1464 |
awt::Rectangle(0, 0, aPageSize.Width, aPageSize.Height)); |
| 1465 |
} |
| 1466 |
} |
| 1467 |
else |
| 1468 |
bReturn = impl_moveOrResizeObject( |
| 1469 |
m_aSelection.getSelectedCID(), MOVE_OBJECT, fShiftAmountX, fShiftAmountY ); |
| 1470 |
} |
| 1471 |
else |
| 1472 |
{ |
| 1473 |
//move additional shapes |
| 1474 |
uno::Reference< drawing::XShape > xShape( m_aSelection.getSelectedAdditionalShape() ); |
| 1475 |
if( xShape.is() ) |
| 1476 |
{ |
| 1477 |
awt::Point aPos( xShape->getPosition() ); |
| 1478 |
awt::Size aSize( xShape->getSize() ); |
| 1479 |
awt::Size aPageSize( getChartModel()->getPageSize() ); |
| 1480 |
aPos.X = static_cast< tools::Long >( static_cast< double >( aPos.X ) + fShiftAmountX ); |
| 1481 |
aPos.Y = static_cast< tools::Long >( static_cast< double >( aPos.Y ) + fShiftAmountY ); |
| 1482 |
if( aPos.X + aSize.Width > aPageSize.Width ) |
| 1483 |
aPos.X = aPageSize.Width - aSize.Width; |
| 1484 |
if( aPos.X < 0 ) |
| 1485 |
aPos.X = 0; |
| 1486 |
if( aPos.Y + aSize.Height > aPageSize.Height ) |
| 1487 |
aPos.Y = aPageSize.Height - aSize.Height; |
| 1488 |
if( aPos.Y < 0 ) |
| 1489 |
aPos.Y = 0; |
| 1490 |
|
| 1491 |
xShape->setPosition( aPos ); |
| 1492 |
} |
| 1493 |
} |
| 1494 |
} |
| 1495 |
} |
| 1496 |
} |
| 1497 |
} |
| 1498 |
|
| 1499 |
// dumping the shape |
| 1500 |
if( !bReturn && bCtrl && nCode == KEY_F12) |
| 1501 |
{ |
| 1502 |
rtl::Reference< ChartModel > xChartModel = getChartModel(); |
| 1503 |
if(xChartModel.is()) |
| 1504 |
{ |
| 1505 |
OUString aDump = xChartModel->dump(u"shapes"_ustr); |
| 1506 |
SAL_WARN("chart2", aDump); |
| 1507 |
} |
| 1508 |
} |
| 1509 |
|
| 1510 |
// text edit |
| 1511 |
if( ! bReturn && |
| 1512 |
nCode == KEY_F2 ) |
| 1513 |
{ |
| 1514 |
if( eObjectType == OBJECTTYPE_TITLE ) |
| 1515 |
{ |
| 1516 |
executeDispatch_EditText(); |
| 1517 |
bReturn = true; |
| 1518 |
} |
| 1519 |
} |
| 1520 |
|
| 1521 |
// deactivate inplace mode (this code should be unnecessary, but |
| 1522 |
// unfortunately is not) |
| 1523 |
if( ! bReturn && |
| 1524 |
nCode == KEY_ESCAPE ) |
| 1525 |
{ |
| 1526 |
uno::Reference< frame::XDispatchHelper > xDispatchHelper( frame::DispatchHelper::create(m_xCC) ); |
| 1527 |
uno::Sequence< beans::PropertyValue > aArgs; |
| 1528 |
xDispatchHelper->executeDispatch( |
| 1529 |
uno::Reference< frame::XDispatchProvider >( m_xFrame, uno::UNO_QUERY ), |
| 1530 |
u".uno:TerminateInplaceActivation"_ustr, |
| 1531 |
u"_parent"_ustr, |
| 1532 |
frame::FrameSearchFlag::PARENT, |
| 1533 |
aArgs ); |
| 1534 |
bReturn = true; |
| 1535 |
} |
| 1536 |
|
| 1537 |
if( ! bReturn && |
| 1538 |
(nCode == KEY_DELETE || nCode == KEY_BACKSPACE )) |
| 1539 |
{ |
| 1540 |
bReturn = executeDispatch_Delete(); |
| 1541 |
if( ! bReturn ) |
| 1542 |
{ |
| 1543 |
std::shared_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pChartWindow->GetFrameWeld(), |
| 1544 |
VclMessageType::Info, VclButtonsType::Ok, |
| 1545 |
SchResId(STR_ACTION_NOTPOSSIBLE))); |
| 1546 |
xInfoBox->runAsync(xInfoBox, [] (int) {}); |
| 1547 |
} |
| 1548 |
} |
| 1549 |
|
| 1550 |
return bReturn; |
| 1551 |
} |
| 1552 |
|
| 1553 |
bool ChartController::requestQuickHelp( |
| 1554 |
::Point aAtLogicPosition, |
| 1555 |
bool bIsBalloonHelp, |
| 1556 |
OUString & rOutQuickHelpText, |
| 1557 |
awt::Rectangle & rOutEqualRect ) |
| 1558 |
{ |
| 1559 |
rtl::Reference<::chart::ChartModel> xChartModel; |
| 1560 |
if( m_aModel.is()) |
| 1561 |
xChartModel = getChartModel(); |
| 1562 |
if( !xChartModel.is()) |
| 1563 |
return false; |
| 1564 |
|
| 1565 |
// help text |
| 1566 |
OUString aCID; |
| 1567 |
if( m_pDrawViewWrapper ) |
| 1568 |
{ |
| 1569 |
aCID = SelectionHelper::getHitObjectCID( |
| 1570 |
aAtLogicPosition, *m_pDrawViewWrapper ); |
| 1571 |
} |
| 1572 |
bool bResult( !aCID.isEmpty()); |
| 1573 |
|
| 1574 |
if( bResult ) |
| 1575 |
{ |
| 1576 |
// get help text |
| 1577 |
rOutQuickHelpText = ObjectNameProvider::getHelpText( aCID, xChartModel, bIsBalloonHelp /* bVerbose */ ); |
| 1578 |
|
| 1579 |
// set rectangle |
| 1580 |
if( m_xChartView ) |
| 1581 |
rOutEqualRect = m_xChartView->getRectangleOfObject( aCID, true ); |
| 1582 |
} |
| 1583 |
|
| 1584 |
return bResult; |
| 1585 |
} |
| 1586 |
|
| 1587 |
// XSelectionSupplier (optional interface) |
| 1588 |
sal_Bool SAL_CALL ChartController::select( const uno::Any& rSelection ) |
| 1589 |
{ |
| 1590 |
bool bSuccess = false; |
| 1591 |
|
| 1592 |
if ( rSelection.hasValue() ) |
| 1593 |
{ |
| 1594 |
if (rSelection.getValueType() == cppu::UnoType<OUString>::get()) |
| 1595 |
{ |
| 1596 |
OUString aNewCID; |
| 1597 |
if ( ( rSelection >>= aNewCID ) && m_aSelection.setSelection( aNewCID ) ) |
| 1598 |
{ |
| 1599 |
bSuccess = true; |
| 1600 |
} |
| 1601 |
} |
| 1602 |
else if (uno::Reference<drawing::XShape> xShape; rSelection >>= xShape) |
| 1603 |
{ |
| 1604 |
if (m_aSelection.setSelection(xShape)) |
| 1605 |
{ |
| 1606 |
bSuccess = true; |
| 1607 |
} |
| 1608 |
} |
| 1609 |
} |
| 1610 |
else |
| 1611 |
{ |
| 1612 |
if ( m_aSelection.hasSelection() ) |
| 1613 |
{ |
| 1614 |
m_aSelection.clearSelection(); |
| 1615 |
bSuccess = true; |
| 1616 |
} |
| 1617 |
} |
| 1618 |
|
| 1619 |
if ( bSuccess ) |
| 1620 |
{ |
| 1621 |
SolarMutexGuard aGuard; |
| 1622 |
if ( m_pDrawViewWrapper && m_pDrawViewWrapper->IsTextEdit() ) |
| 1623 |
{ |
| 1624 |
EndTextEdit(); |
| 1625 |
} |
| 1626 |
impl_selectObjectAndNotiy(); |
| 1627 |
auto pChartWindow(GetChartWindow()); |
| 1628 |
if ( pChartWindow ) |
| 1629 |
{ |
| 1630 |
pChartWindow->Invalidate(); |
| 1631 |
} |
| 1632 |
return true; |
| 1633 |
} |
| 1634 |
|
| 1635 |
return false; |
| 1636 |
} |
| 1637 |
|
| 1638 |
uno::Any SAL_CALL ChartController::getSelection() |
| 1639 |
{ |
| 1640 |
uno::Any aReturn; |
| 1641 |
if ( m_aSelection.hasSelection() ) |
| 1642 |
{ |
| 1643 |
OUString aCID( m_aSelection.getSelectedCID() ); |
| 1644 |
if ( !aCID.isEmpty() ) |
| 1645 |
{ |
| 1646 |
aReturn <<= aCID; |
| 1647 |
} |
| 1648 |
else |
| 1649 |
{ |
| 1650 |
// #i12587# support for shapes in chart |
| 1651 |
aReturn <<= m_aSelection.getSelectedAdditionalShape(); |
| 1652 |
} |
| 1653 |
} |
| 1654 |
return aReturn; |
| 1655 |
} |
| 1656 |
|
| 1657 |
void SAL_CALL ChartController::addSelectionChangeListener( const uno::Reference<view::XSelectionChangeListener> & xListener ) |
| 1658 |
{ |
| 1659 |
SolarMutexGuard aGuard; |
| 1660 |
if( impl_isDisposedOrSuspended() )//@todo? allow adding of listeners in suspend mode? |
| 1661 |
return; //behave passive if already disposed or suspended |
| 1662 |
|
| 1663 |
//--add listener |
| 1664 |
std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex); |
| 1665 |
m_aLifeTimeManager.m_aSelectionChangeListeners.addInterface( aGuard2, xListener ); |
| 1666 |
} |
| 1667 |
|
| 1668 |
void SAL_CALL ChartController::removeSelectionChangeListener( const uno::Reference<view::XSelectionChangeListener> & xListener ) |
| 1669 |
{ |
| 1670 |
SolarMutexGuard aGuard; |
| 1671 |
if( impl_isDisposedOrSuspended() ) //@todo? allow removing of listeners in suspend mode? |
| 1672 |
return; //behave passive if already disposed or suspended |
| 1673 |
|
| 1674 |
//--remove listener |
| 1675 |
std::unique_lock aGuard2(m_aLifeTimeManager.m_aAccessMutex); |
| 1676 |
m_aLifeTimeManager.m_aSelectionChangeListeners.removeInterface( aGuard2, xListener ); |
| 1677 |
} |
| 1678 |
|
| 1679 |
void ChartController::impl_notifySelectionChangeListeners() |
| 1680 |
{ |
| 1681 |
std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex); |
| 1682 |
if( m_aLifeTimeManager.m_aSelectionChangeListeners.getLength(aGuard) ) |
| 1683 |
{ |
| 1684 |
uno::Reference< view::XSelectionSupplier > xSelectionSupplier(this); |
| 1685 |
lang::EventObject aEvent( xSelectionSupplier ); |
| 1686 |
m_aLifeTimeManager.m_aSelectionChangeListeners.notifyEach(aGuard, &view::XSelectionChangeListener::selectionChanged, aEvent); |
| 1687 |
} |
| 1688 |
} |
| 1689 |
|
| 1690 |
void ChartController::impl_selectObjectAndNotiy() |
| 1691 |
{ |
| 1692 |
{ |
| 1693 |
SolarMutexGuard aGuard; |
| 1694 |
DrawViewWrapper* pDrawViewWrapper = m_pDrawViewWrapper.get(); |
| 1695 |
if( pDrawViewWrapper ) |
| 1696 |
{ |
| 1697 |
pDrawViewWrapper->SetDragMode( m_eDragMode ); |
| 1698 |
m_aSelection.applySelection( m_pDrawViewWrapper.get() ); |
| 1699 |
} |
| 1700 |
} |
| 1701 |
impl_notifySelectionChangeListeners(); |
| 1702 |
} |
| 1703 |
|
| 1704 |
bool ChartController::impl_moveOrResizeObject( |
| 1705 |
const OUString & rCID, |
| 1706 |
eMoveOrResizeType eType, |
| 1707 |
double fAmountLogicX, |
| 1708 |
double fAmountLogicY ) |
| 1709 |
{ |
| 1710 |
bool bResult = false; |
| 1711 |
bool bNeedResize = ( eType == CENTERED_RESIZE_OBJECT ); |
| 1712 |
|
| 1713 |
rtl::Reference<::chart::ChartModel> xChartModel( getChartModel() ); |
| 1714 |
uno::Reference< beans::XPropertySet > xObjProp( |
| 1715 |
ObjectIdentifier::getObjectPropertySet( rCID, xChartModel )); |
| 1716 |
if( xObjProp.is()) |
| 1717 |
{ |
| 1718 |
awt::Size aRefSize = xChartModel->getPageSize(); |
| 1719 |
|
| 1720 |
chart2::RelativePosition aRelPos; |
| 1721 |
chart2::RelativeSize aRelSize; |
| 1722 |
bool bDeterminePos = !(xObjProp->getPropertyValue( u"RelativePosition"_ustr) >>= aRelPos); |
| 1723 |
bool bDetermineSize = !bNeedResize || !(xObjProp->getPropertyValue( u"RelativeSize"_ustr) >>= aRelSize); |
| 1724 |
|
| 1725 |
if( ( bDeterminePos || bDetermineSize ) && |
| 1726 |
( aRefSize.Width > 0 && aRefSize.Height > 0 ) ) |
| 1727 |
{ |
| 1728 |
ChartView * pValueProvider( m_xChartView.get() ); |
| 1729 |
if( pValueProvider ) |
| 1730 |
{ |
| 1731 |
awt::Rectangle aRect( pValueProvider->getRectangleOfObject( rCID )); |
| 1732 |
double fWidth = static_cast< double >( aRefSize.Width ); |
| 1733 |
double fHeight = static_cast< double >( aRefSize.Height ); |
| 1734 |
if( bDetermineSize ) |
| 1735 |
{ |
| 1736 |
aRelSize.Primary = static_cast< double >( aRect.Width ) / fWidth; |
| 1737 |
aRelSize.Secondary = static_cast< double >( aRect.Height ) / fHeight; |
| 1738 |
} |
| 1739 |
if( bDeterminePos ) |
| 1740 |
{ |
| 1741 |
if( bNeedResize && aRelSize.Primary > 0.0 && aRelSize.Secondary > 0.0 ) |
| 1742 |
{ |
| 1743 |
aRelPos.Primary = (static_cast< double >( aRect.X ) / fWidth) + |
| 1744 |
(aRelSize.Primary / 2.0); |
| 1745 |
aRelPos.Secondary = (static_cast< double >( aRect.Y ) / fHeight) + |
| 1746 |
(aRelSize.Secondary / 2.0); |
| 1747 |
aRelPos.Anchor = drawing::Alignment_CENTER; |
| 1748 |
} |
| 1749 |
else |
| 1750 |
{ |
| 1751 |
aRelPos.Primary = static_cast< double >( aRect.X ) / fWidth; |
| 1752 |
aRelPos.Secondary = static_cast< double >( aRect.Y ) / fHeight; |
| 1753 |
aRelPos.Anchor = drawing::Alignment_TOP_LEFT; |
| 1754 |
} |
| 1755 |
} |
| 1756 |
} |
| 1757 |
} |
| 1758 |
|
| 1759 |
if( eType == CENTERED_RESIZE_OBJECT ) |
| 1760 |
bResult = lcl_GrowAndShiftLogic( aRelPos, aRelSize, aRefSize, fAmountLogicX, fAmountLogicY ); |
| 1761 |
else if( eType == MOVE_OBJECT ) |
| 1762 |
bResult = lcl_MoveObjectLogic( aRelPos, aRelSize, aRefSize, fAmountLogicX, fAmountLogicY ); |
| 1763 |
|
| 1764 |
if( bResult ) |
| 1765 |
{ |
| 1766 |
ActionDescriptionProvider::ActionType eActionType(ActionDescriptionProvider::ActionType::Move); |
| 1767 |
if( bNeedResize ) |
| 1768 |
eActionType = ActionDescriptionProvider::ActionType::Resize; |
| 1769 |
|
| 1770 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( rCID ); |
| 1771 |
UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( |
| 1772 |
eActionType, ObjectNameProvider::getName( eObjectType )), m_xUndoManager ); |
| 1773 |
{ |
| 1774 |
ControllerLockGuardUNO aCLGuard( xChartModel ); |
| 1775 |
xObjProp->setPropertyValue( u"RelativePosition"_ustr, uno::Any( aRelPos )); |
| 1776 |
if( bNeedResize || (eObjectType == OBJECTTYPE_DIAGRAM) )//Also set an explicit size at the diagram when an explicit position is set |
| 1777 |
xObjProp->setPropertyValue( u"RelativeSize"_ustr, uno::Any( aRelSize )); |
| 1778 |
} |
| 1779 |
aUndoGuard.commit(); |
| 1780 |
} |
| 1781 |
} |
| 1782 |
return bResult; |
| 1783 |
} |
| 1784 |
|
| 1785 |
bool ChartController::impl_DragDataPoint( std::u16string_view rCID, double fAdditionalOffset ) |
| 1786 |
{ |
| 1787 |
bool bResult = false; |
| 1788 |
if( fAdditionalOffset < -1.0 || fAdditionalOffset > 1.0 || fAdditionalOffset == 0.0 ) |
| 1789 |
return bResult; |
| 1790 |
|
| 1791 |
sal_Int32 nDataPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( rCID ); |
| 1792 |
rtl::Reference< DataSeries > xSeries = |
| 1793 |
ObjectIdentifier::getDataSeriesForCID( rCID, getChartModel() ); |
| 1794 |
if( xSeries.is()) |
| 1795 |
{ |
| 1796 |
try |
| 1797 |
{ |
| 1798 |
uno::Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex( nDataPointIndex )); |
| 1799 |
double fOffset = 0.0; |
| 1800 |
if( xPointProp.is() && |
| 1801 |
(xPointProp->getPropertyValue( u"Offset"_ustr ) >>= fOffset ) && |
| 1802 |
(( fAdditionalOffset > 0.0 && fOffset < 1.0 ) || (fOffset > 0.0)) ) |
| 1803 |
{ |
| 1804 |
fOffset += fAdditionalOffset; |
| 1805 |
if( fOffset > 1.0 ) |
| 1806 |
fOffset = 1.0; |
| 1807 |
else if( fOffset < 0.0 ) |
| 1808 |
fOffset = 0.0; |
| 1809 |
xPointProp->setPropertyValue( u"Offset"_ustr, uno::Any( fOffset )); |
| 1810 |
bResult = true; |
| 1811 |
} |
| 1812 |
} |
| 1813 |
catch( const uno::Exception & ) |
| 1814 |
{ |
| 1815 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 1816 |
} |
| 1817 |
} |
| 1818 |
|
| 1819 |
return bResult; |
| 1820 |
} |
| 1821 |
|
| 1822 |
void ChartController::impl_SetMousePointer( const MouseEvent & rEvent ) |
| 1823 |
{ |
| 1824 |
SolarMutexGuard aGuard; |
| 1825 |
auto pChartWindow(GetChartWindow()); |
| 1826 |
|
| 1827 |
if (!m_pDrawViewWrapper || !pChartWindow) |
| 1828 |
return; |
| 1829 |
|
| 1830 |
Point aMousePos( pChartWindow->PixelToLogic( rEvent.GetPosPixel())); |
| 1831 |
sal_uInt16 nModifier = rEvent.GetModifier(); |
| 1832 |
bool bLeftDown = rEvent.IsLeft(); |
| 1833 |
|
| 1834 |
// Check if object is for field button and set the normal arrow pointer in this case |
| 1835 |
SdrObject* pObject = m_pDrawViewWrapper->getHitObject(aMousePos); |
| 1836 |
if (pObject && pObject->GetName().startsWith("FieldButton")) |
| 1837 |
{ |
| 1838 |
pChartWindow->SetPointer(PointerStyle::Arrow); |
| 1839 |
return; |
| 1840 |
} |
| 1841 |
|
| 1842 |
if ( m_pDrawViewWrapper->IsTextEdit() ) |
| 1843 |
{ |
| 1844 |
if( m_pDrawViewWrapper->IsTextEditHit( aMousePos ) ) |
| 1845 |
{ |
| 1846 |
pChartWindow->SetPointer( m_pDrawViewWrapper->GetPreferredPointer( |
| 1847 |
aMousePos, pChartWindow->GetOutDev(), nModifier, bLeftDown ) ); |
| 1848 |
return; |
| 1849 |
} |
| 1850 |
} |
| 1851 |
else if( m_pDrawViewWrapper->IsAction() ) |
| 1852 |
{ |
| 1853 |
return;//don't change pointer during running action |
| 1854 |
} |
| 1855 |
|
| 1856 |
SdrHdl* pHitSelectionHdl = nullptr; |
| 1857 |
if( m_aSelection.isResizeableObjectSelected() ) |
| 1858 |
pHitSelectionHdl = m_pDrawViewWrapper->PickHandle( aMousePos ); |
| 1859 |
|
| 1860 |
if( pHitSelectionHdl ) |
| 1861 |
{ |
| 1862 |
PointerStyle aPointer = m_pDrawViewWrapper->GetPreferredPointer( |
| 1863 |
aMousePos, pChartWindow->GetOutDev(), nModifier, bLeftDown ); |
| 1864 |
bool bForceArrowPointer = false; |
| 1865 |
|
| 1866 |
ObjectIdentifier aOID( m_aSelection.getSelectedOID() ); |
| 1867 |
|
| 1868 |
switch( aPointer) |
| 1869 |
{ |
| 1870 |
case PointerStyle::NSize: |
| 1871 |
case PointerStyle::SSize: |
| 1872 |
case PointerStyle::WSize: |
| 1873 |
case PointerStyle::ESize: |
| 1874 |
case PointerStyle::NWSize: |
| 1875 |
case PointerStyle::NESize: |
| 1876 |
case PointerStyle::SWSize: |
| 1877 |
case PointerStyle::SESize: |
| 1878 |
if( ! m_aSelection.isResizeableObjectSelected() ) |
| 1879 |
bForceArrowPointer = true; |
| 1880 |
break; |
| 1881 |
case PointerStyle::Move: |
| 1882 |
if ( !aOID.isDragableObject() ) |
| 1883 |
bForceArrowPointer = true; |
| 1884 |
break; |
| 1885 |
case PointerStyle::MovePoint: |
| 1886 |
case PointerStyle::MoveBezierWeight: |
| 1887 |
// there is no point-editing in a chart |
| 1888 |
// the PointerStyle::MoveBezierWeight appears in 3d data points |
| 1889 |
bForceArrowPointer = true; |
| 1890 |
break; |
| 1891 |
default: |
| 1892 |
break; |
| 1893 |
} |
| 1894 |
|
| 1895 |
if( bForceArrowPointer ) |
| 1896 |
pChartWindow->SetPointer( PointerStyle::Arrow ); |
| 1897 |
else |
| 1898 |
pChartWindow->SetPointer( aPointer ); |
| 1899 |
|
| 1900 |
return; |
| 1901 |
} |
| 1902 |
|
| 1903 |
// #i12587# support for shapes in chart |
| 1904 |
if ( m_eDrawMode == CHARTDRAW_INSERT && |
| 1905 |
( !m_pDrawViewWrapper->IsMarkedHit( aMousePos ) || !m_aSelection.isDragableObjectSelected() ) ) |
| 1906 |
{ |
| 1907 |
PointerStyle ePointerStyle = PointerStyle::DrawRect; |
| 1908 |
SdrObjKind eKind = m_pDrawViewWrapper->GetCurrentObjIdentifier(); |
| 1909 |
switch ( eKind ) |
| 1910 |
{ |
| 1911 |
case SdrObjKind::Line: |
| 1912 |
{ |
| 1913 |
ePointerStyle = PointerStyle::DrawLine; |
| 1914 |
} |
| 1915 |
break; |
| 1916 |
case SdrObjKind::Rectangle: |
| 1917 |
case SdrObjKind::CustomShape: |
| 1918 |
{ |
| 1919 |
ePointerStyle = PointerStyle::DrawRect; |
| 1920 |
} |
| 1921 |
break; |
| 1922 |
case SdrObjKind::CircleOrEllipse: |
| 1923 |
{ |
| 1924 |
ePointerStyle = PointerStyle::DrawEllipse; |
| 1925 |
} |
| 1926 |
break; |
| 1927 |
case SdrObjKind::FreehandLine: |
| 1928 |
{ |
| 1929 |
ePointerStyle = PointerStyle::DrawPolygon; |
| 1930 |
} |
| 1931 |
break; |
| 1932 |
case SdrObjKind::Text: |
| 1933 |
{ |
| 1934 |
ePointerStyle = PointerStyle::DrawText; |
| 1935 |
} |
| 1936 |
break; |
| 1937 |
case SdrObjKind::Caption: |
| 1938 |
{ |
| 1939 |
ePointerStyle = PointerStyle::DrawCaption; |
| 1940 |
} |
| 1941 |
break; |
| 1942 |
default: |
| 1943 |
{ |
| 1944 |
ePointerStyle = PointerStyle::DrawRect; |
| 1945 |
} |
| 1946 |
break; |
| 1947 |
} |
| 1948 |
pChartWindow->SetPointer( ePointerStyle ); |
| 1949 |
return; |
| 1950 |
} |
| 1951 |
|
| 1952 |
OUString aHitObjectCID( |
| 1953 |
SelectionHelper::getHitObjectCID( |
| 1954 |
aMousePos, *m_pDrawViewWrapper, true /*bGetDiagramInsteadOf_Wall*/ )); |
| 1955 |
|
| 1956 |
if( m_pDrawViewWrapper->IsTextEdit() ) |
| 1957 |
{ |
| 1958 |
if( aHitObjectCID == m_aSelection.getSelectedCID() ) |
| 1959 |
{ |
| 1960 |
pChartWindow->SetPointer( PointerStyle::Arrow ); |
| 1961 |
return; |
| 1962 |
} |
| 1963 |
} |
| 1964 |
|
| 1965 |
if( aHitObjectCID.isEmpty() ) |
| 1966 |
{ |
| 1967 |
//additional shape was hit |
| 1968 |
pChartWindow->SetPointer( PointerStyle::Move ); |
| 1969 |
} |
| 1970 |
else if( ObjectIdentifier::isDragableObject( aHitObjectCID ) ) |
| 1971 |
{ |
| 1972 |
if( (m_eDragMode == SdrDragMode::Rotate) |
| 1973 |
&& SelectionHelper::isRotateableObject( aHitObjectCID |
| 1974 |
, getChartModel() ) ) |
| 1975 |
pChartWindow->SetPointer( PointerStyle::Rotate ); |
| 1976 |
else |
| 1977 |
{ |
| 1978 |
ObjectType eHitObjectType = ObjectIdentifier::getObjectType( aHitObjectCID ); |
| 1979 |
if( eHitObjectType == OBJECTTYPE_DATA_POINT ) |
| 1980 |
{ |
| 1981 |
if( !ObjectIdentifier::areSiblings(aHitObjectCID,m_aSelection.getSelectedCID()) |
| 1982 |
&& !ObjectIdentifier::areIdenticalObjects(aHitObjectCID,m_aSelection.getSelectedCID()) ) |
| 1983 |
{ |
| 1984 |
pChartWindow->SetPointer( PointerStyle::Arrow ); |
| 1985 |
return; |
| 1986 |
} |
| 1987 |
} |
| 1988 |
pChartWindow->SetPointer( PointerStyle::Move ); |
| 1989 |
} |
| 1990 |
} |
| 1991 |
else |
| 1992 |
pChartWindow->SetPointer( PointerStyle::Arrow ); |
| 1993 |
} |
| 1994 |
|
| 1995 |
void ChartController::sendPopupRequest(std::u16string_view rCID, tools::Rectangle aRectangle) |
| 1996 |
{ |
| 1997 |
ChartModel* pChartModel = m_aModel->getModel().get(); |
| 1998 |
if (!pChartModel) |
| 1999 |
return; |
| 2000 |
|
| 2001 |
chart2api::AbstractPivotTableDataProvider* pPivotTableDataProvider = |
| 2002 |
dynamic_cast<chart2api::AbstractPivotTableDataProvider*>(pChartModel->getDataProvider().get()); |
| 2003 |
if (!pPivotTableDataProvider) |
| 2004 |
return; |
| 2005 |
|
| 2006 |
OUString sPivotTableName = pPivotTableDataProvider->getPivotTableName(); |
| 2007 |
|
| 2008 |
css::uno::Reference<css::awt::XRequestCallback> xPopupRequest = pChartModel->getPopupRequest(); |
| 2009 |
PopupRequest* pPopupRequest = dynamic_cast<PopupRequest*>(xPopupRequest.get()); |
| 2010 |
if (!pPopupRequest) |
| 2011 |
return; |
| 2012 |
|
| 2013 |
// Get dimension index from CID |
| 2014 |
size_t nStartPos = rCID.rfind('.'); |
| 2015 |
nStartPos = (nStartPos == std::u16string_view::npos) ? 0 : (nStartPos + 1); |
| 2016 |
sal_Int32 nEndPos = rCID.size(); |
| 2017 |
std::u16string_view sDimensionIndex = rCID.substr(nStartPos, nEndPos - nStartPos); |
| 2018 |
sal_Int32 nDimensionIndex = o3tl::toInt32(sDimensionIndex); |
| 2019 |
|
| 2020 |
awt::Rectangle xRectangle { |
| 2021 |
sal_Int32(aRectangle.Left()), |
| 2022 |
sal_Int32(aRectangle.Top()), |
| 2023 |
sal_Int32(aRectangle.GetWidth()), |
| 2024 |
sal_Int32(aRectangle.GetHeight()) |
| 2025 |
}; |
| 2026 |
|
| 2027 |
uno::Sequence<beans::PropertyValue> aCallbackData = comphelper::InitPropertySequence( |
| 2028 |
{ |
| 2029 |
{"Rectangle", uno::Any(xRectangle)}, |
| 2030 |
{"DimensionIndex", uno::Any(sal_Int32(nDimensionIndex))}, |
| 2031 |
{"PivotTableName", uno::Any(sPivotTableName)}, |
| 2032 |
}); |
| 2033 |
|
| 2034 |
pPopupRequest->getCallback()->notify(uno::Any(aCallbackData)); |
| 2035 |
} |
| 2036 |
|
| 2037 |
} //namespace chart |
| 2038 |
|
| 2039 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |