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

Generated by: LCOV version 1.10