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

Generated by: LCOV version 1.10