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

Generated by: LCOV version 1.10