LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/main - ChartController_Window.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1010 0.0 %
Date: 2012-12-17 Functions: 0 50 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10