LCOV - code coverage report
Current view: top level - sd/source/ui/dlg - LayerTabBar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 142 6.3 %
Date: 2012-08-25 Functions: 3 16 18.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 282 2.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "LayerTabBar.hxx"
      31                 :            : #include <svx/svdlayer.hxx>
      32                 :            : #include <svx/svdpagv.hxx>
      33                 :            : #include <vcl/msgbox.hxx>
      34                 :            : #include <sfx2/dispatch.hxx>
      35                 :            : 
      36                 :            : 
      37                 :            : #include "sdattr.hxx"
      38                 :            : #include "app.hxx"
      39                 :            : #include "helpids.h"
      40                 :            : #include "app.hrc"
      41                 :            : #include "glob.hrc"
      42                 :            : #include "strings.hrc"
      43                 :            : #include "res_bmp.hrc"
      44                 :            : #include "DrawViewShell.hxx"
      45                 :            : #include "Window.hxx"
      46                 :            : #include "View.hxx"
      47                 :            : #include "drawdoc.hxx"
      48                 :            : #include "sdresid.hxx"
      49                 :            : #include "DrawDocShell.hxx"
      50                 :            : #include "drawview.hxx"
      51                 :            : #include "undolayer.hxx"
      52                 :            : 
      53                 :            : 
      54                 :            : namespace sd {
      55                 :            : 
      56                 :            : #define SWITCH_TIMEOUT  20
      57                 :            : 
      58                 :            : 
      59                 :            : /*************************************************************************
      60                 :            : |*
      61                 :            : |* Standard-Konstruktor
      62                 :            : |*
      63                 :            : \************************************************************************/
      64                 :            : 
      65                 :        104 : LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, Window* pParent)
      66                 :            :     : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE ) ),
      67                 :            :     DropTargetHelper( this ),
      68         [ +  - ]:        104 :     pDrViewSh(pViewSh)
      69                 :            : {
      70                 :        104 :     EnableEditMode();
      71         [ +  - ]:        104 :     SetSizePixel(Size(0, 0));
      72         [ +  - ]:        104 :     SetMaxPageWidth( 150 );
      73         [ +  - ]:        104 :     SetHelpId( HID_SD_TABBAR_LAYERS );
      74                 :        104 : }
      75                 :            : 
      76                 :            : 
      77                 :          0 : LayerTabBar::LayerTabBar (
      78                 :            :     DrawViewShell* pViewSh,
      79                 :            :     Window* pParent,
      80                 :            :     const ResId& rResId)
      81                 :          0 :     : TabBar (pParent, rResId.GetWinBits()),
      82                 :            :     DropTargetHelper( this ),
      83         [ #  # ]:          0 :     pDrViewSh(pViewSh)
      84                 :            : {
      85                 :          0 :     EnableEditMode();
      86                 :          0 : }
      87                 :            : 
      88                 :            : /*************************************************************************
      89                 :            : |*
      90                 :            : |* Destruktor
      91                 :            : |*
      92                 :            : \************************************************************************/
      93                 :            : 
      94         [ +  - ]:        104 : LayerTabBar::~LayerTabBar()
      95                 :            : {
      96         [ -  + ]:        208 : }
      97                 :            : 
      98                 :          0 : void LayerTabBar::Select()
      99                 :            : {
     100                 :          0 :     SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     101                 :          0 :     pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
     102                 :          0 : }
     103                 :            : 
     104                 :          0 : void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt)
     105                 :            : {
     106                 :          0 :     sal_Bool bSetPageID=sal_False;
     107                 :            : 
     108 [ #  # ][ #  # ]:          0 :     if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2())
         [ #  # ][ #  # ]
     109                 :            :     {
     110                 :          0 :         Point aPosPixel = rMEvt.GetPosPixel();
     111 [ #  # ][ #  # ]:          0 :         sal_uInt16 aLayerId = GetPageId( PixelToLogic(aPosPixel) );
     112                 :            : 
     113         [ #  # ]:          0 :         if (aLayerId == 0)
     114                 :            :         {
     115         [ #  # ]:          0 :             SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     116         [ #  # ]:          0 :             pDispatcher->Execute(SID_INSERTLAYER, SFX_CALLMODE_SYNCHRON);
     117                 :            : 
     118                 :          0 :             bSetPageID=sal_True;
     119                 :            :         }
     120         [ #  # ]:          0 :         else if (rMEvt.IsShift())
     121                 :            :         {
     122                 :            :             // Toggle zw. Layer sichtbar / unsichtbar
     123         [ #  # ]:          0 :             String aName(GetPageText(aLayerId));
     124                 :          0 :             SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView();
     125         [ #  # ]:          0 :             sal_Bool bVisible = pPV->IsLayerVisible(aName);
     126         [ #  # ]:          0 :             pPV->SetLayerVisible(aName, !bVisible);
     127 [ #  # ][ #  # ]:          0 :             pDrViewSh->ResetActualLayer();
     128                 :            :         }
     129                 :            :     }
     130                 :            : 
     131                 :            :     // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
     132                 :            :     // because you want to activate the new layer
     133         [ #  # ]:          0 :     if( !bSetPageID )
     134                 :          0 :         TabBar::MouseButtonDown(rMEvt);
     135                 :          0 : }
     136                 :            : 
     137                 :          0 : void LayerTabBar::DoubleClick()
     138                 :            : {
     139         [ #  # ]:          0 :     if (GetCurPageId() != 0)
     140                 :            :     {
     141                 :          0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     142                 :          0 :         pDispatcher->Execute( SID_MODIFYLAYER, SFX_CALLMODE_SYNCHRON );
     143                 :            :     }
     144                 :          0 : }
     145                 :            : 
     146                 :            : 
     147                 :            : /*************************************************************************
     148                 :            : |*
     149                 :            : |* AcceptDrop-Event
     150                 :            : |*
     151                 :            : \************************************************************************/
     152                 :            : 
     153                 :          0 : sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt )
     154                 :            : {
     155                 :          0 :     sal_Int8 nRet = DND_ACTION_NONE;
     156                 :            : 
     157         [ #  # ]:          0 :     if( rEvt.mbLeaving )
     158                 :          0 :         EndSwitchPage();
     159                 :            : 
     160         [ #  # ]:          0 :     if( !pDrViewSh->GetDocSh()->IsReadOnly() )
     161                 :            :     {
     162                 :          0 :         sal_uInt16          nPageId = SDRPAGE_NOTFOUND;
     163         [ #  # ]:          0 :         Point           aPos( PixelToLogic( rEvt.maPosPixel ) );
     164                 :          0 :         sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
     165         [ #  # ]:          0 :             GetPageText( GetPageId( aPos ) ), sal_False );
           [ #  #  #  # ]
                 [ #  # ]
     166                 :            : 
     167         [ #  # ]:          0 :         nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId );
     168                 :            : 
     169         [ #  # ]:          0 :         SwitchPage( aPos );
     170                 :            :     }
     171                 :            : 
     172                 :          0 :     return nRet;
     173                 :            : }
     174                 :            : 
     175                 :            : /*************************************************************************
     176                 :            : |*
     177                 :            : |* ExecuteDrop-Event
     178                 :            : |*
     179                 :            : \************************************************************************/
     180                 :            : 
     181                 :          0 : sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt )
     182                 :            : {
     183                 :          0 :     sal_uInt16          nPageId = SDRPAGE_NOTFOUND;
     184                 :          0 :     sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
     185         [ #  # ]:          0 :         GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), sal_False );
           [ #  #  #  # ]
                 [ #  # ]
     186                 :          0 :     sal_Int8        nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId );
     187                 :            : 
     188                 :          0 :     EndSwitchPage();
     189                 :            : 
     190                 :          0 :     return nRet;
     191                 :            : 
     192                 :            : }
     193                 :            : 
     194                 :          0 : void  LayerTabBar::Command(const CommandEvent& rCEvt)
     195                 :            : {
     196         [ #  # ]:          0 :     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
     197                 :            :     {
     198                 :          0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     199         [ #  # ]:          0 :         pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP));
     200                 :            :     }
     201                 :          0 : }
     202                 :            : 
     203                 :          0 : long LayerTabBar::StartRenaming()
     204                 :            : {
     205                 :          0 :     sal_Bool bOK = sal_True;
     206         [ #  # ]:          0 :     String aLayerName = GetPageText( GetEditPageId() );
     207 [ #  # ][ #  # ]:          0 :     String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
     208 [ #  # ][ #  # ]:          0 :     String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
     209 [ #  # ][ #  # ]:          0 :     String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
     210 [ #  # ][ #  # ]:          0 :     String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
     211 [ #  # ][ #  # ]:          0 :     String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
     212                 :            : 
     213 [ #  # ][ #  # ]:          0 :     if ( aLayerName == aLayoutLayer       || aLayerName == aControlsLayer  ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     214         [ #  # ]:          0 :          aLayerName == aMeasureLinesLayer ||
     215 [ #  # ][ #  # ]:          0 :          aLayerName == aBackgroundLayer   || aLayerName == aBackgroundObjLayer )
     216                 :            :     {
     217                 :            :         // Diese Namen duerfen nicht veraendert werden
     218                 :          0 :         bOK = sal_False;
     219                 :            :     }
     220                 :            :     else
     221                 :            :     {
     222                 :          0 :         ::sd::View* pView = pDrViewSh->GetView();
     223                 :            : 
     224 [ #  # ][ #  # ]:          0 :         if ( pView->IsTextEdit() )
     225                 :            :         {
     226         [ #  # ]:          0 :             pView->SdrEndTextEdit();
     227                 :            :         }
     228                 :            :     }
     229                 :            : 
     230 [ #  # ][ #  # ]:          0 :     return(bOK);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     231                 :            : }
     232                 :            : 
     233                 :          0 : long LayerTabBar::AllowRenaming()
     234                 :            : {
     235                 :          0 :     sal_Bool bOK = sal_True;
     236                 :            : 
     237                 :            :     // Ueberpruefung auf schon vorhandene Namen
     238                 :          0 :     ::sd::View* pView = pDrViewSh->GetView();
     239                 :          0 :     SdDrawDocument& rDoc = pView->GetDoc();
     240         [ #  # ]:          0 :     String aLayerName = pView->GetActiveLayer();
     241                 :          0 :     SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
     242         [ #  # ]:          0 :     String aNewName( GetEditText() );
     243                 :            : 
     244 [ #  # ][ #  # ]:          0 :     if ( aNewName.Len() == 0 ||
         [ #  # ][ #  # ]
     245 [ #  # ][ #  # ]:          0 :         (rLayerAdmin.GetLayer( aNewName, sal_False ) && aLayerName != aNewName) )
     246                 :            :     {
     247                 :            :         // Name ist schon vorhanden
     248 [ #  # ][ #  # ]:          0 :         WarningBox aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ),
     249 [ #  # ][ #  # ]:          0 :                                 String(SdResId( STR_WARN_NAME_DUPLICATE ) ) );
         [ #  # ][ #  # ]
     250         [ #  # ]:          0 :         aWarningBox.Execute();
     251         [ #  # ]:          0 :         bOK = sal_False;
     252                 :            :     }
     253                 :            : 
     254         [ #  # ]:          0 :     if (bOK)
     255                 :            :     {
     256 [ #  # ][ #  # ]:          0 :         String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
     257 [ #  # ][ #  # ]:          0 :         String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
     258 [ #  # ][ #  # ]:          0 :         String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
     259 [ #  # ][ #  # ]:          0 :         String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
     260 [ #  # ][ #  # ]:          0 :         String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
     261                 :            : 
     262 [ #  # ][ #  # ]:          0 :         if ( aNewName == aLayoutLayer       || aNewName == aControlsLayer  ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     263         [ #  # ]:          0 :              aNewName == aMeasureLinesLayer ||
     264 [ #  # ][ #  # ]:          0 :              aNewName == aBackgroundLayer   || aNewName == aBackgroundObjLayer )
     265                 :            :         {
     266                 :            :             // Diese Namen duerfen nicht vergeben werden
     267                 :          0 :             bOK = sal_False;
     268 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
                 [ #  # ]
     269                 :            :     }
     270                 :            : 
     271 [ #  # ][ #  # ]:          0 :     return(bOK);
     272                 :            : }
     273                 :            : 
     274                 :          0 : void LayerTabBar::EndRenaming()
     275                 :            : {
     276         [ #  # ]:          0 :     if( !IsEditModeCanceled() )
     277                 :            :     {
     278                 :          0 :         ::sd::View* pView = pDrViewSh->GetView();
     279 [ #  # ][ #  # ]:          0 :         DrawView* pDrView = PTR_CAST( DrawView, pView );
         [ #  # ][ #  # ]
     280                 :            : 
     281                 :          0 :         SdDrawDocument& rDoc = pView->GetDoc();
     282         [ #  # ]:          0 :         String aLayerName = pView->GetActiveLayer();
     283                 :          0 :         SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
     284         [ #  # ]:          0 :         SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, sal_False);
     285                 :            : 
     286         [ #  # ]:          0 :         if (pLayer)
     287                 :            :         {
     288         [ #  # ]:          0 :             String aNewName( GetEditText() );
     289                 :            : 
     290                 :            :             DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" );
     291         [ #  # ]:          0 :             if( pDrView )
     292                 :            :             {
     293         [ #  # ]:          0 :                 ::svl::IUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager();
     294                 :            :                 SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction(
     295                 :            :                     &rDoc,
     296                 :            :                     pLayer,
     297                 :            :                     aLayerName,
     298                 :            :                     pLayer->GetTitle(),
     299                 :            :                     pLayer->GetDescription(),
     300         [ #  # ]:          0 :                     pDrView->IsLayerVisible(aLayerName),
     301         [ #  # ]:          0 :                     pDrView->IsLayerLocked(aLayerName),
     302         [ #  # ]:          0 :                     pDrView->IsLayerPrintable(aLayerName),
     303                 :            :                     aNewName,
     304                 :            :                     pLayer->GetTitle(),
     305                 :            :                     pLayer->GetDescription(),
     306         [ #  # ]:          0 :                     pDrView->IsLayerVisible(aLayerName),
     307         [ #  # ]:          0 :                     pDrView->IsLayerLocked(aLayerName),
     308         [ #  # ]:          0 :                     pDrView->IsLayerPrintable(aLayerName)
     309 [ #  # ][ #  # ]:          0 :                     );
     310         [ #  # ]:          0 :                 pManager->AddUndoAction( pAction );
     311                 :            :             }
     312                 :            : 
     313                 :            :             // Zuerst View benachrichtigen, da innerhalb von SetName() schon
     314                 :            :             // ResetActualLayer() gerufen wird und an der View der Layer dann
     315                 :            :             // schon bekannt sein muss.
     316         [ #  # ]:          0 :             pView->SetActiveLayer(aNewName);
     317         [ #  # ]:          0 :             pLayer->SetName(aNewName);
     318 [ #  # ][ #  # ]:          0 :             rDoc.SetChanged(sal_True);
     319         [ #  # ]:          0 :         }
     320                 :            :     }
     321                 :          0 : }
     322                 :            : 
     323                 :          0 : void LayerTabBar::ActivatePage()
     324                 :            : {
     325         [ #  # ]:          0 :     if ( /*IsInSwitching*/ 1 && pDrViewSh!=NULL)
     326                 :            :     {
     327                 :            : 
     328                 :          0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     329                 :          0 :         pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
     330                 :            :     }
     331                 :          0 : }
     332                 :            : 
     333                 :            : 
     334                 :            : 
     335                 :            : 
     336                 :          0 : void LayerTabBar::SendActivatePageEvent (void)
     337                 :            : {
     338                 :            :     CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
     339                 :          0 :         reinterpret_cast<void*>(GetCurPageId()));
     340                 :          0 : }
     341                 :            : 
     342                 :            : 
     343                 :            : 
     344                 :            : 
     345                 :          0 : void LayerTabBar::SendDeactivatePageEvent (void)
     346                 :            : {
     347                 :            :     CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
     348                 :          0 :         reinterpret_cast<void*>(GetCurPageId()));
     349                 :          0 : }
     350                 :            : 
     351                 :            : } // end of namespace sd
     352                 :            : 
     353                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10