LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/dlg - LayerTabBar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 142 0.0 %
Date: 2012-12-17 Functions: 0 16 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             : 
      21             : #include "LayerTabBar.hxx"
      22             : #include <svx/svdlayer.hxx>
      23             : #include <svx/svdpagv.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : 
      27             : 
      28             : #include "sdattr.hxx"
      29             : #include "app.hxx"
      30             : #include "helpids.h"
      31             : #include "app.hrc"
      32             : #include "glob.hrc"
      33             : #include "strings.hrc"
      34             : #include "res_bmp.hrc"
      35             : #include "DrawViewShell.hxx"
      36             : #include "Window.hxx"
      37             : #include "View.hxx"
      38             : #include "drawdoc.hxx"
      39             : #include "sdresid.hxx"
      40             : #include "DrawDocShell.hxx"
      41             : #include "drawview.hxx"
      42             : #include "undolayer.hxx"
      43             : 
      44             : 
      45             : namespace sd {
      46             : 
      47             : #define SWITCH_TIMEOUT  20
      48             : 
      49             : 
      50             : /*************************************************************************
      51             : |*
      52             : |* Standard-Konstruktor
      53             : |*
      54             : \************************************************************************/
      55             : 
      56           0 : LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, Window* pParent)
      57             :     : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE ) ),
      58             :     DropTargetHelper( this ),
      59           0 :     pDrViewSh(pViewSh)
      60             : {
      61           0 :     EnableEditMode();
      62           0 :     SetSizePixel(Size(0, 0));
      63           0 :     SetMaxPageWidth( 150 );
      64           0 :     SetHelpId( HID_SD_TABBAR_LAYERS );
      65           0 : }
      66             : 
      67             : 
      68           0 : LayerTabBar::LayerTabBar (
      69             :     DrawViewShell* pViewSh,
      70             :     Window* pParent,
      71             :     const ResId& rResId)
      72           0 :     : TabBar (pParent, rResId.GetWinBits()),
      73             :     DropTargetHelper( this ),
      74           0 :     pDrViewSh(pViewSh)
      75             : {
      76           0 :     EnableEditMode();
      77           0 : }
      78             : 
      79             : /*************************************************************************
      80             : |*
      81             : |* Destruktor
      82             : |*
      83             : \************************************************************************/
      84             : 
      85           0 : LayerTabBar::~LayerTabBar()
      86             : {
      87           0 : }
      88             : 
      89           0 : void LayerTabBar::Select()
      90             : {
      91           0 :     SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
      92           0 :     pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
      93           0 : }
      94             : 
      95           0 : void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt)
      96             : {
      97           0 :     sal_Bool bSetPageID=sal_False;
      98             : 
      99           0 :     if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2())
     100             :     {
     101           0 :         Point aPosPixel = rMEvt.GetPosPixel();
     102           0 :         sal_uInt16 aLayerId = GetPageId( PixelToLogic(aPosPixel) );
     103             : 
     104           0 :         if (aLayerId == 0)
     105             :         {
     106           0 :             SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     107           0 :             pDispatcher->Execute(SID_INSERTLAYER, SFX_CALLMODE_SYNCHRON);
     108             : 
     109           0 :             bSetPageID=sal_True;
     110             :         }
     111           0 :         else if (rMEvt.IsShift())
     112             :         {
     113             :             // Toggle zw. Layer sichtbar / unsichtbar
     114           0 :             String aName(GetPageText(aLayerId));
     115           0 :             SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView();
     116           0 :             sal_Bool bVisible = pPV->IsLayerVisible(aName);
     117           0 :             pPV->SetLayerVisible(aName, !bVisible);
     118           0 :             pDrViewSh->ResetActualLayer();
     119             :         }
     120             :     }
     121             : 
     122             :     // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
     123             :     // because you want to activate the new layer
     124           0 :     if( !bSetPageID )
     125           0 :         TabBar::MouseButtonDown(rMEvt);
     126           0 : }
     127             : 
     128           0 : void LayerTabBar::DoubleClick()
     129             : {
     130           0 :     if (GetCurPageId() != 0)
     131             :     {
     132           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     133           0 :         pDispatcher->Execute( SID_MODIFYLAYER, SFX_CALLMODE_SYNCHRON );
     134             :     }
     135           0 : }
     136             : 
     137             : 
     138             : /*************************************************************************
     139             : |*
     140             : |* AcceptDrop-Event
     141             : |*
     142             : \************************************************************************/
     143             : 
     144           0 : sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt )
     145             : {
     146           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     147             : 
     148           0 :     if( rEvt.mbLeaving )
     149           0 :         EndSwitchPage();
     150             : 
     151           0 :     if( !pDrViewSh->GetDocSh()->IsReadOnly() )
     152             :     {
     153           0 :         sal_uInt16          nPageId = SDRPAGE_NOTFOUND;
     154           0 :         Point           aPos( PixelToLogic( rEvt.maPosPixel ) );
     155           0 :         sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
     156           0 :             GetPageText( GetPageId( aPos ) ), sal_False );
     157             : 
     158           0 :         nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId );
     159             : 
     160           0 :         SwitchPage( aPos );
     161             :     }
     162             : 
     163           0 :     return nRet;
     164             : }
     165             : 
     166             : /*************************************************************************
     167             : |*
     168             : |* ExecuteDrop-Event
     169             : |*
     170             : \************************************************************************/
     171             : 
     172           0 : sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt )
     173             : {
     174           0 :     sal_uInt16          nPageId = SDRPAGE_NOTFOUND;
     175           0 :     sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
     176           0 :         GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), sal_False );
     177           0 :     sal_Int8        nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId );
     178             : 
     179           0 :     EndSwitchPage();
     180             : 
     181           0 :     return nRet;
     182             : 
     183             : }
     184             : 
     185           0 : void  LayerTabBar::Command(const CommandEvent& rCEvt)
     186             : {
     187           0 :     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
     188             :     {
     189           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     190           0 :         pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP));
     191             :     }
     192           0 : }
     193             : 
     194           0 : long LayerTabBar::StartRenaming()
     195             : {
     196           0 :     sal_Bool bOK = sal_True;
     197           0 :     String aLayerName = GetPageText( GetEditPageId() );
     198           0 :     String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
     199           0 :     String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
     200           0 :     String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
     201           0 :     String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
     202           0 :     String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
     203             : 
     204           0 :     if ( aLayerName == aLayoutLayer       || aLayerName == aControlsLayer  ||
     205           0 :          aLayerName == aMeasureLinesLayer ||
     206           0 :          aLayerName == aBackgroundLayer   || aLayerName == aBackgroundObjLayer )
     207             :     {
     208             :         // Diese Namen duerfen nicht veraendert werden
     209           0 :         bOK = sal_False;
     210             :     }
     211             :     else
     212             :     {
     213           0 :         ::sd::View* pView = pDrViewSh->GetView();
     214             : 
     215           0 :         if ( pView->IsTextEdit() )
     216             :         {
     217           0 :             pView->SdrEndTextEdit();
     218             :         }
     219             :     }
     220             : 
     221           0 :     return(bOK);
     222             : }
     223             : 
     224           0 : long LayerTabBar::AllowRenaming()
     225             : {
     226           0 :     sal_Bool bOK = sal_True;
     227             : 
     228             :     // Ueberpruefung auf schon vorhandene Namen
     229           0 :     ::sd::View* pView = pDrViewSh->GetView();
     230           0 :     SdDrawDocument& rDoc = pView->GetDoc();
     231           0 :     String aLayerName = pView->GetActiveLayer();
     232           0 :     SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
     233           0 :     String aNewName( GetEditText() );
     234             : 
     235           0 :     if ( aNewName.Len() == 0 ||
     236           0 :         (rLayerAdmin.GetLayer( aNewName, sal_False ) && aLayerName != aNewName) )
     237             :     {
     238             :         // Name ist schon vorhanden
     239           0 :         WarningBox aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ),
     240           0 :                                 String(SdResId( STR_WARN_NAME_DUPLICATE ) ) );
     241           0 :         aWarningBox.Execute();
     242           0 :         bOK = sal_False;
     243             :     }
     244             : 
     245           0 :     if (bOK)
     246             :     {
     247           0 :         String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
     248           0 :         String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
     249           0 :         String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
     250           0 :         String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
     251           0 :         String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
     252             : 
     253           0 :         if ( aNewName == aLayoutLayer       || aNewName == aControlsLayer  ||
     254           0 :              aNewName == aMeasureLinesLayer ||
     255           0 :              aNewName == aBackgroundLayer   || aNewName == aBackgroundObjLayer )
     256             :         {
     257             :             // Diese Namen duerfen nicht vergeben werden
     258           0 :             bOK = sal_False;
     259           0 :         }
     260             :     }
     261             : 
     262           0 :     return(bOK);
     263             : }
     264             : 
     265           0 : void LayerTabBar::EndRenaming()
     266             : {
     267           0 :     if( !IsEditModeCanceled() )
     268             :     {
     269           0 :         ::sd::View* pView = pDrViewSh->GetView();
     270           0 :         DrawView* pDrView = PTR_CAST( DrawView, pView );
     271             : 
     272           0 :         SdDrawDocument& rDoc = pView->GetDoc();
     273           0 :         String aLayerName = pView->GetActiveLayer();
     274           0 :         SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
     275           0 :         SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, sal_False);
     276             : 
     277           0 :         if (pLayer)
     278             :         {
     279           0 :             String aNewName( GetEditText() );
     280             : 
     281             :             DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" );
     282           0 :             if( pDrView )
     283             :             {
     284           0 :                 ::svl::IUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager();
     285             :                 SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction(
     286             :                     &rDoc,
     287             :                     pLayer,
     288             :                     aLayerName,
     289             :                     pLayer->GetTitle(),
     290             :                     pLayer->GetDescription(),
     291           0 :                     pDrView->IsLayerVisible(aLayerName),
     292           0 :                     pDrView->IsLayerLocked(aLayerName),
     293           0 :                     pDrView->IsLayerPrintable(aLayerName),
     294             :                     aNewName,
     295             :                     pLayer->GetTitle(),
     296             :                     pLayer->GetDescription(),
     297           0 :                     pDrView->IsLayerVisible(aLayerName),
     298           0 :                     pDrView->IsLayerLocked(aLayerName),
     299           0 :                     pDrView->IsLayerPrintable(aLayerName)
     300           0 :                     );
     301           0 :                 pManager->AddUndoAction( pAction );
     302             :             }
     303             : 
     304             :             // Zuerst View benachrichtigen, da innerhalb von SetName() schon
     305             :             // ResetActualLayer() gerufen wird und an der View der Layer dann
     306             :             // schon bekannt sein muss.
     307           0 :             pView->SetActiveLayer(aNewName);
     308           0 :             pLayer->SetName(aNewName);
     309           0 :             rDoc.SetChanged(sal_True);
     310           0 :         }
     311             :     }
     312           0 : }
     313             : 
     314           0 : void LayerTabBar::ActivatePage()
     315             : {
     316           0 :     if ( /*IsInSwitching*/ 1 && pDrViewSh!=NULL)
     317             :     {
     318             : 
     319           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     320           0 :         pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
     321             :     }
     322           0 : }
     323             : 
     324             : 
     325             : 
     326             : 
     327           0 : void LayerTabBar::SendActivatePageEvent (void)
     328             : {
     329             :     CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
     330           0 :         reinterpret_cast<void*>(GetCurPageId()));
     331           0 : }
     332             : 
     333             : 
     334             : 
     335             : 
     336           0 : void LayerTabBar::SendDeactivatePageEvent (void)
     337             : {
     338             :     CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
     339           0 :         reinterpret_cast<void*>(GetCurPageId()));
     340           0 : }
     341             : 
     342             : } // end of namespace sd
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10