LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/table - tablefunction.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 103 1.0 %
Date: 2012-12-27 Functions: 2 6 33.3 %
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 <svl/style.hxx>
      53             : 
      54             : #include "framework/FrameworkHelper.hxx"
      55             : #include "app.hrc"
      56             : #include "glob.hrc"
      57             : #include "DrawViewShell.hxx"
      58             : #include "drawdoc.hxx"
      59             : #include "DrawDocShell.hxx"
      60             : #include "Window.hxx"
      61             : #include "drawview.hxx"
      62             : #include "sdresid.hxx"
      63             : #include "undo/undoobjects.hxx"
      64             : 
      65             : using ::rtl::OUString;
      66             : using namespace ::sd;
      67             : using namespace ::sdr::table;
      68             : using namespace ::com::sun::star;
      69             : using namespace ::com::sun::star::uno;
      70             : using namespace ::com::sun::star::beans;
      71             : using namespace ::com::sun::star::util;
      72             : using namespace ::com::sun::star::frame;
      73             : using namespace ::com::sun::star::container;
      74             : using namespace ::com::sun::star::lang;
      75             : using namespace ::com::sun::star::drawing;
      76             : using namespace ::com::sun::star::linguistic2;
      77             : 
      78             : namespace sd
      79             : {
      80             : extern void showTableDesignDialog( ::Window*, ViewShellBase& );
      81             : 
      82           0 : static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle )
      83             : {
      84           0 :     if( pModel && pObj )
      85             :     {
      86           0 :         Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) );
      87           0 :         if( xPool.is() ) try
      88             :         {
      89           0 :             const OUString sFamilyName("table" );
      90           0 :             Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW );
      91           0 :             OUString aStdName( "default" );
      92           0 :             if( !sTableStyle.isEmpty() )
      93           0 :                 aStdName = sTableStyle;
      94           0 :             Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW );
      95           0 :             pObj->setTableStyle( xStyle );
      96             :         }
      97           0 :         catch( Exception& )
      98             :         {
      99             :             OSL_FAIL("sd::apply_default_table_style(), exception caught!");
     100           0 :         }
     101             :     }
     102           0 : }
     103             : 
     104           0 : void DrawViewShell::FuTable(SfxRequest& rReq)
     105             : {
     106           0 :     switch( rReq.GetSlot() )
     107             :     {
     108             :     case SID_INSERT_TABLE:
     109             :     {
     110           0 :         sal_Int32 nColumns = 0;
     111           0 :         sal_Int32 nRows = 0;
     112           0 :         OUString sTableStyle;
     113             : 
     114           0 :         SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, sal_False );
     115           0 :         SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, sal_False );
     116           0 :         SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, sal_False );
     117             : 
     118           0 :         if( pCols )
     119           0 :             nColumns = pCols->GetValue();
     120             : 
     121           0 :         if( pRows )
     122           0 :             nRows = pRows->GetValue();
     123             : 
     124           0 :         if( pStyle )
     125           0 :             sTableStyle = pStyle->GetValue();
     126             : 
     127           0 :         if( (nColumns == 0) || (nRows == 0) )
     128             :         {
     129           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     130           0 :             ::std::auto_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0);
     131             : 
     132           0 :             if( !pDlg.get() || (pDlg->Execute() != RET_OK) )
     133             :                 break;
     134             : 
     135           0 :             nColumns = pDlg->getColumns();
     136           0 :             nRows = pDlg->getRows();
     137             :         }
     138             : 
     139           0 :         Rectangle aRect;
     140             : 
     141           0 :         SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_TABLE );
     142           0 :         if( pPickObj )
     143             :         {
     144           0 :             aRect = pPickObj->GetLogicRect();
     145           0 :             aRect.setHeight( 200 );
     146             :         }
     147             :         else
     148             :         {
     149           0 :             Size aSize( 14100, 200 );
     150             : 
     151           0 :             Point aPos;
     152           0 :             Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() );
     153           0 :             aPos = aWinRect.Center();
     154           0 :             aPos = GetActiveWindow()->PixelToLogic(aPos);
     155           0 :             aPos.X() -= aSize.Width() / 2;
     156           0 :             aPos.Y() -= aSize.Height() / 2;
     157           0 :             aRect = Rectangle(aPos, aSize);
     158             :         }
     159             : 
     160           0 :         ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows );
     161           0 :         pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), sal_True );
     162           0 :         apply_table_style( pObj, GetDoc(), sTableStyle );
     163           0 :         SdrPageView* pPV = mpView->GetSdrPageView();
     164             : 
     165             :         // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
     166           0 :         if( pPickObj )
     167             :         {
     168           0 :             SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
     169           0 :             if(pPage && pPage->IsPresObj(pPickObj))
     170             :             {
     171           0 :                 pObj->SetUserCall( pPickObj->GetUserCall() );
     172           0 :                 pPage->InsertPresObj( pObj, PRESOBJ_TABLE );
     173             :             }
     174             :         }
     175             : 
     176           0 :         GetParentWindow()->GrabFocus();
     177           0 :         if( pPickObj )
     178           0 :             mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj, sal_True );
     179             :         else
     180           0 :             mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER);
     181             : 
     182           0 :         Invalidate(SID_DRAWTBX_INSERT);
     183           0 :         rReq.Ignore();
     184           0 :         SfxViewShell* pViewShell = GetViewShell();
     185             :         OSL_ASSERT (pViewShell!=NULL);
     186           0 :         SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
     187           0 :         rBindings.Invalidate( SID_INSERT_TABLE, sal_True, sal_False );
     188           0 :         break;
     189             :     }
     190             :     case SID_TABLEDESIGN:
     191             :     {
     192           0 :         if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
     193             :         {
     194             :             // in draw open a modal dialog since we have no tool pane yet
     195           0 :             showTableDesignDialog( GetActiveWindow(), GetViewShellBase() );
     196             :         }
     197             :         else
     198             :         {
     199             :             // Make the slide transition panel visible (expand it) in the
     200             :             // tool pane.
     201           0 :             framework::FrameworkHelper::Instance(GetViewShellBase())->RequestTaskPanel(
     202           0 :                 framework::FrameworkHelper::msTableDesignPanelURL);
     203             :         }
     204             : 
     205           0 :         Cancel();
     206           0 :         rReq.Done ();
     207             :     }
     208             :     default:
     209           0 :         break;
     210             :     }
     211           0 : }
     212             : 
     213             : // --------------------------------------------------------------------
     214             : 
     215           0 : void DrawViewShell::GetTableMenuState( SfxItemSet &rSet )
     216             : {
     217           0 :     bool bIsUIActive = GetDocSh()->IsUIActive();
     218           0 :     if( bIsUIActive )
     219             :     {
     220           0 :         rSet.DisableItem( SID_INSERT_TABLE );
     221             :     }
     222             :     else
     223             :     {
     224           0 :         String aActiveLayer = mpDrawView->GetActiveLayer();
     225           0 :         SdrPageView* pPV = mpDrawView->GetSdrPageView();
     226             : 
     227           0 :         if( bIsUIActive ||
     228           0 :             ( aActiveLayer.Len() != 0 && pPV && ( pPV->IsLayerLocked(aActiveLayer) ||
     229           0 :             !pPV->IsLayerVisible(aActiveLayer) ) ) ||
     230           0 :             SD_MOD()->GetWaterCan() )
     231             :         {
     232           0 :             rSet.DisableItem( SID_INSERT_TABLE );
     233           0 :         }
     234             :     }
     235           0 : }
     236             : 
     237             : // --------------------------------------------------------------------
     238             : 
     239           0 : void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel )
     240             : {
     241           0 :     rStream.Seek( 0 );
     242             : 
     243           0 :     if( pModel )
     244             :     {
     245           0 :         SdrPage* pPage = pModel->GetPage(0);
     246           0 :         if( pPage )
     247             :         {
     248           0 :             Size aSize( 200, 200 );
     249           0 :             Point aPos;
     250           0 :             Rectangle aRect (aPos, aSize);
     251           0 :             ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( pModel, aRect, 1, 1 );
     252           0 :             pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), sal_True );
     253           0 :             OUString sTableStyle;
     254           0 :             apply_table_style( pObj, pModel, sTableStyle );
     255             : 
     256           0 :             pPage->NbcInsertObject( pObj );
     257             : 
     258           0 :             sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj );
     259             :         }
     260             :     }
     261           0 : }
     262             : 
     263           9 : }
     264             : 
     265             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10