LCOV - code coverage report
Current view: top level - sw/source/uibase/table - chartins.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 103 1.0 %
Date: 2014-11-03 Functions: 2 5 40.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 <sfx2/viewfrm.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include <sfx2/dispatch.hxx>
      23             : #include <sfx2/basedlgs.hxx>
      24             : #include <IDocumentUndoRedo.hxx>
      25             : #include <IDocumentChartDataProviderAccess.hxx>
      26             : 
      27             : #include <sfx2/app.hxx>
      28             : #include <swtypes.hxx>
      29             : #include <swmodule.hxx>
      30             : #include <wrtsh.hxx>
      31             : #include <docsh.hxx>
      32             : #include <view.hxx>
      33             : #include <chartins.hxx>
      34             : #include <tablemgr.hxx>
      35             : #include <frmfmt.hxx>
      36             : #include <swtable.hxx>
      37             : #include <tblsel.hxx>
      38             : #include <unochart.hxx>
      39             : #include <autoedit.hxx>
      40             : #include <doc.hxx>
      41             : 
      42             : #include <edtwin.hxx>
      43             : 
      44             : #include <cmdid.h>
      45             : #include <anchoredobject.hxx>
      46             : 
      47             : #include <comphelper/classids.hxx>
      48             : 
      49             : #include <cppuhelper/bootstrap.hxx>
      50             : #include <cppuhelper/component_context.hxx>
      51             : #include <comphelper/processfactory.hxx>
      52             : #include <com/sun/star/chart2/data/XDataProvider.hpp>
      53             : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      54             : #include <com/sun/star/chart/ChartDataRowSource.hpp>
      55             : #include <com/sun/star/frame/XComponentLoader.hpp>
      56             : #include <com/sun/star/lang/XInitialization.hpp>
      57             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      58             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      59             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      60             : 
      61             : using namespace ::com::sun::star;
      62             : using namespace ::com::sun::star::uno;
      63             : 
      64           0 : Point SwGetChartDialogPos( const vcl::Window *pParentWin, const Size& rDialogSize, const Rectangle& rLogicChart )
      65             : {
      66             :     // positioning code according to spepc; similar to Calc fuins2.cxx
      67           0 :     Point aRet;
      68             : 
      69             :     OSL_ENSURE( pParentWin, "Window not found" );
      70           0 :     if (pParentWin)
      71             :     {
      72           0 :         Rectangle aObjPixel = pParentWin->LogicToPixel( rLogicChart, pParentWin->GetMapMode() );
      73           0 :         Rectangle aObjAbs( pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.TopLeft() ),
      74           0 :                            pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.BottomRight() ) );
      75             : 
      76           0 :         Rectangle aDesktop = pParentWin->GetDesktopRectPixel();
      77           0 :         Size aSpace = pParentWin->LogicToPixel( Size( 8, 12 ), MAP_APPFONT );
      78             : 
      79           0 :         bool bLayoutRTL = ::GetActiveView()->GetWrtShell().IsTableRightToLeft();
      80           0 :         bool bCenterHor = false;
      81             : 
      82           0 :         if ( aDesktop.Bottom() - aObjAbs.Bottom() >= rDialogSize.Height() + aSpace.Height() )
      83             :         {
      84             :             // first preference: below the chart
      85           0 :             aRet.Y() = aObjAbs.Bottom() + aSpace.Height();
      86           0 :             bCenterHor = true;
      87             :         }
      88           0 :         else if ( aObjAbs.Top() - aDesktop.Top() >= rDialogSize.Height() + aSpace.Height() )
      89             :         {
      90             :             // second preference: above the chart
      91           0 :             aRet.Y() = aObjAbs.Top() - rDialogSize.Height() - aSpace.Height();
      92           0 :             bCenterHor = true;
      93             :         }
      94             :         else
      95             :         {
      96           0 :             bool bFitLeft = ( aObjAbs.Left() - aDesktop.Left() >= rDialogSize.Width() + aSpace.Width() );
      97           0 :             bool bFitRight = ( aDesktop.Right() - aObjAbs.Right() >= rDialogSize.Width() + aSpace.Width() );
      98             : 
      99           0 :             if ( bFitLeft || bFitRight )
     100             :             {
     101             :                 // if both fit, prefer right in RTL mode, left otherwise
     102           0 :                 bool bPutRight = bFitRight && ( bLayoutRTL || !bFitLeft );
     103           0 :                 if ( bPutRight )
     104           0 :                     aRet.X() = aObjAbs.Right() + aSpace.Width();
     105             :                 else
     106           0 :                     aRet.X() = aObjAbs.Left() - rDialogSize.Width() - aSpace.Width();
     107             : 
     108             :                 // center vertically
     109           0 :                 aRet.Y() = aObjAbs.Top() + ( aObjAbs.GetHeight() - rDialogSize.Height() ) / 2;
     110             :             }
     111             :             else
     112             :             {
     113             :                 // doesn't fit on any edge - put at the bottom of the screen
     114           0 :                 aRet.Y() = aDesktop.Bottom() - rDialogSize.Height();
     115           0 :                 bCenterHor = true;
     116             :             }
     117             :         }
     118           0 :         if ( bCenterHor )
     119           0 :             aRet.X() = aObjAbs.Left() + ( aObjAbs.GetWidth() - rDialogSize.Width() ) / 2;
     120             : 
     121             :         // limit to screen (centering might lead to invalid positions)
     122           0 :         if ( aRet.X() + rDialogSize.Width() - 1 > aDesktop.Right() )
     123           0 :             aRet.X() = aDesktop.Right() - rDialogSize.Width() + 1;
     124           0 :         if ( aRet.X() < aDesktop.Left() )
     125           0 :             aRet.X() = aDesktop.Left();
     126           0 :         if ( aRet.Y() + rDialogSize.Height() - 1 > aDesktop.Bottom() )
     127           0 :             aRet.Y() = aDesktop.Bottom() - rDialogSize.Height() + 1;
     128           0 :         if ( aRet.Y() < aDesktop.Top() )
     129           0 :             aRet.Y() = aDesktop.Top();
     130             :     }
     131             : 
     132           0 :     return aRet;
     133             : }
     134             : 
     135           0 : void SwInsertChart(vcl::Window* pParent, SfxBindings* pBindings )
     136             : {
     137             :     (void) pParent;
     138             :     (void) pBindings;
     139           0 :     SwView *pView = ::GetActiveView();
     140             : 
     141             :     // get range string of marked data
     142           0 :     SwWrtShell &rWrtShell = pView->GetWrtShell();
     143           0 :     uno::Reference< chart2::data::XDataProvider > xDataProvider;
     144           0 :     uno::Reference< frame::XModel > xChartModel;
     145           0 :     OUString aRangeString;
     146             : 
     147           0 :     if( rWrtShell.IsCrsrInTbl())
     148             :     {
     149           0 :         if (!rWrtShell.IsTableMode())
     150             :         {
     151             :             // select whole table
     152           0 :             rWrtShell.GetView().GetViewFrame()->GetDispatcher()->
     153           0 :                 Execute(FN_TABLE_SELECT_ALL, SfxCallMode::SYNCHRON);
     154             :         }
     155           0 :         if( ! rWrtShell.IsTblComplexForChart())
     156             :         {
     157           0 :             SwFrmFmt* pTblFmt = rWrtShell.GetTableFmt();
     158           0 :             aRangeString = pTblFmt->GetName() + "." + rWrtShell.GetBoxNms();
     159             : 
     160             :             // get table data provider
     161           0 :             xDataProvider.set( pView->GetDocShell()->getIDocumentChartDataProviderAccess()->GetChartDataProvider( true ) );
     162             :         }
     163             :     }
     164             : 
     165           0 :     SwFlyFrmFmt *pFlyFrmFmt = 0;
     166           0 :     xChartModel.set( SwTableFUNC( &rWrtShell, false ).InsertChart( xDataProvider, xDataProvider.is(), aRangeString, &pFlyFrmFmt ));
     167             : 
     168             :     //open wizard
     169             :     //@todo get context from writer if that has one
     170             :     uno::Reference< uno::XComponentContext > xContext(
     171           0 :         ::cppu::defaultBootstrap_InitialComponentContext() );
     172           0 :     if( xContext.is() && xChartModel.is() && xDataProvider.is())
     173             :     {
     174           0 :         uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
     175           0 :         if(xMCF.is())
     176             :         {
     177             :             uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
     178           0 :                 xMCF->createInstanceWithContext(
     179             :                     OUString("com.sun.star.comp.chart2.WizardDialog")
     180           0 :                     , xContext), uno::UNO_QUERY);
     181           0 :             uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
     182           0 :             if( xInit.is() )
     183             :             {
     184           0 :                 uno::Reference< awt::XWindow > xDialogParentWindow(0);
     185             :                 //  initialize dialog
     186           0 :                 uno::Sequence<uno::Any> aSeq(2);
     187           0 :                 uno::Any* pArray = aSeq.getArray();
     188           0 :                 beans::PropertyValue aParam1;
     189           0 :                 aParam1.Name = "ParentWindow";
     190           0 :                 aParam1.Value <<= uno::makeAny(xDialogParentWindow);
     191           0 :                 beans::PropertyValue aParam2;
     192           0 :                 aParam2.Name = "ChartModel";
     193           0 :                 aParam2.Value <<= uno::makeAny(xChartModel);
     194           0 :                 pArray[0] <<= uno::makeAny(aParam1);
     195           0 :                 pArray[1] <<= uno::makeAny(aParam2);
     196           0 :                 xInit->initialize( aSeq );
     197             : 
     198             :                 // try to set the dialog's position so it doesn't hide the chart
     199           0 :                 uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
     200           0 :                 if ( xDialogProps.is() )
     201             :                 {
     202             :                     try
     203             :                     {
     204             :                         //get dialog size:
     205           0 :                         awt::Size aDialogAWTSize;
     206           0 :                         if( xDialogProps->getPropertyValue("Size")
     207           0 :                             >>= aDialogAWTSize )
     208             :                         {
     209           0 :                             Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
     210           0 :                             if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
     211             :                             {
     212             :                                 //calculate and set new position
     213           0 :                                 SwRect aSwRect;
     214           0 :                                 if (pFlyFrmFmt)
     215           0 :                                     aSwRect = pFlyFrmFmt->GetAnchoredObj()->GetObjRectWithSpaces();
     216           0 :                                 Rectangle aRect( aSwRect.SVRect() );
     217           0 :                                 Point aDialogPos = SwGetChartDialogPos( &rWrtShell.GetView().GetEditWin(), aDialogSize, aRect );
     218           0 :                                 xDialogProps->setPropertyValue("Position",
     219           0 :                                     uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
     220             :                             }
     221             :                         }
     222             :                     }
     223           0 :                     catch (const uno::Exception&)
     224             :                     {
     225             :                         OSL_FAIL("Chart wizard couldn't be positioned automatically\n" );
     226             :                     }
     227             :                 }
     228             : 
     229           0 :                 sal_Int16 nDialogRet = xDialog->execute();
     230           0 :                 if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
     231             :                 {
     232           0 :                     rWrtShell.Undo();
     233           0 :                     rWrtShell.GetIDocumentUndoRedo().ClearRedo();
     234             :                 }
     235             :                 else
     236             :                 {
     237             :                     OSL_ENSURE( nDialogRet == ui::dialogs::ExecutableDialogResults::OK,
     238             :                         "dialog execution failed" );
     239           0 :                 }
     240             :             }
     241           0 :             uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
     242           0 :             if( xComponent.is())
     243           0 :                 xComponent->dispose();
     244           0 :         }
     245           0 :     }
     246           0 : }
     247             : 
     248           0 : void AutoEdit::KeyInput( const KeyEvent& rEvt )
     249             : {
     250           0 :     if( rEvt.GetKeyCode().GetCode() != KEY_SPACE )
     251           0 :         Edit::KeyInput( rEvt );
     252         270 : }
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10