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

Generated by: LCOV version 1.10