LCOV - code coverage report
Current view: top level - sd/source/ui/table - tablefunction.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 12 106 11.3 %
Date: 2014-04-11 Functions: 3 6 50.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             : 
      21             : #include <sal/config.h>
      22             : #include <com/sun/star/uno/XComponentContext.hpp>
      23             : #include <com/sun/star/drawing/XSelectionFunction.hpp>
      24             : #include <com/sun/star/awt/KeyModifier.hpp>
      25             : #include <com/sun/star/lang/XInitialization.hpp>
      26             : 
      27             : #include <cppuhelper/compbase2.hxx>
      28             : #include <cppuhelper/basemutex.hxx>
      29             : 
      30             : #include <vcl/svapp.hxx>
      31             : 
      32             : #include <svx/svdotable.hxx>
      33             : #include <svx/sdr/overlay/overlayobjectcell.hxx>
      34             : #include <svx/sdr/overlay/overlaymanager.hxx>
      35             : #include <svx/svxids.hrc>
      36             : #include <editeng/outlobj.hxx>
      37             : #include <svx/svdoutl.hxx>
      38             : #include <svx/svdpagv.hxx>
      39             : #include <svx/svdetc.hxx>
      40             : #include <editeng/editstat.hxx>
      41             : #include <editeng/unolingu.hxx>
      42             : #include <svx/sdrpagewindow.hxx>
      43             : #include <svx/sdr/table/tabledesign.hxx>
      44             : #include <svx/svxdlg.hxx>
      45             : #include <vcl/msgbox.hxx>
      46             : 
      47             : #include <svl/itempool.hxx>
      48             : #include <sfx2/viewfrm.hxx>
      49             : #include <sfx2/dispatch.hxx>
      50             : #include <sfx2/bindings.hxx>
      51             : #include <sfx2/request.hxx>
      52             : #include <sfx2/sidebar/Sidebar.hxx>
      53             : #include <svl/style.hxx>
      54             : 
      55             : #include "framework/FrameworkHelper.hxx"
      56             : #include "app.hrc"
      57             : #include "glob.hrc"
      58             : #include "DrawViewShell.hxx"
      59             : #include "drawdoc.hxx"
      60             : #include "DrawDocShell.hxx"
      61             : #include "Window.hxx"
      62             : #include "drawview.hxx"
      63             : #include "sdresid.hxx"
      64             : #include "undo/undoobjects.hxx"
      65             : 
      66             : #include <boost/scoped_ptr.hpp>
      67             : 
      68             : using namespace ::sd;
      69             : using namespace ::sdr::table;
      70             : using namespace ::com::sun::star;
      71             : using namespace ::com::sun::star::uno;
      72             : using namespace ::com::sun::star::beans;
      73             : using namespace ::com::sun::star::util;
      74             : using namespace ::com::sun::star::frame;
      75             : using namespace ::com::sun::star::container;
      76             : using namespace ::com::sun::star::lang;
      77             : using namespace ::com::sun::star::drawing;
      78             : using namespace ::com::sun::star::linguistic2;
      79             : 
      80             : namespace sd
      81             : {
      82             : extern void showTableDesignDialog( ::Window*, ViewShellBase& );
      83             : 
      84           0 : static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle )
      85             : {
      86           0 :     if( pModel && pObj )
      87             :     {
      88           0 :         Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) );
      89           0 :         if( xPool.is() ) try
      90             :         {
      91           0 :             const OUString sFamilyName("table" );
      92           0 :             Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW );
      93           0 :             OUString aStdName( "default" );
      94           0 :             if( !sTableStyle.isEmpty() )
      95           0 :                 aStdName = sTableStyle;
      96           0 :             Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW );
      97           0 :             pObj->setTableStyle( xStyle );
      98             :         }
      99           0 :         catch( Exception& )
     100             :         {
     101             :             OSL_FAIL("sd::apply_default_table_style(), exception caught!");
     102           0 :         }
     103             :     }
     104           0 : }
     105             : 
     106           0 : void DrawViewShell::FuTable(SfxRequest& rReq)
     107             : {
     108           0 :     switch( rReq.GetSlot() )
     109             :     {
     110             :     case SID_INSERT_TABLE:
     111             :     {
     112           0 :         sal_Int32 nColumns = 0;
     113           0 :         sal_Int32 nRows = 0;
     114           0 :         OUString sTableStyle;
     115             : 
     116           0 :         SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, false );
     117           0 :         SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, false );
     118           0 :         SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, false );
     119             : 
     120           0 :         if( pCols )
     121           0 :             nColumns = pCols->GetValue();
     122             : 
     123           0 :         if( pRows )
     124           0 :             nRows = pRows->GetValue();
     125             : 
     126           0 :         if( pStyle )
     127           0 :             sTableStyle = pStyle->GetValue();
     128             : 
     129           0 :         if( (nColumns == 0) || (nRows == 0) )
     130             :         {
     131           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     132           0 :             boost::scoped_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0);
     133             : 
     134           0 :             if( !pDlg.get() || (pDlg->Execute() != RET_OK) )
     135           0 :                 break;
     136             : 
     137           0 :             nColumns = pDlg->getColumns();
     138           0 :             nRows = pDlg->getRows();
     139             :         }
     140             : 
     141           0 :         Rectangle aRect;
     142             : 
     143           0 :         SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_TABLE );
     144           0 :         if( pPickObj )
     145             :         {
     146           0 :             aRect = pPickObj->GetLogicRect();
     147           0 :             aRect.setHeight( 200 );
     148             :         }
     149             :         else
     150             :         {
     151           0 :             Size aSize( 14100, 200 );
     152             : 
     153           0 :             Point aPos;
     154           0 :             Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() );
     155           0 :             aPos = aWinRect.Center();
     156           0 :             aPos = GetActiveWindow()->PixelToLogic(aPos);
     157           0 :             aPos.X() -= aSize.Width() / 2;
     158           0 :             aPos.Y() -= aSize.Height() / 2;
     159           0 :             aRect = Rectangle(aPos, aSize);
     160             :         }
     161             : 
     162           0 :         ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows );
     163           0 :         pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), true );
     164           0 :         apply_table_style( pObj, GetDoc(), sTableStyle );
     165           0 :         SdrPageView* pPV = mpView->GetSdrPageView();
     166             : 
     167             :         // #i123359# if an object is to be replaced/manipulated it may be that it is in text edit mode,
     168             :         // so to be on the safe side call SdrEndTextEdit here
     169           0 :         SdrTextObj* pCheckForTextEdit = dynamic_cast< SdrTextObj* >(pPickObj);
     170             : 
     171           0 :         if(pCheckForTextEdit && pCheckForTextEdit->IsInEditMode())
     172             :         {
     173           0 :             mpView->SdrEndTextEdit();
     174             :         }
     175             : 
     176             :         // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
     177           0 :         if( pPickObj )
     178             :         {
     179           0 :             SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
     180           0 :             if(pPage && pPage->IsPresObj(pPickObj))
     181             :             {
     182           0 :                 pObj->SetUserCall( pPickObj->GetUserCall() );
     183           0 :                 pPage->InsertPresObj( pObj, PRESOBJ_TABLE );
     184             :             }
     185             :         }
     186             : 
     187           0 :         GetParentWindow()->GrabFocus();
     188           0 :         if( pPickObj )
     189           0 :             mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj, true );
     190             :         else
     191           0 :             mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER);
     192             : 
     193           0 :         Invalidate(SID_DRAWTBX_INSERT);
     194           0 :         rReq.Ignore();
     195           0 :         SfxViewShell* pViewShell = GetViewShell();
     196             :         OSL_ASSERT (pViewShell!=NULL);
     197           0 :         SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
     198           0 :         rBindings.Invalidate( SID_INSERT_TABLE, true, false );
     199           0 :         break;
     200             :     }
     201             :     case SID_TABLEDESIGN:
     202             :     {
     203           0 :         if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
     204             :         {
     205             :             // in draw open a modal dialog since we have no tool pane yet
     206           0 :             showTableDesignDialog( GetActiveWindow(), GetViewShellBase() );
     207             :         }
     208             :         else
     209             :         {
     210             :             // Make the table design panel visible (expand it) in the
     211             :             // sidebar.
     212             :             ::sfx2::sidebar::Sidebar::ShowPanel(
     213             :                 OUString("ImpressTableDesignPanel"),
     214           0 :                 GetViewFrame()->GetFrame().GetFrameInterface());
     215             :         }
     216             : 
     217           0 :         Cancel();
     218           0 :         rReq.Done ();
     219             :     }
     220             :     default:
     221           0 :         break;
     222             :     }
     223           0 : }
     224             : 
     225             : 
     226             : 
     227          18 : void DrawViewShell::GetTableMenuState( SfxItemSet &rSet )
     228             : {
     229          18 :     bool bIsUIActive = GetDocSh()->IsUIActive();
     230          18 :     if( bIsUIActive )
     231             :     {
     232           0 :         rSet.DisableItem( SID_INSERT_TABLE );
     233             :     }
     234             :     else
     235             :     {
     236          18 :         OUString aActiveLayer = mpDrawView->GetActiveLayer();
     237          18 :         SdrPageView* pPV = mpDrawView->GetSdrPageView();
     238             : 
     239          36 :         if( bIsUIActive ||
     240          54 :             ( !aActiveLayer.isEmpty() && pPV && ( pPV->IsLayerLocked(aActiveLayer) ||
     241          54 :             !pPV->IsLayerVisible(aActiveLayer) ) ) ||
     242          18 :             SD_MOD()->GetWaterCan() )
     243             :         {
     244           0 :             rSet.DisableItem( SID_INSERT_TABLE );
     245          18 :         }
     246             :     }
     247          18 : }
     248             : 
     249             : 
     250             : 
     251           0 : void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel )
     252             : {
     253           0 :     rStream.Seek( 0 );
     254             : 
     255           0 :     if( pModel )
     256             :     {
     257           0 :         SdrPage* pPage = pModel->GetPage(0);
     258           0 :         if( pPage )
     259             :         {
     260           0 :             Size aSize( 200, 200 );
     261           0 :             Point aPos;
     262           0 :             Rectangle aRect (aPos, aSize);
     263           0 :             ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( pModel, aRect, 1, 1 );
     264           0 :             pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), true );
     265           0 :             OUString sTableStyle;
     266           0 :             apply_table_style( pObj, pModel, sTableStyle );
     267             : 
     268           0 :             pPage->NbcInsertObject( pObj );
     269             : 
     270           0 :             sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj );
     271             :         }
     272             :     }
     273           0 : }
     274             : 
     275          48 : }
     276             : 
     277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10