LCOV - code coverage report
Current view: top level - sc/source/ui/view - tabcont.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 74 295 25.1 %
Date: 2012-08-25 Functions: 8 21 38.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 92 440 20.9 %

           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                 :            : #include <sfx2/viewfrm.hxx>
      30                 :            : #include <sfx2/dispatch.hxx>
      31                 :            : #include <sfx2/docfile.hxx>
      32                 :            : #include <tools/urlobj.hxx>
      33                 :            : #include <vcl/svapp.hxx>
      34                 :            : #include "tabcont.hxx"
      35                 :            : #include "tabvwsh.hxx"
      36                 :            : #include "docsh.hxx"
      37                 :            : #include "scmod.hxx"
      38                 :            : #include "scresid.hxx"
      39                 :            : #include "sc.hrc"
      40                 :            : #include "globstr.hrc"
      41                 :            : #include "transobj.hxx"
      42                 :            : #include "clipparam.hxx"
      43                 :            : #include "dragdata.hxx"
      44                 :            : #include "markdata.hxx"
      45                 :            : 
      46                 :            : // STATIC DATA -----------------------------------------------------------
      47                 :            : 
      48                 :            : //==================================================================
      49                 :            : 
      50                 :        229 : ScTabControl::ScTabControl( Window* pParent, ScViewData* pData ) :
      51                 :            :     TabBar( pParent,
      52                 :            :             WinBits(WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_RANGESELECT |
      53                 :            :                     WB_MULTISELECT | WB_DRAG | WB_SIZEABLE) ),
      54                 :            :             DropTargetHelper( this ),
      55                 :            :             DragSourceHelper( this ),
      56                 :            :             pViewData( pData ),
      57                 :            :             nMouseClickPageId( TabBar::PAGE_NOT_FOUND ),
      58                 :            :             nSelPageIdByMouse( TabBar::PAGE_NOT_FOUND ),
      59 [ +  - ][ +  - ]:        229 :             bErrorShown( false )
      60                 :            : {
      61         [ +  - ]:        229 :     ScDocument* pDoc = pViewData->GetDocument();
      62                 :            : 
      63                 :        229 :     rtl::OUString aString;
      64                 :        229 :     Color aTabBgColor;
      65         [ +  - ]:        229 :     SCTAB nCount = pDoc->GetTableCount();
      66         [ +  + ]:        506 :     for (SCTAB i=0; i<nCount; i++)
      67                 :            :     {
      68 [ +  - ][ +  - ]:        277 :         if (pDoc->IsVisible(i))
      69                 :            :         {
      70 [ +  - ][ +  - ]:        277 :             if (pDoc->GetName(i,aString))
      71                 :            :             {
      72 [ +  - ][ -  + ]:        277 :                 if ( pDoc->IsScenario(i) )
      73 [ #  # ][ #  # ]:          0 :                     InsertPage( static_cast<sal_uInt16>(i)+1, aString, TPB_SPECIAL );
                 [ #  # ]
      74                 :            :                 else
      75 [ +  - ][ +  - ]:        277 :                     InsertPage( static_cast<sal_uInt16>(i)+1, aString );
                 [ +  - ]
      76 [ +  - ][ -  + ]:        277 :                 if ( !pDoc->IsDefaultTabBgColor(i) )
      77                 :            :                 {
      78         [ #  # ]:          0 :                     aTabBgColor = pDoc->GetTabBgColor(i);
      79         [ #  # ]:          0 :                     SetTabBgColor( static_cast<sal_uInt16>(i)+1, aTabBgColor );
      80                 :            :                 }
      81                 :            :             }
      82                 :            :         }
      83                 :            :     }
      84                 :            : 
      85         [ +  - ]:        229 :     SetCurPageId( static_cast<sal_uInt16>(pViewData->GetTabNo()) + 1 );
      86                 :            : 
      87         [ +  - ]:        229 :     SetSizePixel( Size(SC_TABBAR_DEFWIDTH, 0) );
      88                 :            : 
      89 [ +  - ][ +  - ]:        229 :     SetSplitHdl( LINK( pViewData->GetView(), ScTabView, TabBarResize ) );
      90                 :            : 
      91                 :        229 :     EnableEditMode();
      92         [ +  - ]:        229 :     UpdateInputContext();
      93                 :        229 : }
      94                 :            : 
      95 [ +  - ][ +  - ]:        225 : ScTabControl::~ScTabControl()
      96                 :            : {
      97         [ -  + ]:        450 : }
      98                 :            : 
      99                 :        842 : sal_uInt16 ScTabControl::GetMaxId() const
     100                 :            : {
     101                 :        842 :     sal_uInt16 nVisCnt = GetPageCount();
     102         [ +  - ]:        842 :     if (nVisCnt)
     103                 :        842 :         return GetPageId(nVisCnt-1);
     104                 :            : 
     105                 :        842 :     return 0;
     106                 :            : }
     107                 :            : 
     108                 :          0 : SCTAB ScTabControl::GetPrivatDropPos(const Point& rPos )
     109                 :            : {
     110                 :          0 :     sal_uInt16 nPos = ShowDropPos(rPos);
     111                 :            : 
     112                 :          0 :     SCTAB nRealPos = static_cast<SCTAB>(nPos);
     113                 :            : 
     114         [ #  # ]:          0 :     if(nPos !=0 )
     115                 :            :     {
     116                 :          0 :         ScDocument* pDoc = pViewData->GetDocument();
     117                 :            : 
     118                 :          0 :         SCTAB nCount = pDoc->GetTableCount();
     119                 :            : 
     120                 :          0 :         sal_uInt16 nViewPos=0;
     121                 :          0 :         nRealPos = nCount;
     122         [ #  # ]:          0 :         for (SCTAB i=0; i<nCount; i++)
     123                 :            :         {
     124         [ #  # ]:          0 :             if (pDoc->IsVisible(i))
     125                 :            :             {
     126                 :          0 :                 nViewPos++;
     127         [ #  # ]:          0 :                 if(nViewPos==nPos)
     128                 :            :                 {
     129                 :            :                     SCTAB j;
     130         [ #  # ]:          0 :                     for (j=i+1; j<nCount; j++)
     131                 :            :                     {
     132         [ #  # ]:          0 :                         if (pDoc->IsVisible(j))
     133                 :            :                         {
     134                 :          0 :                             break;
     135                 :            :                         }
     136                 :            :                     }
     137                 :          0 :                     nRealPos =j;
     138                 :          0 :                     break;
     139                 :            :                 }
     140                 :            :             }
     141                 :            :         }
     142                 :            :     }
     143                 :          0 :     return nRealPos ;
     144                 :            : }
     145                 :            : 
     146                 :          0 : void ScTabControl::MouseButtonDown( const MouseEvent& rMEvt )
     147                 :            : {
     148                 :          0 :     ScModule* pScMod = SC_MOD();
     149 [ #  # ][ #  # ]:          0 :     if ( !pScMod->IsModalMode() && !pScMod->IsFormulaMode() && !IsInEditMode() )
         [ #  # ][ #  # ]
     150                 :            :     {
     151                 :            :         //  View aktivieren
     152                 :          0 :         pViewData->GetViewShell()->SetActive();         // Appear und SetViewFrame
     153                 :          0 :         pViewData->GetView()->ActiveGrabFocus();
     154                 :            :     }
     155                 :            : 
     156                 :            :     /*  Click into free area -> insert new sheet (like in Draw).
     157                 :            :         Needing clean left click without modifiers (may be context menu).
     158                 :            :         Remember clicks to all pages, to be able to move mouse pointer later. */
     159 [ #  # ][ #  # ]:          0 :     if( rMEvt.IsLeft() && (rMEvt.GetModifier() == 0) )
                 [ #  # ]
     160                 :          0 :         nMouseClickPageId = GetPageId( rMEvt.GetPosPixel(), true );
     161                 :            :     else
     162                 :          0 :         nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
     163                 :            : 
     164                 :          0 :     TabBar::MouseButtonDown( rMEvt );
     165                 :          0 : }
     166                 :            : 
     167                 :          0 : void ScTabControl::MouseButtonUp( const MouseEvent& rMEvt )
     168                 :            : {
     169         [ #  # ]:          0 :     Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
     170                 :            : 
     171                 :            :     // mouse button down and up on same page?
     172 [ #  # ][ #  # ]:          0 :     if( nMouseClickPageId != GetPageId( aPos, true ) )
     173                 :          0 :         nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
     174                 :            : 
     175         [ #  # ]:          0 :     if (nMouseClickPageId == TabBar::INSERT_TAB_POS)
     176                 :            :     {
     177                 :            :         // Insert a new sheet at the right end, with default name.
     178         [ #  # ]:          0 :         ScDocument* pDoc = pViewData->GetDocument();
     179 [ #  # ][ #  # ]:          0 :         if (!pDoc->IsDocEditable())
     180                 :            :             return;
     181                 :          0 :         rtl::OUString aName;
     182         [ #  # ]:          0 :         pDoc->CreateValidTabName(aName);
     183         [ #  # ]:          0 :         SCTAB nTabCount = pDoc->GetTableCount();
     184 [ #  # ][ #  # ]:          0 :         pViewData->GetViewShell()->InsertTable(aName, nTabCount);
                 [ #  # ]
     185                 :          0 :         return;
     186                 :            :     }
     187                 :            : 
     188 [ #  # ][ #  # ]:          0 :     if ( rMEvt.GetClicks() == 2 && rMEvt.IsLeft() && nMouseClickPageId != 0 && nMouseClickPageId != TAB_PAGE_NOTFOUND )
         [ #  # ][ #  # ]
                 [ #  # ]
     189                 :            :     {
     190                 :          0 :         SfxDispatcher* pDispatcher = pViewData->GetViewShell()->GetViewFrame()->GetDispatcher();
     191         [ #  # ]:          0 :         pDispatcher->Execute( FID_TAB_MENU_RENAME, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
     192                 :            :         return;
     193                 :            :     }
     194                 :            : 
     195         [ #  # ]:          0 :     if( nMouseClickPageId == 0 )
     196                 :            :     {
     197                 :            :         // Click in the area next to the existing tabs:
     198                 :            :         // #i70320# if several sheets are selected, deselect all ecxept the current sheet,
     199                 :            :         // otherwise add new sheet
     200 [ #  # ][ #  # ]:          0 :         sal_uInt16 nSlot = ( GetSelectPageCount() > 1 ) ? FID_TAB_DESELECTALL : FID_INS_TABLE;
     201                 :          0 :         SfxDispatcher* pDispatcher = pViewData->GetViewShell()->GetViewFrame()->GetDispatcher();
     202         [ #  # ]:          0 :         pDispatcher->Execute( nSlot, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
     203                 :            :         // forget page ID, to be really sure that the dialog is not called twice
     204                 :          0 :         nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
     205                 :            :     }
     206                 :            : 
     207         [ #  # ]:          0 :     TabBar::MouseButtonUp( rMEvt );
     208                 :            : }
     209                 :            : 
     210                 :          0 : void ScTabControl::Select()
     211                 :            : {
     212                 :            :     /*  Remember last clicked page ID. */
     213                 :          0 :     nSelPageIdByMouse = nMouseClickPageId;
     214                 :            :     /*  Reset nMouseClickPageId, so that next Select() call may invalidate
     215                 :            :         nSelPageIdByMouse (i.e. if called from keyboard). */
     216                 :          0 :     nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
     217                 :            : 
     218                 :          0 :     ScModule* pScMod = SC_MOD();
     219                 :          0 :     ScDocument* pDoc = pViewData->GetDocument();
     220                 :          0 :     ScMarkData& rMark = pViewData->GetMarkData();
     221                 :          0 :     SCTAB nCount = pDoc->GetTableCount();
     222                 :            :     SCTAB i;
     223                 :            : 
     224         [ #  # ]:          0 :     if ( pScMod->IsTableLocked() )      // darf jetzt nicht umgeschaltet werden ?
     225                 :            :     {
     226                 :            :         //  den alten Zustand des TabControls wiederherstellen:
     227                 :            : 
     228         [ #  # ]:          0 :         for (i=0; i<nCount; i++)
     229                 :          0 :             SelectPage( static_cast<sal_uInt16>(i)+1, rMark.GetTableSelect(i) );
     230                 :          0 :         SetCurPageId( static_cast<sal_uInt16>(pViewData->GetTabNo()) + 1 );
     231                 :            : 
     232                 :          0 :         return;
     233                 :            :     }
     234                 :            : 
     235                 :          0 :     sal_uInt16 nCurId = GetCurPageId();
     236         [ #  # ]:          0 :     if (!nCurId) return;            // kann vorkommen, wenn bei Excel-Import alles versteckt ist
     237                 :          0 :     sal_uInt16 nPage = nCurId - 1;
     238                 :            : 
     239                 :            :     // OLE-inplace deaktivieren
     240         [ #  # ]:          0 :     if ( nPage != static_cast<sal_uInt16>(pViewData->GetTabNo()) )
     241                 :          0 :         pViewData->GetView()->DrawMarkListHasChanged();
     242                 :            : 
     243                 :            :     //  InputEnterHandler nur wenn nicht Referenzeingabe
     244                 :            : 
     245                 :          0 :     sal_Bool bRefMode = pScMod->IsFormulaMode();
     246         [ #  # ]:          0 :     if (!bRefMode)
     247                 :          0 :         pScMod->InputEnterHandler();
     248                 :            : 
     249         [ #  # ]:          0 :     for (i=0; i<nCount; i++)
     250                 :          0 :         rMark.SelectTable( i, IsPageSelected(static_cast<sal_uInt16>(i)+1) );
     251                 :            : 
     252                 :          0 :     SfxDispatcher& rDisp = pViewData->GetDispatcher();
     253         [ #  # ]:          0 :     if (rDisp.IsLocked())
     254                 :          0 :         pViewData->GetView()->SetTabNo( static_cast<SCTAB>(nPage) );
     255                 :            :     else
     256                 :            :     {
     257                 :            :         //  Tabelle fuer Basic ist 1-basiert
     258         [ #  # ]:          0 :         SfxUInt16Item aItem( SID_CURRENTTAB, nPage + 1 );
     259                 :            :         rDisp.Execute( SID_CURRENTTAB, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
     260 [ #  # ][ #  # ]:          0 :                                 &aItem, (void*) NULL );
     261                 :            :     }
     262                 :            : 
     263                 :          0 :     SfxBindings& rBind = pViewData->GetBindings();
     264                 :          0 :     rBind.Invalidate( FID_FILL_TAB );
     265                 :          0 :     rBind.Invalidate( FID_TAB_DESELECTALL );
     266                 :            : 
     267                 :          0 :     rBind.Invalidate( FID_INS_TABLE );
     268                 :          0 :     rBind.Invalidate( FID_TAB_APPEND );
     269                 :          0 :     rBind.Invalidate( FID_TAB_MOVE );
     270                 :          0 :     rBind.Invalidate( FID_TAB_RENAME );
     271                 :          0 :     rBind.Invalidate( FID_DELETE_TABLE );
     272                 :          0 :     rBind.Invalidate( FID_TABLE_SHOW );
     273                 :          0 :     rBind.Invalidate( FID_TABLE_HIDE );
     274                 :          0 :     rBind.Invalidate( FID_TAB_SET_TAB_BG_COLOR );
     275                 :            : 
     276                 :            :         //  SetReference nur wenn der Konsolidieren-Dialog offen ist
     277                 :            :         //  (fuer Referenzen ueber mehrere Tabellen)
     278                 :            :         //  bei anderen gibt das nur unnoetiges Gezappel
     279                 :            : 
     280 [ #  # ][ #  # ]:          0 :     if ( bRefMode && pViewData->GetRefType() == SC_REFTYPE_REF )
                 [ #  # ]
     281         [ #  # ]:          0 :         if ( pViewData->GetViewShell()->GetViewFrame()->HasChildWindow(SID_OPENDLG_CONSOLIDATE) )
     282                 :            :         {
     283                 :            :             ScRange aRange(
     284                 :          0 :                     pViewData->GetRefStartX(), pViewData->GetRefStartY(), pViewData->GetRefStartZ(),
     285                 :          0 :                     pViewData->GetRefEndX(), pViewData->GetRefEndY(), pViewData->GetRefEndZ() );
     286         [ #  # ]:          0 :             pScMod->SetReference( aRange, pDoc, &rMark );
     287         [ #  # ]:          0 :             pScMod->EndReference();                     // wegen Auto-Hide
     288                 :            :         }
     289                 :            : }
     290                 :            : 
     291                 :        761 : void ScTabControl::UpdateInputContext()
     292                 :            : {
     293                 :        761 :     ScDocument* pDoc = pViewData->GetDocument();
     294                 :        761 :     WinBits nStyle = GetStyle();
     295         [ -  + ]:        761 :     if (pDoc->GetDocumentShell()->IsReadOnly())
     296                 :            :         // no insert sheet tab for readonly doc.
     297                 :          0 :         SetStyle((nStyle & ~WB_INSERTTAB));
     298                 :            :     else
     299                 :        761 :         SetStyle((nStyle | WB_INSERTTAB));
     300                 :        761 : }
     301                 :            : 
     302                 :        842 : void ScTabControl::UpdateStatus()
     303                 :            : {
     304         [ +  - ]:        842 :     ScDocument* pDoc = pViewData->GetDocument();
     305         [ +  - ]:        842 :     ScMarkData& rMark = pViewData->GetMarkData();
     306                 :        842 :     sal_Bool bActive = pViewData->IsActive();
     307                 :            : 
     308         [ +  - ]:        842 :     SCTAB nCount = pDoc->GetTableCount();
     309                 :            :     SCTAB i;
     310                 :        842 :     rtl::OUString aString;
     311         [ +  - ]:        842 :     SCTAB nMaxCnt = Max( nCount, static_cast<SCTAB>(GetMaxId()) );
     312                 :        842 :     Color aTabBgColor;
     313                 :            : 
     314                 :        842 :     sal_Bool bModified = false;                                     // Tabellen-Namen
     315 [ +  + ][ +  + ]:       1937 :     for (i=0; i<nMaxCnt && !bModified; i++)
                 [ +  + ]
     316                 :            :     {
     317 [ +  - ][ +  + ]:       1095 :         if (pDoc->IsVisible(i))
     318                 :            :         {
     319         [ +  - ]:       1089 :             pDoc->GetName(i,aString);
     320         [ +  - ]:       1089 :             aTabBgColor = pDoc->GetTabBgColor(i);
     321                 :            :         }
     322                 :            :         else
     323                 :            :         {
     324                 :          6 :             aString = rtl::OUString();
     325                 :            :         }
     326                 :            : 
     327 [ +  - ][ +  - ]:       1095 :         if ( !aString.equals(GetPageText(static_cast<sal_uInt16>(i)+1)) || (GetTabBgColor(static_cast<sal_uInt16>(i)+1) != aTabBgColor) )
         [ +  + ][ +  - ]
         [ -  + ][ +  + ]
         [ +  - ][ +  - ]
         [ +  - ][ +  +  
          #  #  #  #  #  
                      # ]
     328                 :         68 :             bModified = sal_True;
     329                 :            :     }
     330                 :            : 
     331         [ +  + ]:        842 :     if (bModified)
     332                 :            :     {
     333         [ +  - ]:         68 :         Clear();
     334         [ +  + ]:        195 :         for (i=0; i<nCount; i++)
     335                 :            :         {
     336 [ +  - ][ +  + ]:        127 :             if (pDoc->IsVisible(i))
     337                 :            :             {
     338 [ +  - ][ +  - ]:        125 :                 if (pDoc->GetName(i,aString))
     339                 :            :                 {
     340 [ +  - ][ -  + ]:        125 :                     if ( pDoc->IsScenario(i) )
     341 [ #  # ][ #  # ]:          0 :                         InsertPage( static_cast<sal_uInt16>(i)+1, aString, TPB_SPECIAL );
                 [ #  # ]
     342                 :            :                     else
     343 [ +  - ][ +  - ]:        125 :                         InsertPage( static_cast<sal_uInt16>(i)+1, aString );
                 [ +  - ]
     344 [ +  - ][ -  + ]:        125 :                     if ( !pDoc->IsDefaultTabBgColor(i) )
     345                 :            :                     {
     346         [ #  # ]:          0 :                         aTabBgColor = pDoc->GetTabBgColor(i);
     347         [ #  # ]:          0 :                         SetTabBgColor( static_cast<sal_uInt16>(i)+1, aTabBgColor );
     348                 :            :                     }
     349                 :            :                 }
     350                 :            :             }
     351                 :            :         }
     352                 :            :     }
     353         [ +  - ]:        842 :     SetCurPageId( static_cast<sal_uInt16>(pViewData->GetTabNo()) + 1 );
     354                 :            : 
     355         [ +  + ]:        842 :     if (bActive)
     356                 :            :     {
     357                 :        836 :         bModified = false;                                          // Selektion
     358 [ +  + ][ +  + ]:       1892 :         for (i=0; i<nMaxCnt && !bModified; i++)
                 [ +  + ]
     359 [ +  - ][ +  - ]:       1056 :             if ( rMark.GetTableSelect(i) != (bool) IsPageSelected(static_cast<sal_uInt16>(i)+1) )
                 [ +  + ]
     360                 :        260 :                 bModified = sal_True;
     361                 :            : 
     362                 :            :         // #i99576# the following loop is mis-optimized on unxsoli4 and the reason
     363                 :            :         // why this file is in NOOPTFILES.
     364         [ +  + ]:        836 :         if ( bModified )
     365         [ +  + ]:        586 :             for (i=0; i<nCount; i++)
     366 [ +  - ][ +  - ]:        326 :                 SelectPage( static_cast<sal_uInt16>(i)+1, rMark.GetTableSelect(i) );
     367                 :            :     }
     368                 :            :     else
     369                 :            :     {
     370                 :        842 :     }
     371                 :        842 : }
     372                 :            : 
     373                 :        682 : void ScTabControl::SetSheetLayoutRTL( sal_Bool bSheetRTL )
     374                 :            : {
     375                 :        682 :     SetEffectiveRTL( bSheetRTL );
     376                 :        682 :     nSelPageIdByMouse = TabBar::PAGE_NOT_FOUND;
     377                 :        682 : }
     378                 :            : 
     379                 :            : 
     380                 :          0 : void ScTabControl::Command( const CommandEvent& rCEvt )
     381                 :            : {
     382                 :          0 :     ScModule*       pScMod   = SC_MOD();
     383                 :          0 :     ScTabViewShell* pViewSh  = pViewData->GetViewShell();
     384 [ #  # ][ #  # ]:          0 :     sal_Bool            bDisable = pScMod->IsFormulaMode() || pScMod->IsModalMode();
     385                 :            : 
     386                 :            :     // ViewFrame erstmal aktivieren (Bug 19493):
     387                 :          0 :     pViewSh->SetActive();
     388                 :            : 
     389                 :          0 :     sal_uInt16 nCmd = rCEvt.GetCommand();
     390         [ #  # ]:          0 :     if ( nCmd == COMMAND_CONTEXTMENU )
     391                 :            :     {
     392         [ #  # ]:          0 :         if (!bDisable)
     393                 :            :         {
     394                 :            :             // #i18735# select the page that is under the mouse cursor
     395                 :            :             // if multiple tables are selected and the one under the cursor
     396                 :            :             // is not part of them then unselect them
     397                 :          0 :             sal_uInt16 nId = GetPageId( rCEvt.GetMousePosPixel() );
     398         [ #  # ]:          0 :             if (nId)
     399                 :            :             {
     400                 :          0 :                 sal_Bool bAlreadySelected = IsPageSelected( nId );
     401                 :            :                 //make the clicked page the current one
     402                 :          0 :                 SetCurPageId( nId );
     403                 :            :                 //change the selection when the current one is not already
     404                 :            :                 //selected or part of a multi selection
     405         [ #  # ]:          0 :                 if(!bAlreadySelected)
     406                 :            :                 {
     407                 :          0 :                     sal_uInt16 nCount = GetMaxId();
     408                 :            : 
     409         [ #  # ]:          0 :                     for (sal_uInt16 i=1; i<=nCount; i++)
     410                 :          0 :                         SelectPage( i, i==nId );
     411                 :          0 :                     Select();
     412                 :            :                 }
     413                 :            :             }
     414                 :            : 
     415                 :            :             // #i52073# OLE inplace editing has to be stopped before showing the sheet tab context menu
     416                 :          0 :             pViewSh->DeactivateOle();
     417                 :            : 
     418                 :            :             //  Popup-Menu:
     419                 :            :             //  get Dispatcher from ViewData (ViewFrame) instead of Shell (Frame), so it can't be null
     420 [ #  # ][ #  # ]:          0 :             pViewData->GetDispatcher().ExecutePopup( ScResId(RID_POPUP_TAB) );
     421                 :            :         }
     422                 :            :     }
     423                 :          0 : }
     424                 :            : 
     425                 :          0 : void ScTabControl::StartDrag( sal_Int8 /* nAction */, const Point& rPosPixel )
     426                 :            : {
     427                 :          0 :     ScModule* pScMod = SC_MOD();
     428 [ #  # ][ #  # ]:          0 :     sal_Bool bDisable = pScMod->IsFormulaMode() || pScMod->IsModalMode();
     429                 :            : 
     430         [ #  # ]:          0 :     if (!bDisable)
     431                 :            :     {
     432 [ #  # ][ #  # ]:          0 :         Region aRegion( Rectangle(0,0,0,0) );
     433         [ #  # ]:          0 :         CommandEvent aCEvt( rPosPixel, COMMAND_STARTDRAG, sal_True );   // needed for StartDrag
     434 [ #  # ][ #  # ]:          0 :         if (TabBar::StartDrag( aCEvt, aRegion ))
     435 [ #  # ][ #  # ]:          0 :             DoDrag( aRegion );
     436                 :            :     }
     437                 :          0 : }
     438                 :            : 
     439                 :          0 : void ScTabControl::DoDrag( const Region& /* rRegion */ )
     440                 :            : {
     441                 :          0 :     ScDocShell* pDocSh = pViewData->GetDocShell();
     442                 :          0 :     ScDocument* pDoc = pDocSh->GetDocument();
     443                 :            : 
     444                 :          0 :     SCTAB nTab = pViewData->GetTabNo();
     445 [ #  # ][ #  # ]:          0 :     ScMarkData aTabMark = pViewData->GetMarkData();
     446         [ #  # ]:          0 :     aTabMark.ResetMark();   // doesn't change marked table information
     447         [ #  # ]:          0 :     aTabMark.SetMarkArea( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab) );
     448                 :            : 
     449 [ #  # ][ #  # ]:          0 :     ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
     450         [ #  # ]:          0 :     ScClipParam aClipParam(ScRange(0, 0, 0, MAXCOL, MAXROW, 0), false);
     451         [ #  # ]:          0 :     pDoc->CopyToClip(aClipParam, pClipDoc, &aTabMark, false);
     452                 :            : 
     453         [ #  # ]:          0 :     TransferableObjectDescriptor aObjDesc;
     454         [ #  # ]:          0 :     pDocSh->FillTransferableObjectDescriptor( aObjDesc );
     455 [ #  # ][ #  # ]:          0 :     aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
                 [ #  # ]
     456                 :            :     // maSize is set in ScTransferObj ctor
     457                 :            : 
     458         [ #  # ]:          0 :     ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
     459 [ #  # ][ #  # ]:          0 :     com::sun::star::uno::Reference<com::sun::star::datatransfer::XTransferable> xTransferable( pTransferObj );
     460                 :            : 
     461         [ #  # ]:          0 :     pTransferObj->SetDragSourceFlags( SC_DROP_TABLE );
     462                 :            : 
     463         [ #  # ]:          0 :     pTransferObj->SetDragSource( pDocSh, aTabMark );
     464                 :            : 
     465         [ #  # ]:          0 :     Window* pWindow = pViewData->GetActiveWin();
     466 [ #  # ][ #  # ]:          0 :     SC_MOD()->SetDragObject( pTransferObj, NULL );      // for internal D&D
     467 [ #  # ][ #  # ]:          0 :     pTransferObj->StartDrag( pWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
         [ #  # ][ #  # ]
     468                 :          0 : }
     469                 :            : 
     470                 :          0 : sal_uInt16 lcl_DocShellNr( ScDocument* pDoc )
     471                 :            : {
     472                 :          0 :     sal_uInt16 nShellCnt = 0;
     473                 :          0 :     SfxObjectShell* pShell = SfxObjectShell::GetFirst();
     474         [ #  # ]:          0 :     while ( pShell )
     475                 :            :     {
     476         [ #  # ]:          0 :         if ( pShell->Type() == TYPE(ScDocShell) )
     477                 :            :         {
     478         [ #  # ]:          0 :             if ( ((ScDocShell*)pShell)->GetDocument() == pDoc )
     479                 :          0 :                 return nShellCnt;
     480                 :            : 
     481                 :          0 :             ++nShellCnt;
     482                 :            :         }
     483                 :          0 :         pShell = SfxObjectShell::GetNext( *pShell );
     484                 :            :     }
     485                 :            : 
     486                 :            :     OSL_FAIL("Dokument nicht gefunden");
     487                 :          0 :     return 0;
     488                 :            : }
     489                 :            : 
     490                 :          0 : sal_Int8 ScTabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
     491                 :            : {
     492                 :          0 :     EndSwitchPage();
     493                 :            : 
     494                 :          0 :     ScDocument* pDoc = pViewData->GetDocument();
     495                 :          0 :     const ScDragData& rData = SC_MOD()->GetDragData();
     496   [ #  #  #  # ]:          0 :     if ( rData.pCellTransfer && ( rData.pCellTransfer->GetDragSourceFlags() & SC_DROP_TABLE ) &&
         [ #  # ][ #  # ]
     497                 :          0 :             rData.pCellTransfer->GetSourceDocument() == pDoc )
     498                 :            :     {
     499                 :            :         // moving of tables within the document
     500                 :          0 :         SCTAB nPos = GetPrivatDropPos( rEvt.maPosPixel );
     501                 :          0 :         HideDropPos();
     502                 :            : 
     503 [ #  # ][ #  # ]:          0 :         if ( nPos == rData.pCellTransfer->GetVisibleTab() && rEvt.mnAction == DND_ACTION_MOVE )
                 [ #  # ]
     504                 :            :         {
     505                 :            :             // #i83005# do nothing - don't move to the same position
     506                 :            :             // (too easily triggered unintentionally, and might take a long time in large documents)
     507                 :            :         }
     508                 :            :         else
     509                 :            :         {
     510 [ #  # ][ #  # ]:          0 :             if ( !pDoc->GetChangeTrack() && pDoc->IsDocEditable() )
                 [ #  # ]
     511                 :            :             {
     512                 :            :                 //! use table selection from the tab control where dragging was started?
     513                 :          0 :                 pViewData->GetView()->MoveTable( lcl_DocShellNr(pDoc), nPos, rEvt.mnAction != DND_ACTION_MOVE );
     514                 :            : 
     515                 :          0 :                 rData.pCellTransfer->SetDragWasInternal();          // don't delete
     516                 :          0 :                 return sal_True;
     517                 :            :             }
     518                 :            :         }
     519                 :            :     }
     520                 :            : 
     521                 :          0 :     return 0;
     522                 :            : }
     523                 :            : 
     524                 :          0 : sal_Int8 ScTabControl::AcceptDrop( const AcceptDropEvent& rEvt )
     525                 :            : {
     526         [ #  # ]:          0 :     if ( rEvt.mbLeaving )
     527                 :            :     {
     528                 :          0 :         EndSwitchPage();
     529                 :          0 :         HideDropPos();
     530                 :          0 :         return rEvt.mnAction;
     531                 :            :     }
     532                 :            : 
     533                 :          0 :     const ScDocument* pDoc = pViewData->GetDocument();
     534                 :          0 :     const ScDragData& rData = SC_MOD()->GetDragData();
     535   [ #  #  #  # ]:          0 :     if ( rData.pCellTransfer && ( rData.pCellTransfer->GetDragSourceFlags() & SC_DROP_TABLE ) &&
         [ #  # ][ #  # ]
     536                 :          0 :             rData.pCellTransfer->GetSourceDocument() == pDoc )
     537                 :            :     {
     538                 :            :         // moving of tables within the document
     539 [ #  # ][ #  # ]:          0 :         if ( !pDoc->GetChangeTrack() && pDoc->IsDocEditable() )
                 [ #  # ]
     540                 :            :         {
     541                 :          0 :             ShowDropPos( rEvt.maPosPixel );
     542                 :          0 :             return rEvt.mnAction;
     543                 :            :         }
     544                 :            :     }
     545                 :            :     else                    // switch sheets for all formats
     546                 :            :     {
     547                 :          0 :         SwitchPage( rEvt.maPosPixel );      // switch sheet after timeout
     548                 :          0 :         return 0;                           // nothing can be dropped here
     549                 :            :     }
     550                 :            : 
     551                 :          0 :     return 0;
     552                 :            : }
     553                 :            : 
     554                 :          0 : long ScTabControl::StartRenaming()
     555                 :            : {
     556         [ #  # ]:          0 :     if ( pViewData->GetDocument()->IsDocEditable() )
     557                 :          0 :         return TABBAR_RENAMING_YES;
     558                 :            :     else
     559                 :          0 :         return TABBAR_RENAMING_NO;
     560                 :            : }
     561                 :            : 
     562                 :          0 : long ScTabControl::AllowRenaming()
     563                 :            : {
     564                 :          0 :     ScTabViewShell* pViewSh = pViewData->GetViewShell();
     565                 :            :     OSL_ENSURE( pViewSh, "pViewData->GetViewShell()" );
     566                 :            : 
     567                 :          0 :     long nRet = TABBAR_RENAMING_CANCEL;
     568                 :          0 :     sal_uInt16 nId = GetEditPageId();
     569         [ #  # ]:          0 :     if ( nId )
     570                 :            :     {
     571                 :          0 :         SCTAB nTab = nId - 1;
     572         [ #  # ]:          0 :         String aNewName = GetEditText();
     573         [ #  # ]:          0 :         sal_Bool bDone = pViewSh->RenameTable( aNewName, nTab );
     574         [ #  # ]:          0 :         if ( bDone )
     575                 :          0 :             nRet = TABBAR_RENAMING_YES;
     576         [ #  # ]:          0 :         else if ( bErrorShown )
     577                 :            :         {
     578                 :            :             //  if the error message from this TabControl is currently visible,
     579                 :            :             //  don't end edit mode now, to avoid problems when returning to
     580                 :            :             //  the other call (showing the error) - this should not happen
     581                 :            :             OSL_FAIL("ScTabControl::AllowRenaming: nested calls");
     582                 :          0 :             nRet = TABBAR_RENAMING_NO;
     583                 :            :         }
     584 [ #  # ][ #  # ]:          0 :         else if ( Application::IsInModalMode() )
     585                 :            :         {
     586                 :            :             //  don't show error message above any modal dialog
     587                 :            :             //  instead cancel renaming without error message
     588                 :          0 :             nRet = TABBAR_RENAMING_CANCEL;
     589                 :            :         }
     590                 :            :         else
     591                 :            :         {
     592                 :          0 :             bErrorShown = sal_True;
     593         [ #  # ]:          0 :             pViewSh->ErrorMessage( STR_INVALIDTABNAME );
     594                 :          0 :             bErrorShown = false;
     595                 :          0 :             nRet = TABBAR_RENAMING_NO;
     596         [ #  # ]:          0 :         }
     597                 :            :     }
     598                 :          0 :     return nRet;
     599                 :            : }
     600                 :            : 
     601                 :          0 : void ScTabControl::EndRenaming()
     602                 :            : {
     603         [ #  # ]:          0 :     if ( HasFocus() )
     604                 :          0 :         pViewData->GetView()->ActiveGrabFocus();
     605                 :          0 : }
     606                 :            : 
     607                 :          4 : void ScTabControl::Mirror()
     608                 :            : {
     609                 :          4 :     TabBar::Mirror();
     610         [ -  + ]:          4 :     if( nSelPageIdByMouse != TabBar::PAGE_NOT_FOUND )
     611                 :            :     {
     612         [ #  # ]:          0 :         Rectangle aRect( GetPageRect( GetCurPageId() ) );
     613 [ #  # ][ #  # ]:          0 :         if( !aRect.IsEmpty() )
     614 [ #  # ][ #  # ]:          0 :             SetPointerPosPixel( aRect.Center() );
     615                 :          0 :         nSelPageIdByMouse = TabBar::PAGE_NOT_FOUND;  // only once after a Select()
     616                 :            :     }
     617                 :          4 : }
     618                 :            : 
     619                 :            : 
     620                 :            : 
     621                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10