LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/drawfunc - drawsh2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 198 11.1 %
Date: 2013-07-09 Functions: 7 13 53.8 %
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 <com/sun/star/embed/EmbedMisc.hpp>
      21             : 
      22             : #include "scitems.hxx"
      23             : #include <editeng/eeitem.hxx>
      24             : #include <editeng/sizeitem.hxx>
      25             : #include <svx/svdpagv.hxx>
      26             : #include <svx/xdef.hxx>
      27             : #include <sfx2/app.hxx>
      28             : #include <sfx2/objsh.hxx>
      29             : #include <sfx2/viewfrm.hxx>
      30             : #include <svl/ptitem.hxx>
      31             : #include <svl/whiter.hxx>
      32             : #include <svx/svdobj.hxx>
      33             : #include <svx/svdouno.hxx>
      34             : #include <svx/extrusionbar.hxx>
      35             : #include <svx/fontworkbar.hxx>
      36             : #include <svx/sidebar/SelectionChangeHandler.hxx>
      37             : #include <svx/sidebar/SelectionAnalyzer.hxx>
      38             : #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
      39             : 
      40             : #include "drawsh.hxx"
      41             : #include "drawview.hxx"
      42             : #include "viewdata.hxx"
      43             : #include "sc.hrc"
      44             : #include "tabvwsh.hxx"
      45             : #include "document.hxx"
      46             : #include "drwlayer.hxx"
      47             : #include "userdat.hxx"
      48             : #include <svx/svdoole2.hxx>
      49             : #include <svx/svdocapt.hxx>
      50             : 
      51             : #include <boost/bind.hpp>
      52             : 
      53             : 
      54             : sal_uInt16 ScGetFontWorkId();       // in drtxtob
      55             : 
      56             : using namespace com::sun::star;
      57             : 
      58             : 
      59             : //------------------------------------------------------------------
      60             : 
      61           1 : ScDrawShell::ScDrawShell( ScViewData* pData ) :
      62           1 :     SfxShell(pData->GetViewShell()),
      63             :     pViewData( pData ),
      64             :     mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
      65             :             ::boost::bind(&ScDrawShell::GetSidebarContextName, this),
      66           1 :             GetFrame()->GetFrame().GetController(),
      67           2 :             sfx2::sidebar::EnumContext::Context_Cell))
      68             : {
      69           1 :     SetPool( &pViewData->GetScDrawView()->GetModel()->GetItemPool() );
      70           1 :     ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
      71           1 :     SetUndoManager( pMgr );
      72           1 :     if ( !pViewData->GetDocument()->IsUndoEnabled() )
      73             :     {
      74           0 :         pMgr->SetMaxUndoActionCount( 0 );
      75             :     }
      76           1 :     SetHelpId( HID_SCSHELL_DRAWSH );
      77           1 :     SetName(OUString("Drawing"));
      78             : 
      79           1 :     mpSelectionChangeHandler->Connect();
      80           1 : }
      81             : 
      82           3 : ScDrawShell::~ScDrawShell()
      83             : {
      84           1 :     mpSelectionChangeHandler->Disconnect();
      85           2 : }
      86             : 
      87           0 : void ScDrawShell::GetState( SfxItemSet& rSet )          // Zustaende / Toggles
      88             : {
      89           0 :     ScDrawView* pView    = pViewData->GetScDrawView();
      90           0 :     SdrDragMode eMode    = pView->GetDragMode();
      91             : 
      92           0 :     rSet.Put( SfxBoolItem( SID_OBJECT_ROTATE, eMode == SDRDRAG_ROTATE ) );
      93           0 :     rSet.Put( SfxBoolItem( SID_OBJECT_MIRROR, eMode == SDRDRAG_MIRROR ) );
      94           0 :     rSet.Put( SfxBoolItem( SID_BEZIER_EDIT, !pView->IsFrameDragSingles() ) );
      95             : 
      96           0 :     sal_uInt16 nFWId = ScGetFontWorkId();
      97           0 :     SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
      98           0 :     rSet.Put(SfxBoolItem(SID_FONTWORK, pViewFrm->HasChildWindow(nFWId)));
      99             : 
     100             :         // Notes always default to Page anchor.
     101           0 :     bool bDisableAnchor = false;
     102           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     103           0 :     sal_uLong nMarkCount = rMarkList.GetMarkCount();
     104           0 :     if ( nMarkCount == 1 )
     105             :     {
     106           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     107           0 :         if( ScDrawLayer::IsNoteCaption( pObj ) )
     108             :         {
     109           0 :             bDisableAnchor = true;
     110           0 :             rSet.DisableItem( SID_ANCHOR_PAGE );
     111           0 :             rSet.DisableItem( SID_ANCHOR_CELL );
     112             :         }
     113             :     }
     114             : 
     115           0 :     if ( !bDisableAnchor )
     116             :     {
     117           0 :         switch( pView->GetAnchorType() )
     118             :         {
     119             :         case SCA_PAGE:
     120           0 :             rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, sal_True ) );
     121           0 :             rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
     122           0 :         break;
     123             : 
     124             :         case SCA_CELL:
     125           0 :         rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
     126           0 :         rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, sal_True ) );
     127           0 :         break;
     128             : 
     129             :         default:
     130           0 :         rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
     131           0 :         rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
     132           0 :         break;
     133             :         }
     134             :     }
     135           0 : }
     136             : 
     137           0 : void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet )      // Funktionen disablen
     138             : {
     139           0 :     ScDrawView* pView = pViewData->GetScDrawView();
     140             : 
     141             :     //  call IsMirrorAllowed first to make sure ForcePossibilities (and thus CheckMarked)
     142             :     //  is called before GetMarkCount, so the nMarkCount value is valid for the rest of this method.
     143           0 :     if (!pView->IsMirrorAllowed(sal_True,sal_True))
     144             :     {
     145           0 :         rSet.DisableItem( SID_MIRROR_HORIZONTAL );
     146           0 :         rSet.DisableItem( SID_MIRROR_VERTICAL );
     147           0 :         rSet.DisableItem( SID_FLIP_HORIZONTAL );
     148           0 :         rSet.DisableItem( SID_FLIP_VERTICAL );
     149             :     }
     150             : 
     151           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     152           0 :     sal_uLong nMarkCount = rMarkList.GetMarkCount();
     153             : 
     154           0 :     if ( nMarkCount <= 1 || !pView->IsGroupPossible() )
     155           0 :         rSet.DisableItem( SID_GROUP );
     156           0 :     if ( nMarkCount == 0 || !pView->IsUnGroupPossible() )
     157           0 :         rSet.DisableItem( SID_UNGROUP );
     158           0 :     if ( nMarkCount != 1 || !pView->IsGroupEnterPossible() )
     159           0 :         rSet.DisableItem( SID_ENTER_GROUP );
     160           0 :     if ( !pView->IsGroupEntered() )
     161           0 :         rSet.DisableItem( SID_LEAVE_GROUP );
     162             : 
     163           0 :     if ( nMarkCount <= 1 )                      // nichts oder nur ein Objekt selektiert
     164             :     {
     165             :             //  Ausrichtung
     166           0 :         rSet.DisableItem( SID_OBJECT_ALIGN_LEFT );      // keine Ausrichtung an der Seite
     167           0 :         rSet.DisableItem( SID_OBJECT_ALIGN_CENTER );
     168           0 :         rSet.DisableItem( SID_OBJECT_ALIGN_RIGHT );
     169           0 :         rSet.DisableItem( SID_OBJECT_ALIGN_UP );
     170           0 :         rSet.DisableItem( SID_OBJECT_ALIGN_MIDDLE );
     171           0 :         rSet.DisableItem( SID_OBJECT_ALIGN_DOWN );
     172             : 
     173             :         // pseudo slots for Format menu
     174           0 :         rSet.DisableItem( SID_ALIGN_ANY_LEFT );
     175           0 :         rSet.DisableItem( SID_ALIGN_ANY_HCENTER );
     176           0 :         rSet.DisableItem( SID_ALIGN_ANY_RIGHT );
     177           0 :         rSet.DisableItem( SID_ALIGN_ANY_TOP );
     178           0 :         rSet.DisableItem( SID_ALIGN_ANY_VCENTER );
     179           0 :         rSet.DisableItem( SID_ALIGN_ANY_BOTTOM );
     180             :     }
     181             : 
     182             :     // do not change layer of form controls
     183             :     // #i83729# do not change layer of cell notes (on internal layer)
     184           0 :     if ( !nMarkCount || pView->HasMarkedControl() || pView->HasMarkedInternal() )
     185             :     {
     186           0 :         rSet.DisableItem( SID_OBJECT_HEAVEN );
     187           0 :         rSet.DisableItem( SID_OBJECT_HELL );
     188             :     }
     189             :     else
     190             :     {
     191           0 :         if(AreAllObjectsOnLayer(SC_LAYER_FRONT,rMarkList))
     192             :         {
     193           0 :             rSet.DisableItem( SID_OBJECT_HEAVEN );
     194             :         }
     195           0 :         else if(AreAllObjectsOnLayer(SC_LAYER_BACK,rMarkList))
     196             :         {
     197           0 :             rSet.DisableItem( SID_OBJECT_HELL );
     198             :         }
     199             :     }
     200             : 
     201           0 :     sal_Bool bCanRename = false;
     202           0 :     if ( nMarkCount > 1 )
     203             :     {
     204             :         // no hypelink options for a selected group
     205           0 :         rSet.DisableItem( SID_DRAW_HLINK_EDIT );
     206           0 :         rSet.DisableItem( SID_DRAW_HLINK_DELETE );
     207           0 :         rSet.DisableItem( SID_OPEN_HYPERLINK );
     208             :     }
     209           0 :     else if ( nMarkCount == 1 )
     210             :     {
     211           0 :         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
     212           0 :         ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
     213           0 :         if ( !pInfo || pInfo->GetHlink().isEmpty() )
     214             :         {
     215           0 :             rSet.DisableItem( SID_DRAW_HLINK_DELETE );
     216           0 :             rSet.DisableItem( SID_OPEN_HYPERLINK );
     217             :         }
     218           0 :         SdrLayerID nLayerID = pObj->GetLayer();
     219           0 :         if ( nLayerID != SC_LAYER_INTERN )
     220           0 :             bCanRename = sal_True;                          // #i51351# anything except internal objects can be renamed
     221             : 
     222             :         // #91929#; don't show original size entry if not possible
     223           0 :         sal_uInt16 nObjType = pObj->GetObjIdentifier();
     224           0 :         if ( nObjType == OBJ_OLE2 )
     225             :         {
     226           0 :             SdrOle2Obj* pOleObj = static_cast<SdrOle2Obj*>(rMarkList.GetMark( 0 )->GetMarkedSdrObj());
     227           0 :             if (pOleObj->GetObjRef().is() &&
     228           0 :                 ((pOleObj->GetObjRef()->getStatus( pOleObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) ) )
     229             :                 //TODO/LATER: why different slots in Draw and Calc?
     230           0 :                 rSet.DisableItem(SID_ORIGINALSIZE);
     231             :         }
     232           0 :         else if ( nObjType == OBJ_CAPTION )
     233             :         {
     234           0 :             if ( nLayerID == SC_LAYER_INTERN )
     235             :             {
     236             :                 // SdrCaptionObj() Notes cannot be cut/copy in isolation from
     237             :                 // their cells.
     238           0 :                 rSet.DisableItem( SID_CUT );
     239           0 :                 rSet.DisableItem( SID_COPY );
     240             :                 // Notes always default to Page anchor.
     241           0 :                 rSet.DisableItem( SID_ANCHOR_TOGGLE );
     242             :             }
     243             :         }
     244             :     }
     245           0 :     if ( !bCanRename )
     246             :     {
     247             :         // #i68101#
     248           0 :         rSet.DisableItem( SID_RENAME_OBJECT );
     249           0 :         rSet.DisableItem( SID_TITLE_DESCRIPTION_OBJECT );
     250             :     }
     251             : 
     252           0 :     if ( !nMarkCount )                          // nichts selektiert
     253             :     {
     254             :             //  Anordnung
     255           0 :         rSet.DisableItem( SID_FRAME_UP );
     256           0 :         rSet.DisableItem( SID_FRAME_DOWN );
     257           0 :         rSet.DisableItem( SID_FRAME_TO_TOP );
     258           0 :         rSet.DisableItem( SID_FRAME_TO_BOTTOM );
     259             :             //  Clipboard / loeschen
     260           0 :         rSet.DisableItem( SID_DELETE );
     261           0 :         rSet.DisableItem( SID_DELETE_CONTENTS );
     262           0 :         rSet.DisableItem( SID_CUT );
     263           0 :         rSet.DisableItem( SID_COPY );
     264             :             //  sonstiges
     265           0 :         rSet.DisableItem( SID_ANCHOR_TOGGLE );
     266           0 :         rSet.DisableItem( SID_ORIGINALSIZE );
     267           0 :         rSet.DisableItem( SID_ATTR_TRANSFORM );
     268             :     }
     269             : 
     270           0 :     if ( rSet.GetItemState( SID_ENABLE_HYPHENATION ) != SFX_ITEM_UNKNOWN )
     271             :     {
     272           0 :         SfxItemSet aAttrs( pView->GetModel()->GetItemPool() );
     273           0 :         pView->GetAttributes( aAttrs );
     274           0 :         if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
     275             :         {
     276           0 :             sal_Bool bValue = ( (const SfxBoolItem&) aAttrs.Get( EE_PARA_HYPHENATE ) ).GetValue();
     277           0 :             rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION, bValue ) );
     278           0 :         }
     279             :     }
     280             : 
     281           0 :     svx::ExtrusionBar::getState( pView, rSet );
     282           0 :     svx::FontworkBar::getState( pView, rSet );
     283           0 : }
     284             : 
     285             : //
     286             : //          Attribute fuer Drawing-Objekte
     287             : //
     288             : 
     289           0 : void ScDrawShell::GetDrawAttrState( SfxItemSet& rSet )
     290             : {
     291           0 :     Point       aMousePos   = pViewData->GetMousePosPixel();
     292           0 :     Window*     pWindow     = pViewData->GetActiveWin();
     293           0 :     ScDrawView* pDrView     = pViewData->GetScDrawView();
     294           0 :     Point       aPos        = pWindow->PixelToLogic(aMousePos);
     295           0 :     sal_Bool        bHasMarked  = pDrView->AreObjectsMarked();
     296             : 
     297           0 :     if( bHasMarked )
     298             :     {
     299           0 :         rSet.Put( pDrView->GetAttrFromMarked(false), false );
     300             :     }
     301             :     else
     302             :     {
     303           0 :         rSet.Put( pDrView->GetDefaultAttr() );
     304             :     }
     305             : 
     306           0 :     SdrPageView* pPV = pDrView->GetSdrPageView();
     307           0 :     if ( pPV )
     308             :     {
     309             :         // #i52073# when a sheet with an active OLE object is deleted,
     310             :         // the slot state is queried without an active page view
     311             : 
     312             :         //  Items for position and size (see ScGridWindow::UpdateStatusPosSize, #108137#)
     313             : 
     314             :         // #i34458# The SvxSizeItem in SID_TABLE_CELL is no longer needed by
     315             :         // SvxPosSizeStatusBarControl, it's enough to have it in SID_ATTR_SIZE.
     316             : 
     317           0 :         sal_Bool bActionItem = false;
     318           0 :         if ( pDrView->IsAction() )              // action rectangle
     319             :         {
     320           0 :             Rectangle aRect;
     321           0 :             pDrView->TakeActionRect( aRect );
     322           0 :             if ( !aRect.IsEmpty() )
     323             :             {
     324           0 :                 pPV->LogicToPagePos(aRect);
     325           0 :                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
     326           0 :                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
     327           0 :                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
     328           0 :                 bActionItem = sal_True;
     329             :             }
     330             :         }
     331           0 :         if ( !bActionItem )
     332             :         {
     333           0 :             if ( pDrView->AreObjectsMarked() )      // selected objects
     334             :             {
     335           0 :                 Rectangle aRect = pDrView->GetAllMarkedRect();
     336           0 :                 pPV->LogicToPagePos(aRect);
     337           0 :                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
     338           0 :                 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
     339           0 :                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize ) );
     340             :             }
     341             :             else                                // mouse position
     342             :             {
     343             :                 // aPos is initialized above
     344           0 :                 pPV->LogicToPagePos(aPos);
     345           0 :                 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
     346           0 :                 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
     347             :             }
     348             :         }
     349             :     }
     350           0 : }
     351             : 
     352           0 : void ScDrawShell::GetAttrFuncState(SfxItemSet &rSet)
     353             : {
     354             :     //  Dialoge fuer Draw-Attribute disablen, wenn noetig
     355             : 
     356           0 :     ScDrawView* pDrView = pViewData->GetScDrawView();
     357           0 :     SfxItemSet aViewSet = pDrView->GetAttrFromMarked(false);
     358             : 
     359           0 :     if ( aViewSet.GetItemState( XATTR_LINESTYLE ) == SFX_ITEM_DEFAULT )
     360             :     {
     361           0 :         rSet.DisableItem( SID_ATTRIBUTES_LINE );
     362           0 :         rSet.DisableItem( SID_ATTR_LINEEND_STYLE );     // Tbx-Controller
     363             :     }
     364             : 
     365           0 :     if ( aViewSet.GetItemState( XATTR_FILLSTYLE ) == SFX_ITEM_DEFAULT )
     366           0 :         rSet.DisableItem( SID_ATTRIBUTES_AREA );
     367           0 : }
     368             : 
     369           0 : sal_Bool ScDrawShell::AreAllObjectsOnLayer(sal_uInt16 nLayerNo,const SdrMarkList& rMark)
     370             : {
     371           0 :     sal_Bool bResult=sal_True;
     372           0 :     sal_uLong nCount = rMark.GetMarkCount();
     373           0 :     for (sal_uLong i=0; i<nCount; i++)
     374             :     {
     375           0 :         SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
     376           0 :         if ( !pObj->ISA(SdrUnoObj) )
     377             :         {
     378           0 :             if(nLayerNo!=pObj->GetLayer())
     379             :             {
     380           0 :                 bResult=false;
     381           0 :                 break;
     382             :             }
     383             :         }
     384             :     }
     385           0 :     return bResult;
     386             : }
     387             : 
     388           0 : void ScDrawShell::GetDrawAttrStateForIFBX( SfxItemSet& rSet )
     389             : {
     390           0 :     ScDrawView* pView = pViewData->GetScDrawView();
     391           0 :     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
     392             : 
     393           0 :     if( rMarkList.GetMark(0) != 0 )
     394             :     {
     395           0 :         SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
     396           0 :         rSet.Put(aNewAttr, sal_False);
     397             :     }
     398           0 : }
     399             : 
     400             : 
     401             : 
     402             : 
     403           6 : void ScDrawShell::Activate (const sal_Bool bMDI)
     404             : {
     405             :     (void)bMDI;
     406             : 
     407             :     ContextChangeEventMultiplexer::NotifyContextChange(
     408           6 :         GetFrame()->GetFrame().GetController(),
     409             :         ::sfx2::sidebar::EnumContext::GetContextEnum(
     410          12 :             GetSidebarContextName()));
     411           6 : }
     412             : 
     413             : 
     414             : 
     415             : 
     416          16 : ::rtl::OUString ScDrawShell::GetSidebarContextName (void)
     417             : {
     418             :     return sfx2::sidebar::EnumContext::GetContextName(
     419             :         ::svx::sidebar::SelectionAnalyzer::GetContextForSelection_SC(
     420          16 :             GetDrawView()->GetMarkedObjectList()));
     421          93 : }
     422             : 
     423             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10