LCOV - code coverage report
Current view: top level - sd/source/ui/view - tabcontr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 10 151 6.6 %
Date: 2014-11-03 Functions: 4 25 16.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 "TabControl.hxx"
      21             : 
      22             : #include <sfx2/viewfrm.hxx>
      23             : #include <svx/svdlayer.hxx>
      24             : #include <svx/svdpagv.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : 
      27             : #include "sdattr.hxx"
      28             : #include "sdmod.hxx"
      29             : #include "app.hrc"
      30             : #include "glob.hrc"
      31             : #include "res_bmp.hrc"
      32             : #include "DrawViewShell.hxx"
      33             : #include "GraphicViewShell.hxx"
      34             : #include "helpids.h"
      35             : #include "View.hxx"
      36             : #include "sdpage.hxx"
      37             : #include "drawdoc.hxx"
      38             : #include "Window.hxx"
      39             : #include "unmodpg.hxx"
      40             : #include "DrawDocShell.hxx"
      41             : #include "sdresid.hxx"
      42             : 
      43             : namespace sd {
      44             : 
      45             : // - SdTabControl::SdPageObjsTransferable -
      46             : 
      47           0 : TabControl::TabControlTransferable::~TabControlTransferable()
      48             : {
      49           0 : }
      50             : 
      51           0 : void TabControl::TabControlTransferable::AddSupportedFormats()
      52             : {
      53           0 :     AddFormat( SOT_FORMATSTR_ID_STARDRAW_TABBAR );
      54           0 : }
      55             : 
      56           0 : bool TabControl::TabControlTransferable::GetData( const css::datatransfer::DataFlavor& /*rFlavor*/, const OUString& /*rDestDoc*/ )
      57             : {
      58           0 :     return false;
      59             : }
      60             : 
      61           0 : void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction )
      62             : {
      63           0 :     mrParent.DragFinished( nDropAction );
      64           0 : }
      65             : 
      66         212 : TabControl::TabControl(DrawViewShell* pViewSh, vcl::Window* pParent) :
      67             :     TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE | WB_DRAG) ),
      68             :     DragSourceHelper( this ),
      69             :     DropTargetHelper( this ),
      70             :     RrePageID(1),
      71             :     pDrViewSh(pViewSh),
      72         212 :     bInternalMove(false)
      73             : {
      74         212 :     EnableEditMode();
      75         212 :     SetSizePixel(Size(0, 0));
      76         212 :     SetMaxPageWidth( 150 );
      77         212 :     SetHelpId( HID_SD_TABBAR_PAGES );
      78         212 : }
      79             : 
      80         212 : TabControl::~TabControl()
      81             : {
      82         212 : }
      83             : 
      84           0 : void TabControl::Select()
      85             : {
      86           0 :     SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
      87             :     pDispatcher->Execute(SID_SWITCHPAGE, SfxCallMode::ASYNCHRON |
      88           0 :                             SfxCallMode::RECORD);
      89           0 : }
      90             : 
      91           0 : void  TabControl::MouseButtonDown(const MouseEvent& rMEvt)
      92             : {
      93           0 :     if (rMEvt.IsLeft()
      94           0 :         && !rMEvt.IsMod1()
      95           0 :         && !rMEvt.IsMod2()
      96           0 :         && !rMEvt.IsShift())
      97             :     {
      98           0 :         Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
      99           0 :         sal_uInt16 aPageId = GetPageId(aPos);
     100             : 
     101             :         //initialize
     102           0 :         if(RrePageID!=aPageId)
     103           0 :             pDrViewSh->FreshNavigatrEntry();
     104           0 :         RrePageID=aPageId;
     105           0 :         if (aPageId == 0)
     106             :         {
     107           0 :             SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     108             : 
     109             :             pDispatcher->Execute(SID_INSERTPAGE_QUICK,
     110           0 :                                 SfxCallMode::SYNCHRON | SfxCallMode::RECORD);
     111             :         }
     112             :     }
     113             : 
     114             :     // A single left click with pressed control key on a tab page first
     115             :     // switches to that page before the usual handling (copying with drag
     116             :     // and drop) takes place.
     117           0 :     else if (rMEvt.IsLeft() && rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift())
     118             :     {
     119           0 :         pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
     120             :     }
     121             : 
     122             :     // When only the right button is pressed then first process a
     123             :     // synthesized left button click to make the page the current one
     124             :     // whose tab has been clicked.  When then the actual right button
     125             :     // click is processed the resulting context menu relates to the
     126             :     // now current page.
     127           0 :     if (rMEvt.IsRight() && ! rMEvt.IsLeft())
     128             :     {
     129             :         MouseEvent aSyntheticEvent (
     130           0 :             rMEvt.GetPosPixel(),
     131           0 :             rMEvt.GetClicks(),
     132           0 :             rMEvt.GetMode(),
     133             :             MOUSE_LEFT,
     134           0 :             rMEvt.GetModifier());
     135           0 :         TabBar::MouseButtonDown(aSyntheticEvent);
     136             :     }
     137             : 
     138           0 :     TabBar::MouseButtonDown(rMEvt);
     139           0 : }
     140             : 
     141           0 : void TabControl::DoubleClick()
     142             : {
     143           0 :     if (GetCurPageId() != 0)
     144             :     {
     145           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     146             :         pDispatcher->Execute( SID_MODIFYPAGE,
     147           0 :                         SfxCallMode::SYNCHRON | SfxCallMode::RECORD );
     148             :     }
     149           0 : }
     150             : 
     151           0 : void TabControl::StartDrag( sal_Int8, const Point& )
     152             : {
     153           0 :     bInternalMove = true;
     154             : 
     155             :     // object is delete by reference mechanismn
     156           0 :     ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE );
     157           0 : }
     158             : 
     159           0 : void TabControl::DragFinished( sal_Int8 )
     160             : {
     161           0 :     bInternalMove = false;
     162           0 : }
     163             : 
     164           0 : sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
     165             : {
     166           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     167             : 
     168           0 :     if( rEvt.mbLeaving )
     169           0 :         EndSwitchPage();
     170             : 
     171           0 :     if( !pDrViewSh->GetDocSh()->IsReadOnly() )
     172             :     {
     173           0 :         SdDrawDocument* pDoc = pDrViewSh->GetDoc();
     174           0 :         Point           aPos( rEvt.maPosPixel );
     175             : 
     176           0 :         if( bInternalMove )
     177             :         {
     178           0 :             if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
     179           0 :                 HideDropPos();
     180             :             else
     181             :             {
     182           0 :                 ShowDropPos( aPos );
     183           0 :                 nRet = rEvt.mnAction;
     184             :             }
     185             :         }
     186             :         else
     187             :         {
     188           0 :             HideDropPos();
     189             : 
     190           0 :             sal_Int32 nPageId = GetPageId( aPos ) - 1;
     191             : 
     192           0 :             if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
     193             :             {
     194           0 :                 nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
     195           0 :                 SwitchPage( aPos );
     196             :             }
     197             :         }
     198             :     }
     199             : 
     200           0 :     return nRet;
     201             : }
     202             : 
     203           0 : sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
     204             : {
     205           0 :     SdDrawDocument* pDoc = pDrViewSh->GetDoc();
     206           0 :     Point           aPos( rEvt.maPosPixel );
     207           0 :     sal_Int8        nRet = DND_ACTION_NONE;
     208             : 
     209           0 :     if( bInternalMove )
     210             :     {
     211           0 :         sal_uInt16 nPageId = ShowDropPos( aPos ) - 1;
     212             : 
     213           0 :         switch (rEvt.mnAction)
     214             :         {
     215             :             case DND_ACTION_MOVE:
     216           0 :                 if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( nPageId ) )
     217             :                 {
     218           0 :                     SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     219           0 :                     pDispatcher->Execute(SID_SWITCHPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
     220             :                 }
     221           0 :                 break;
     222             : 
     223             :             case DND_ACTION_COPY:
     224             :             {
     225             :                 // Copying the selected page to the place that rEvt points
     226             :                 // takes place in three steps:
     227             :                 // 1. Create a copy of the selected page.  This copy will
     228             :                 // lie directly behind the selected page.
     229             :                 // 2. Move the copy to the desired place.
     230             :                 // 3. Select the copy.
     231           0 :                 if (pDrViewSh->IsSwitchPageAllowed())
     232             :                 {
     233             :                     // 1. Create a copy.
     234           0 :                     sal_uInt16 nPageNumOfCopy = pDoc->DuplicatePage (GetCurPageId() - 1);
     235             :                     // 2. Move page.  For this first switch to the copy:
     236             :                     // MovePages operates on the currently selected page(s).
     237           0 :                     pDrViewSh->SwitchPage (nPageNumOfCopy);
     238             :                     // Adapt target page id when necessary, i.e. page copy
     239             :                     // has been inserted in front of the target page.
     240           0 :                     sal_uInt16 nPageNum = nPageId;
     241           0 :                     if ((nPageNumOfCopy <= nPageNum) && (nPageNum != (sal_uInt16)-1))
     242           0 :                         nPageNum += 1;
     243           0 :                     if (pDoc->MovePages(nPageNum))
     244             :                     {
     245             :                         // 3. Switch to the copy that has been moved to its
     246             :                         // final destination.  Use an asynchron slot call to
     247             :                         // be executed after the still pending ones.
     248           0 :                         if (nPageNumOfCopy >= nPageNum || (nPageNum == (sal_uInt16)-1))
     249           0 :                             nPageNum += 1;
     250           0 :                         SetCurPageId (GetPageId(nPageNum));
     251           0 :                         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     252             :                         pDispatcher->Execute(SID_SWITCHPAGE,
     253           0 :                             SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
     254             :                     }
     255             :                 }
     256             : 
     257           0 :                 break;
     258             :             }
     259             :         }
     260             : 
     261           0 :         nRet = rEvt.mnAction;
     262             :     }
     263             :     else
     264             :     {
     265           0 :         sal_Int32 nPageId = GetPageId( aPos ) - 1;
     266             : 
     267           0 :         if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
     268             :         {
     269           0 :             nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
     270             :         }
     271             :     }
     272             : 
     273           0 :     HideDropPos();
     274           0 :     EndSwitchPage();
     275             : 
     276           0 :     return nRet;
     277             : }
     278             : 
     279           0 : void TabControl::Command(const CommandEvent& rCEvt)
     280             : {
     281           0 :     sal_uInt16 nCmd = rCEvt.GetCommand();
     282             : 
     283           0 :     if ( nCmd == COMMAND_CONTEXTMENU )
     284             :     {
     285           0 :         bool bGraphicShell = pDrViewSh->ISA(GraphicViewShell);
     286             :         sal_uInt16 nResId = bGraphicShell ? RID_GRAPHIC_PAGETAB_POPUP :
     287           0 :                                         RID_DRAW_PAGETAB_POPUP;
     288           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     289           0 :         pDispatcher->ExecutePopup( SdResId( nResId ) );
     290             :     }
     291           0 : }
     292             : 
     293           0 : bool TabControl::StartRenaming()
     294             : {
     295           0 :     bool bOK = false;
     296             : 
     297           0 :     if (pDrViewSh->GetPageKind() == PK_STANDARD)
     298             :     {
     299           0 :         bOK = true;
     300             : 
     301           0 :         ::sd::View* pView = pDrViewSh->GetView();
     302             : 
     303           0 :         if ( pView->IsTextEdit() )
     304           0 :             pView->SdrEndTextEdit();
     305             :     }
     306             : 
     307           0 :     return bOK;
     308             : }
     309             : 
     310           0 : TabBarAllowRenamingReturnCode TabControl::AllowRenaming()
     311             : {
     312           0 :     bool bOK = true;
     313             : 
     314           0 :     OUString aNewName( GetEditText() );
     315           0 :     OUString aCompareName( GetPageText( GetEditPageId() ) );
     316             : 
     317           0 :     if( aCompareName != aNewName )
     318             :     {
     319             :         // rename page
     320           0 :         if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
     321             :         {
     322           0 :             SetEditText( aNewName );
     323           0 :             EndRenaming();
     324             :         }
     325             :         else
     326             :         {
     327           0 :             bOK = false;
     328             :         }
     329             :     }
     330           0 :     return bOK ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO;
     331             : }
     332             : 
     333           0 : void TabControl::EndRenaming()
     334             : {
     335           0 :     if( !IsEditModeCanceled() )
     336           0 :         pDrViewSh->RenameSlide( GetEditPageId(), GetEditText() );
     337           0 : }
     338             : 
     339           0 : void TabControl::ActivatePage()
     340             : {
     341           0 :     if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
     342             :     {
     343           0 :         SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
     344             :         pDispatcher->Execute(SID_SWITCHPAGE,
     345           0 :                              SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
     346             :     }
     347           0 : }
     348             : 
     349           0 : bool TabControl::DeactivatePage()
     350             : {
     351           0 :     return pDrViewSh->IsSwitchPageAllowed();
     352             : }
     353             : 
     354           0 : void TabControl::SendActivatePageEvent (void)
     355             : {
     356             :     CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
     357           0 :         reinterpret_cast<void*>(GetCurPageId()));
     358           0 : }
     359             : 
     360           0 : void TabControl::SendDeactivatePageEvent (void)
     361             : {
     362             :     CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
     363           0 :         reinterpret_cast<void*>(GetCurPageId()));
     364           0 : }
     365             : 
     366         114 : } // end of namespace sd
     367             : 
     368             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10