LCOV - code coverage report
Current view: top level - sw/source/ui/table - chartins.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 107 0.0 %
Date: 2012-08-25 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 224 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sfx2/viewfrm.hxx>
      30                 :            : #include <vcl/msgbox.hxx>
      31                 :            : #include <sfx2/dispatch.hxx>
      32                 :            : #include <sfx2/basedlgs.hxx>
      33                 :            : #include <IDocumentUndoRedo.hxx>
      34                 :            : 
      35                 :            : #include <sfx2/app.hxx>
      36                 :            : #include <swtypes.hxx>
      37                 :            : #include <swmodule.hxx>
      38                 :            : #include <wrtsh.hxx>
      39                 :            : #include <docsh.hxx>
      40                 :            : #include <view.hxx>
      41                 :            : #include <chartins.hxx>
      42                 :            : #include <tablemgr.hxx>
      43                 :            : #include <frmfmt.hxx>
      44                 :            : #include <swtable.hxx>
      45                 :            : #include <tblsel.hxx>
      46                 :            : #include <unochart.hxx>
      47                 :            : #include <autoedit.hxx>
      48                 :            : #include <doc.hxx>
      49                 :            : 
      50                 :            : #include <edtwin.hxx>
      51                 :            : 
      52                 :            : #include <cmdid.h>
      53                 :            : #include <chartins.hrc>
      54                 :            : #include <anchoredobject.hxx>
      55                 :            : 
      56                 :            : #include <sot/clsids.hxx>
      57                 :            : 
      58                 :            : #include <cppuhelper/bootstrap.hxx>
      59                 :            : #include <cppuhelper/component_context.hxx>
      60                 :            : #include <comphelper/processfactory.hxx>
      61                 :            : #include <com/sun/star/chart2/data/XDataProvider.hpp>
      62                 :            : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      63                 :            : #include <com/sun/star/chart/ChartDataRowSource.hpp>
      64                 :            : #include <com/sun/star/frame/XComponentLoader.hpp>
      65                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      66                 :            : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      67                 :            : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      68                 :            : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      69                 :            : 
      70                 :            : using namespace ::com::sun::star;
      71                 :            : using namespace ::com::sun::star::uno;
      72                 :            : using ::rtl::OUString;
      73                 :            : 
      74                 :            : 
      75                 :            : 
      76                 :          0 : Point SwGetChartDialogPos( const Window *pParentWin, const Size& rDialogSize, const Rectangle& rLogicChart )
      77                 :            : {
      78                 :            :     // !! positioning code according to spepc; similar to Calc fuins2.cxx
      79                 :            : 
      80                 :          0 :     Point aRet;
      81                 :            : 
      82                 :            :     OSL_ENSURE( pParentWin, "Window not found" );
      83         [ #  # ]:          0 :     if (pParentWin)
      84                 :            :     {
      85         [ #  # ]:          0 :         Rectangle aObjPixel = pParentWin->LogicToPixel( rLogicChart, pParentWin->GetMapMode() );
      86                 :          0 :         Rectangle aObjAbs( pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.TopLeft() ),
      87         [ #  # ]:          0 :                            pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.BottomRight() ) );
           [ #  #  #  # ]
                 [ #  # ]
      88                 :            : 
      89         [ #  # ]:          0 :         Rectangle aDesktop = pParentWin->GetDesktopRectPixel();
      90 [ #  # ][ #  # ]:          0 :         Size aSpace = pParentWin->LogicToPixel( Size( 8, 12 ), MAP_APPFONT );
                 [ #  # ]
      91                 :            : 
      92 [ #  # ][ #  # ]:          0 :         sal_Bool bLayoutRTL = ::GetActiveView()->GetWrtShell().IsTableRightToLeft();
      93                 :          0 :         bool bCenterHor = false;
      94                 :            : 
      95         [ #  # ]:          0 :         if ( aDesktop.Bottom() - aObjAbs.Bottom() >= rDialogSize.Height() + aSpace.Height() )
      96                 :            :         {
      97                 :            :             // first preference: below the chart
      98                 :          0 :             aRet.Y() = aObjAbs.Bottom() + aSpace.Height();
      99                 :          0 :             bCenterHor = true;
     100                 :            :         }
     101         [ #  # ]:          0 :         else if ( aObjAbs.Top() - aDesktop.Top() >= rDialogSize.Height() + aSpace.Height() )
     102                 :            :         {
     103                 :            :             // second preference: above the chart
     104                 :          0 :             aRet.Y() = aObjAbs.Top() - rDialogSize.Height() - aSpace.Height();
     105                 :          0 :             bCenterHor = true;
     106                 :            :         }
     107                 :            :         else
     108                 :            :         {
     109                 :          0 :             bool bFitLeft = ( aObjAbs.Left() - aDesktop.Left() >= rDialogSize.Width() + aSpace.Width() );
     110                 :          0 :             bool bFitRight = ( aDesktop.Right() - aObjAbs.Right() >= rDialogSize.Width() + aSpace.Width() );
     111                 :            : 
     112 [ #  # ][ #  # ]:          0 :             if ( bFitLeft || bFitRight )
     113                 :            :             {
     114                 :            :                 // if both fit, prefer right in RTL mode, left otherwise
     115 [ #  # ][ #  # ]:          0 :                 bool bPutRight = bFitRight && ( bLayoutRTL || !bFitLeft );
                 [ #  # ]
     116         [ #  # ]:          0 :                 if ( bPutRight )
     117                 :          0 :                     aRet.X() = aObjAbs.Right() + aSpace.Width();
     118                 :            :                 else
     119                 :          0 :                     aRet.X() = aObjAbs.Left() - rDialogSize.Width() - aSpace.Width();
     120                 :            : 
     121                 :            :                 // center vertically
     122         [ #  # ]:          0 :                 aRet.Y() = aObjAbs.Top() + ( aObjAbs.GetHeight() - rDialogSize.Height() ) / 2;
     123                 :            :             }
     124                 :            :             else
     125                 :            :             {
     126                 :            :                 // doesn't fit on any edge - put at the bottom of the screen
     127                 :          0 :                 aRet.Y() = aDesktop.Bottom() - rDialogSize.Height();
     128                 :          0 :                 bCenterHor = true;
     129                 :            :             }
     130                 :            :         }
     131         [ #  # ]:          0 :         if ( bCenterHor )
     132         [ #  # ]:          0 :             aRet.X() = aObjAbs.Left() + ( aObjAbs.GetWidth() - rDialogSize.Width() ) / 2;
     133                 :            : 
     134                 :            :         // limit to screen (centering might lead to invalid positions)
     135         [ #  # ]:          0 :         if ( aRet.X() + rDialogSize.Width() - 1 > aDesktop.Right() )
     136                 :          0 :             aRet.X() = aDesktop.Right() - rDialogSize.Width() + 1;
     137         [ #  # ]:          0 :         if ( aRet.X() < aDesktop.Left() )
     138                 :          0 :             aRet.X() = aDesktop.Left();
     139         [ #  # ]:          0 :         if ( aRet.Y() + rDialogSize.Height() - 1 > aDesktop.Bottom() )
     140                 :          0 :             aRet.Y() = aDesktop.Bottom() - rDialogSize.Height() + 1;
     141         [ #  # ]:          0 :         if ( aRet.Y() < aDesktop.Top() )
     142                 :          0 :             aRet.Y() = aDesktop.Top();
     143                 :            :     }
     144                 :            : 
     145                 :          0 :     return aRet;
     146                 :            : }
     147                 :            : 
     148                 :          0 : void SwInsertChart(Window* pParent, SfxBindings* pBindings )
     149                 :            : {
     150                 :            :     (void) pParent;
     151                 :            :     (void) pBindings;
     152         [ #  # ]:          0 :     SwView *pView = ::GetActiveView();
     153                 :            : 
     154                 :            :     // get range string of marked data
     155                 :          0 :     SwWrtShell &rWrtShell = pView->GetWrtShell();
     156                 :          0 :     uno::Reference< chart2::data::XDataProvider > xDataProvider;
     157                 :          0 :     uno::Reference< frame::XModel > xChartModel;
     158                 :          0 :     OUString aRangeString;
     159                 :            : 
     160 [ #  # ][ #  # ]:          0 :     if( rWrtShell.IsCrsrInTbl())
     161                 :            :     {
     162         [ #  # ]:          0 :         if (!rWrtShell.IsTableMode())
     163                 :            :         {
     164                 :            :             // select whole table
     165                 :          0 :             rWrtShell.GetView().GetViewFrame()->GetDispatcher()->
     166         [ #  # ]:          0 :                 Execute(FN_TABLE_SELECT_ALL, SFX_CALLMODE_SYNCHRON);
     167                 :            :         }
     168 [ #  # ][ #  # ]:          0 :         if( ! rWrtShell.IsTblComplexForChart())
     169                 :            :         {
     170         [ #  # ]:          0 :             SwFrmFmt* pTblFmt = rWrtShell.GetTableFmt();
     171         [ #  # ]:          0 :             String aCurrentTblName = pTblFmt->GetName();
     172         [ #  # ]:          0 :             aRangeString = aCurrentTblName;
     173                 :          0 :             aRangeString += OUString::valueOf( sal_Unicode('.') );
     174 [ #  # ][ #  # ]:          0 :             aRangeString += rWrtShell.GetBoxNms();
                 [ #  # ]
     175                 :            : 
     176                 :            :             // get table data provider
     177 [ #  # ][ #  # ]:          0 :             xDataProvider.set( pView->GetDocShell()->getIDocumentChartDataProviderAccess()->GetChartDataProvider( true ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     178                 :            :         }
     179                 :            :     }
     180                 :            : 
     181                 :          0 :     SwFlyFrmFmt *pFlyFrmFmt = 0;
     182 [ #  # ][ #  # ]:          0 :     xChartModel.set( SwTableFUNC( &rWrtShell, sal_False ).InsertChart( xDataProvider, (sal_True == xDataProvider.is()), aRangeString, &pFlyFrmFmt ));
         [ #  # ][ #  # ]
     183                 :            : 
     184                 :            :     //open wizard
     185                 :            :     //@todo get context from writer if that has one
     186                 :            :     uno::Reference< uno::XComponentContext > xContext(
     187         [ #  # ]:          0 :         ::cppu::defaultBootstrap_InitialComponentContext() );
     188 [ #  # ][ #  # ]:          0 :     if( xContext.is() && xChartModel.is() && xDataProvider.is())
         [ #  # ][ #  # ]
     189                 :            :     {
     190 [ #  # ][ #  # ]:          0 :         uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
     191         [ #  # ]:          0 :         if(xMCF.is())
     192                 :            :         {
     193                 :            :             uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
     194         [ #  # ]:          0 :                 xMCF->createInstanceWithContext(
     195                 :            :                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.chart2.WizardDialog"))
     196 [ #  # ][ #  # ]:          0 :                     , xContext), uno::UNO_QUERY);
                 [ #  # ]
     197         [ #  # ]:          0 :             uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
     198         [ #  # ]:          0 :             if( xInit.is() )
     199                 :            :             {
     200         [ #  # ]:          0 :                 uno::Reference< awt::XWindow > xDialogParentWindow(0);
     201                 :            :                 //  initialize dialog
     202         [ #  # ]:          0 :                 uno::Sequence<uno::Any> aSeq(2);
     203         [ #  # ]:          0 :                 uno::Any* pArray = aSeq.getArray();
     204                 :          0 :                 beans::PropertyValue aParam1;
     205         [ #  # ]:          0 :                 aParam1.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow"));
     206 [ #  # ][ #  # ]:          0 :                 aParam1.Value <<= uno::makeAny(xDialogParentWindow);
     207                 :          0 :                 beans::PropertyValue aParam2;
     208         [ #  # ]:          0 :                 aParam2.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ChartModel"));
     209 [ #  # ][ #  # ]:          0 :                 aParam2.Value <<= uno::makeAny(xChartModel);
     210 [ #  # ][ #  # ]:          0 :                 pArray[0] <<= uno::makeAny(aParam1);
     211 [ #  # ][ #  # ]:          0 :                 pArray[1] <<= uno::makeAny(aParam2);
     212 [ #  # ][ #  # ]:          0 :                 xInit->initialize( aSeq );
     213                 :            : 
     214                 :            :                 // try to set the dialog's position so it doesn't hide the chart
     215         [ #  # ]:          0 :                 uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
     216         [ #  # ]:          0 :                 if ( xDialogProps.is() )
     217                 :            :                 {
     218                 :            :                     try
     219                 :            :                     {
     220                 :            :                         //get dialog size:
     221                 :          0 :                         awt::Size aDialogAWTSize;
     222   [ #  #  #  # ]:          0 :                         if( xDialogProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size")) )
     223 [ #  # ][ #  # ]:          0 :                             >>= aDialogAWTSize )
                 [ #  # ]
     224                 :            :                         {
     225                 :          0 :                             Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
     226 [ #  # ][ #  # ]:          0 :                             if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
                 [ #  # ]
     227                 :            :                             {
     228                 :            :                                 //calculate and set new position
     229                 :          0 :                                 SwRect aSwRect;
     230         [ #  # ]:          0 :                                 if (pFlyFrmFmt)
     231 [ #  # ][ #  # ]:          0 :                                     aSwRect = pFlyFrmFmt->GetAnchoredObj()->GetObjRectWithSpaces();
     232         [ #  # ]:          0 :                                 Rectangle aRect( aSwRect.SVRect() );
     233         [ #  # ]:          0 :                                 Point aDialogPos = SwGetChartDialogPos( &rWrtShell.GetView().GetEditWin(), aDialogSize, aRect );
     234         [ #  # ]:          0 :                                 xDialogProps->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Position")),
     235 [ #  # ][ #  # ]:          0 :                                     uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
         [ #  # ][ #  # ]
     236                 :            :                             }
     237                 :            :                         }
     238                 :            :                     }
     239         [ #  # ]:          0 :                     catch (const uno::Exception&)
     240                 :            :                     {
     241                 :            :                         OSL_FAIL("Chart wizard couldn't be positioned automatically\n" );
     242                 :            :                     }
     243                 :            :                 }
     244                 :            : 
     245 [ #  # ][ #  # ]:          0 :                 sal_Int16 nDialogRet = xDialog->execute();
     246         [ #  # ]:          0 :                 if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
     247                 :            :                 {
     248         [ #  # ]:          0 :                     rWrtShell.Undo();
     249 [ #  # ][ #  # ]:          0 :                     rWrtShell.GetIDocumentUndoRedo().ClearRedo();
     250                 :            :                 }
     251                 :            :                 else
     252                 :            :                 {
     253                 :            :                     OSL_ENSURE( nDialogRet == ui::dialogs::ExecutableDialogResults::OK,
     254                 :            :                         "dialog execution failed" );
     255         [ #  # ]:          0 :                 }
     256                 :            :             }
     257         [ #  # ]:          0 :             uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
     258         [ #  # ]:          0 :             if( xComponent.is())
     259 [ #  # ][ #  # ]:          0 :                 xComponent->dispose();
     260                 :          0 :         }
     261                 :          0 :     }
     262                 :          0 : }
     263                 :            : 
     264                 :            : 
     265                 :          0 : void AutoEdit::KeyInput( const KeyEvent& rEvt )
     266                 :            : {
     267                 :          0 :     sal_uInt16 nCode = rEvt.GetKeyCode().GetCode();
     268         [ #  # ]:          0 :     if( nCode != KEY_SPACE )
     269                 :          0 :         Edit::KeyInput( rEvt );
     270                 :          0 : }
     271                 :            : 
     272                 :            : 
     273                 :            : 
     274                 :            : 
     275                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10