LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - LayerTabBar.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 10 138 7.2 %
Date: 2015-06-13 12:38:46 Functions: 5 17 29.4 %
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 "LayerTabBar.hxx"
      21             : #include <svx/svdlayer.hxx>
      22             : #include <svx/svdpagv.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <sfx2/dispatch.hxx>
      25             : 
      26             : #include "sdattr.hxx"
      27             : #include "sdmod.hxx"
      28             : #include "helpids.h"
      29             : #include "app.hrc"
      30             : #include "glob.hrc"
      31             : #include "strings.hrc"
      32             : #include "res_bmp.hrc"
      33             : #include "DrawViewShell.hxx"
      34             : #include "Window.hxx"
      35             : #include "View.hxx"
      36             : #include "drawdoc.hxx"
      37             : #include "sdresid.hxx"
      38             : #include "DrawDocShell.hxx"
      39             : #include "drawview.hxx"
      40             : #include "undolayer.hxx"
      41             : 
      42             : namespace sd {
      43             : 
      44             : /**
      45             :  * default constructor
      46             :  */
      47          86 : LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, vcl::Window* pParent)
      48             :     : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL ) ),
      49             :     DropTargetHelper( this ),
      50          86 :     pDrViewSh(pViewSh)
      51             : {
      52          86 :     EnableEditMode();
      53          86 :     SetSizePixel(Size(0, 0));
      54          86 :     SetMaxPageWidth( 150 );
      55          86 :     SetHelpId( HID_SD_TABBAR_LAYERS );
      56          86 : }
      57             : 
      58         172 : LayerTabBar::~LayerTabBar()
      59             : {
      60         172 : }
      61             : 
      62           0 : void LayerTabBar::Select()
      63             : {
      64           0 :     SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
      65           0 :     pDispatcher->Execute(SID_SWITCHLAYER, SfxCallMode::ASYNCHRON);
      66           0 : }
      67             : 
      68           0 : void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt)
      69             : {
      70           0 :     bool bSetPageID=false;
      71             : 
      72           0 :     if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2())
      73             :     {
      74           0 :         Point aPosPixel = rMEvt.GetPosPixel();
      75           0 :         sal_uInt16 aLayerId = GetPageId( PixelToLogic(aPosPixel) );
      76             : 
      77           0 :         if (aLayerId == 0)
      78             :         {
      79           0 :             SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
      80           0 :             pDispatcher->Execute(SID_INSERTLAYER, SfxCallMode::SYNCHRON);
      81             : 
      82           0 :             bSetPageID=true;
      83             :         }
      84           0 :         else if (rMEvt.IsShift())
      85             :         {
      86             :             // Toggle between layer visible / hidden
      87           0 :             OUString aName(GetPageText(aLayerId));
      88           0 :             SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView();
      89           0 :             bool bVisible = pPV->IsLayerVisible(aName);
      90           0 :             pPV->SetLayerVisible(aName, !bVisible);
      91           0 :             pDrViewSh->ResetActualLayer();
      92             :         }
      93             :     }
      94             : 
      95             :     // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
      96             :     // because you want to activate the new layer
      97           0 :     if( !bSetPageID )
      98           0 :         TabBar::MouseButtonDown(rMEvt);
      99           0 : }
     100             : 
     101           0 : void LayerTabBar::DoubleClick()
     102             : {
     103           0 :     if (GetCurPageId() != 0)
     104             :     {
     105           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     106           0 :         pDispatcher->Execute( SID_MODIFYLAYER, SfxCallMode::SYNCHRON );
     107             :     }
     108           0 : }
     109             : 
     110             : /**
     111             :  * AcceptDrop-Event
     112             :  */
     113             : 
     114           0 : sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt )
     115             : {
     116           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     117             : 
     118           0 :     if( rEvt.mbLeaving )
     119           0 :         EndSwitchPage();
     120             : 
     121           0 :     if( !pDrViewSh->GetDocSh()->IsReadOnly() )
     122             :     {
     123           0 :         sal_uInt16          nPageId = SDRPAGE_NOTFOUND;
     124           0 :         Point           aPos( PixelToLogic( rEvt.maPosPixel ) );
     125           0 :         sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
     126           0 :             GetPageText( GetPageId( aPos ) ), false );
     127             : 
     128           0 :         nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId );
     129             : 
     130           0 :         SwitchPage( aPos );
     131             :     }
     132             : 
     133           0 :     return nRet;
     134             : }
     135             : 
     136             : /**
     137             :  * ExecuteDrop-Event
     138             :  */
     139           0 : sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt )
     140             : {
     141           0 :     sal_uInt16          nPageId = SDRPAGE_NOTFOUND;
     142           0 :     sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
     143           0 :         GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), false );
     144           0 :     sal_Int8        nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId );
     145             : 
     146           0 :     EndSwitchPage();
     147             : 
     148           0 :     return nRet;
     149             : 
     150             : }
     151             : 
     152           0 : void  LayerTabBar::Command(const CommandEvent& rCEvt)
     153             : {
     154           0 :     if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
     155             :     {
     156           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     157           0 :         pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP));
     158             :     }
     159           0 : }
     160             : 
     161           0 : bool LayerTabBar::StartRenaming()
     162             : {
     163           0 :     bool bOK = true;
     164           0 :     OUString aLayerName = GetPageText( GetEditPageId() );
     165           0 :     OUString aLayoutLayer = SD_RESSTR(STR_LAYER_LAYOUT);
     166           0 :     OUString aControlsLayer = SD_RESSTR(STR_LAYER_CONTROLS);
     167           0 :     OUString aMeasureLinesLayer = SD_RESSTR(STR_LAYER_MEASURELINES);
     168           0 :     OUString aBackgroundLayer = SD_RESSTR(STR_LAYER_BCKGRND);
     169           0 :     OUString aBackgroundObjLayer = SD_RESSTR(STR_LAYER_BCKGRNDOBJ);
     170             : 
     171           0 :     if ( aLayerName == aLayoutLayer       || aLayerName == aControlsLayer  ||
     172           0 :          aLayerName == aMeasureLinesLayer ||
     173           0 :          aLayerName == aBackgroundLayer   || aLayerName == aBackgroundObjLayer )
     174             :     {
     175             :         // It is not allowed to change this names
     176           0 :         bOK = false;
     177             :     }
     178             :     else
     179             :     {
     180           0 :         ::sd::View* pView = pDrViewSh->GetView();
     181             : 
     182           0 :         if ( pView->IsTextEdit() )
     183             :         {
     184           0 :             pView->SdrEndTextEdit();
     185             :         }
     186             :     }
     187             : 
     188           0 :     return bOK;
     189             : }
     190             : 
     191           0 : TabBarAllowRenamingReturnCode LayerTabBar::AllowRenaming()
     192             : {
     193           0 :     bool bOK = true;
     194             : 
     195             :     // Check if names already exists
     196           0 :     ::sd::View* pView = pDrViewSh->GetView();
     197           0 :     SdDrawDocument& rDoc = pView->GetDoc();
     198           0 :     OUString aLayerName = pView->GetActiveLayer();
     199           0 :     SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
     200           0 :     OUString aNewName( GetEditText() );
     201             : 
     202           0 :     if (aNewName.isEmpty() ||
     203           0 :         (rLayerAdmin.GetLayer( aNewName, false ) && aLayerName != aNewName) )
     204             :     {
     205             :         // Name already exists
     206           0 :         ScopedVclPtrInstance<WarningBox> aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ),
     207           0 :                                 SD_RESSTR( STR_WARN_NAME_DUPLICATE ) );
     208           0 :         aWarningBox->Execute();
     209           0 :         bOK = false;
     210             :     }
     211             : 
     212           0 :     if (bOK)
     213             :     {
     214           0 :         OUString aLayoutLayer = SD_RESSTR(STR_LAYER_LAYOUT);
     215           0 :         OUString aControlsLayer = SD_RESSTR(STR_LAYER_CONTROLS);
     216           0 :         OUString aMeasureLinesLayer = SD_RESSTR(STR_LAYER_MEASURELINES);
     217           0 :         OUString aBackgroundLayer = SD_RESSTR(STR_LAYER_BCKGRND);
     218           0 :         OUString aBackgroundObjLayer = SD_RESSTR(STR_LAYER_BCKGRNDOBJ);
     219             : 
     220           0 :         if ( aNewName == aLayoutLayer       || aNewName == aControlsLayer  ||
     221           0 :              aNewName == aMeasureLinesLayer ||
     222           0 :              aNewName == aBackgroundLayer   || aNewName == aBackgroundObjLayer )
     223             :         {
     224             :             // It is not allowed to use his names
     225           0 :             bOK = false;
     226           0 :         }
     227             :     }
     228             : 
     229           0 :     return bOK ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO;
     230             : }
     231             : 
     232           0 : void LayerTabBar::EndRenaming()
     233             : {
     234           0 :     if( !IsEditModeCanceled() )
     235             :     {
     236           0 :         ::sd::View* pView = pDrViewSh->GetView();
     237           0 :         DrawView* pDrView = PTR_CAST( DrawView, pView );
     238             : 
     239           0 :         SdDrawDocument& rDoc = pView->GetDoc();
     240           0 :         OUString aLayerName = pView->GetActiveLayer();
     241           0 :         SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
     242           0 :         SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, false);
     243             : 
     244           0 :         if (pLayer)
     245             :         {
     246           0 :             OUString aNewName( GetEditText() );
     247             : 
     248             :             DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" );
     249           0 :             if( pDrView )
     250             :             {
     251           0 :                 ::svl::IUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager();
     252             :                 SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction(
     253             :                     &rDoc,
     254             :                     pLayer,
     255             :                     aLayerName,
     256             :                     pLayer->GetTitle(),
     257             :                     pLayer->GetDescription(),
     258           0 :                     pDrView->IsLayerVisible(aLayerName),
     259           0 :                     pDrView->IsLayerLocked(aLayerName),
     260           0 :                     pDrView->IsLayerPrintable(aLayerName),
     261             :                     aNewName,
     262             :                     pLayer->GetTitle(),
     263             :                     pLayer->GetDescription(),
     264           0 :                     pDrView->IsLayerVisible(aLayerName),
     265           0 :                     pDrView->IsLayerLocked(aLayerName),
     266           0 :                     pDrView->IsLayerPrintable(aLayerName)
     267           0 :                     );
     268           0 :                 pManager->AddUndoAction( pAction );
     269             :             }
     270             : 
     271             :             // First notify View since SetName() calls ResetActualLayer() and
     272             :             // the View then already has to know the Layer
     273           0 :             pView->SetActiveLayer(aNewName);
     274           0 :             pLayer->SetName(aNewName);
     275           0 :             rDoc.SetChanged(true);
     276           0 :         }
     277             :     }
     278           0 : }
     279             : 
     280           0 : void LayerTabBar::ActivatePage()
     281             : {
     282           0 :     if ( /*IsInSwitching*/ true && pDrViewSh!=NULL)
     283             :     {
     284             : 
     285           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     286           0 :         pDispatcher->Execute(SID_SWITCHLAYER, SfxCallMode::ASYNCHRON);
     287             :     }
     288           0 : }
     289             : 
     290           0 : void LayerTabBar::SendActivatePageEvent()
     291             : {
     292             :     CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
     293           0 :         reinterpret_cast<void*>(GetCurPageId()));
     294           0 : }
     295             : 
     296           0 : void LayerTabBar::SendDeactivatePageEvent()
     297             : {
     298             :     CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
     299           0 :         reinterpret_cast<void*>(GetCurPageId()));
     300           0 : }
     301             : 
     302          66 : } // end of namespace sd
     303             : 
     304             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11