LCOV - code coverage report
Current view: top level - sc/source/ui/view - tabvwshe.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 123 0.0 %
Date: 2012-08-25 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 231 0.0 %

           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 <comphelper/string.hxx>
      30                 :            : #include <editeng/eeitem.hxx>
      31                 :            : 
      32                 :            : #include "scitems.hxx"
      33                 :            : #include <editeng/editview.hxx>
      34                 :            : #include <editeng/flditem.hxx>
      35                 :            : #include <svx/hlnkitem.hxx>
      36                 :            : #include <svl/srchitem.hxx>
      37                 :            : #include <sfx2/dispatch.hxx>
      38                 :            : #include <sfx2/viewfrm.hxx>
      39                 :            : #include <sfx2/request.hxx>
      40                 :            : #include <sfx2/objface.hxx>
      41                 :            : #include <svl/stritem.hxx>
      42                 :            : 
      43                 :            : #include "tabvwsh.hxx"
      44                 :            : #include "sc.hrc"
      45                 :            : #include "scmod.hxx"
      46                 :            : #include "impex.hxx"
      47                 :            : #include "editsh.hxx"
      48                 :            : #include "dociter.hxx"
      49                 :            : #include "inputhdl.hxx"
      50                 :            : #include "document.hxx"
      51                 :            : 
      52                 :            : //==================================================================
      53                 :            : 
      54                 :          0 : String ScTabViewShell::GetSelectionText( sal_Bool bWholeWord )
      55                 :            : {
      56                 :          0 :     String aStrSelection;
      57                 :            : 
      58 [ #  # ][ #  # ]:          0 :     if ( pEditShell && pEditShell == GetMySubShell() )
         [ #  # ][ #  # ]
      59                 :            :     {
      60 [ #  # ][ #  # ]:          0 :         aStrSelection = pEditShell->GetSelectionText( bWholeWord );
                 [ #  # ]
      61                 :            :     }
      62                 :            :     else
      63                 :            :     {
      64                 :          0 :         ScRange aRange;
      65                 :            : 
      66 [ #  # ][ #  # ]:          0 :         if ( GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
      67                 :            :         {
      68         [ #  # ]:          0 :             ScDocument* pDoc = GetViewData()->GetDocument();
      69 [ #  # ][ #  # ]:          0 :             if ( bInFormatDialog && aRange.aStart.Row() != aRange.aEnd.Row() )
                 [ #  # ]
      70                 :            :             {
      71                 :            :                 // Range auf eine Datenzeile begrenzen
      72                 :            :                 // (nur wenn der Aufruf aus einem Format-Dialog kommt)
      73                 :          0 :                 ScHorizontalCellIterator aIter( pDoc, aRange.aStart.Tab(),
      74                 :          0 :                     aRange.aStart.Col(), aRange.aStart.Row(),
      75         [ #  # ]:          0 :                     aRange.aEnd.Col(), aRange.aEnd.Row() );
      76                 :            :                 SCCOL nCol;
      77                 :            :                 SCROW nRow;
      78 [ #  # ][ #  # ]:          0 :                 if ( aIter.GetNext( nCol, nRow ) )
      79                 :            :                 {
      80                 :          0 :                     aRange.aStart.SetCol( nCol );
      81                 :          0 :                     aRange.aStart.SetRow( nRow );
      82                 :          0 :                     aRange.aEnd.SetRow( nRow );
      83                 :            :                 }
      84                 :            :                 else
      85         [ #  # ]:          0 :                     aRange.aEnd = aRange.aStart;
      86                 :            :             }
      87                 :            :             else
      88                 :            :             {
      89                 :            :                 // #i111531# with 1M rows it was necessary to limit the range
      90                 :            :                 // to the actually used data area.
      91                 :            :                 SCCOL nCol1, nCol2;
      92                 :            :                 SCROW nRow1, nRow2;
      93                 :            :                 SCTAB nTab1, nTab2;
      94                 :          0 :                 aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
      95                 :            :                 bool bShrunk;
      96         [ #  # ]:          0 :                 pDoc->ShrinkToUsedDataArea( bShrunk, nTab1, nCol1, nRow1, nCol2, nRow2, false);
      97         [ #  # ]:          0 :                 if (bShrunk)
      98                 :            :                 {
      99                 :          0 :                     aRange.aStart.SetCol( nCol1 );
     100                 :          0 :                     aRange.aStart.SetRow( nRow1 );
     101                 :          0 :                     aRange.aEnd.SetCol( nCol2 );
     102                 :          0 :                     aRange.aEnd.SetRow( nRow2 );
     103                 :            :                 }
     104                 :            :             }
     105                 :            : 
     106         [ #  # ]:          0 :             ScImportExport aObj( pDoc, aRange );
     107                 :          0 :             aObj.SetFormulas( GetViewData()->GetOptions().GetOption( VOPT_FORMULAS ) );
     108                 :          0 :             rtl::OUString aExportOUString;
     109         [ #  # ]:          0 :             aObj.ExportString( aExportOUString );
     110 [ #  # ][ #  # ]:          0 :             aStrSelection = convertLineEnd(aExportOUString, LINEEND_CR);
     111                 :            : 
     112                 :            :             //  Tab/CR durch Space ersetzen, wenn fuer Dialog oder per Basic/SelectionTextExt,
     113                 :            :             //  oder wenn es eine einzelne Zeile ist.
     114                 :            :             //  Sonst mehrzeilig mit Tabs beibehalten (z.B. Mail oder Basic/SelectionText).
     115                 :            :             //  Fuer Mail werden die Tabs dann spaeter in (mehrere) Spaces gewandelt.
     116                 :            : 
     117 [ #  # ][ #  # ]:          0 :             if ( bInFormatDialog || bWholeWord || aRange.aEnd.Row() == aRange.aStart.Row() )
         [ #  # ][ #  # ]
     118                 :            :             {
     119                 :            :                 xub_StrLen nAt;
     120 [ #  # ][ #  # ]:          0 :                 while (  (nAt = aStrSelection.Search( CHAR_CR )) != STRING_NOTFOUND )
     121         [ #  # ]:          0 :                     aStrSelection.SetChar( nAt, ' ' );
     122 [ #  # ][ #  # ]:          0 :                 while (  (nAt = aStrSelection.Search( '\t' )) != STRING_NOTFOUND )
     123         [ #  # ]:          0 :                     aStrSelection.SetChar( nAt, ' ' );
     124                 :            : 
     125 [ #  # ][ #  # ]:          0 :                 aStrSelection = comphelper::string::stripEnd(aStrSelection, ' ');
                 [ #  # ]
     126         [ #  # ]:          0 :             }
     127                 :            :         }
     128                 :            :     }
     129                 :            : 
     130                 :          0 :     return aStrSelection;
     131                 :            : }
     132                 :            : 
     133                 :            : //------------------------------------------------------------------------
     134                 :            : 
     135                 :          0 : void ScTabViewShell::InsertURL( const String& rName, const String& rURL, const String& rTarget,
     136                 :            :                                 sal_uInt16 nMode )
     137                 :            : {
     138                 :          0 :     SvxLinkInsertMode eMode = (SvxLinkInsertMode) nMode;
     139                 :          0 :     sal_Bool bAsText = ( eMode != HLINK_BUTTON );       // Default ist jetzt Text
     140                 :            : 
     141         [ #  # ]:          0 :     if ( bAsText )
     142                 :            :     {
     143         [ #  # ]:          0 :         if ( GetViewData()->IsActive() )
     144                 :            :         {
     145                 :            :             //  if the view is active, always use InsertURLField, which starts EditMode
     146                 :            :             //  and selects the URL, so it can be changed from the URL bar / dialog
     147                 :            : 
     148                 :          0 :             InsertURLField( rName, rURL, rTarget );
     149                 :            :         }
     150                 :            :         else
     151                 :            :         {
     152                 :            :             //  if the view is not active, InsertURLField doesn't work
     153                 :            :             //  -> use InsertBookmark to directly manipulate cell content
     154                 :            :             //  bTryReplace=sal_True -> if cell contains only one URL, replace it
     155                 :            : 
     156                 :          0 :             SCCOL nPosX = GetViewData()->GetCurX();
     157                 :          0 :             SCROW nPosY = GetViewData()->GetCurY();
     158                 :          0 :             InsertBookmark( rName, rURL, nPosX, nPosY, &rTarget, sal_True );
     159                 :            :         }
     160                 :            :     }
     161                 :            :     else
     162                 :            :     {
     163                 :          0 :         SC_MOD()->InputEnterHandler();
     164                 :          0 :         InsertURLButton( rName, rURL, rTarget );
     165                 :            :     }
     166                 :          0 : }
     167                 :            : 
     168                 :            : //------------------------------------------------------------------------
     169                 :            : 
     170                 :            : // wenn CLOOKs: -> mit <editview.hxx> <flditem.hxx>in neue tabvwsh
     171                 :            : 
     172                 :          0 : void lcl_SelectFieldAfterInsert( EditView& rView )
     173                 :            : {
     174         [ #  # ]:          0 :     ESelection aSel = rView.GetSelection();
     175 [ #  # ][ #  # ]:          0 :     if ( aSel.nStartPos == aSel.nEndPos && aSel.nStartPos > 0 )
     176                 :            :     {
     177                 :            :         //  Cursor is behind the inserted field -> extend selection to the left
     178                 :            : 
     179                 :          0 :         --aSel.nStartPos;
     180         [ #  # ]:          0 :         rView.SetSelection( aSel );
     181                 :            :     }
     182                 :          0 : }
     183                 :            : 
     184                 :          0 : void ScTabViewShell::InsertURLField( const String& rName, const String& rURL, const String& rTarget )
     185                 :            : {
     186 [ #  # ][ #  # ]:          0 :     SvxURLField aURLField( rURL, rName, SVXURLFORMAT_REPR );
                 [ #  # ]
     187         [ #  # ]:          0 :     aURLField.SetTargetFrame( rTarget );
     188         [ #  # ]:          0 :     SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
     189                 :            : 
     190                 :          0 :     ScViewData*     pViewData   = GetViewData();
     191         [ #  # ]:          0 :     ScModule*       pScMod      = SC_MOD();
     192         [ #  # ]:          0 :     ScInputHandler* pHdl        = pScMod->GetInputHdl( pViewData->GetViewShell() );
     193                 :            : 
     194                 :          0 :     sal_Bool bSelectFirst = false;
     195 [ #  # ][ #  # ]:          0 :     if ( !pScMod->IsEditMode() )
     196                 :            :     {
     197 [ #  # ][ #  # ]:          0 :         if ( !SelectionEditable() )
     198                 :            :         {
     199                 :            :             // no error message (may be called from drag&drop)
     200                 :          0 :             return;
     201                 :            :         }
     202                 :            : 
     203                 :            :         // single url in cell is shown in the dialog and replaced
     204         [ #  # ]:          0 :         bSelectFirst = HasBookmarkAtCursor( NULL );
     205         [ #  # ]:          0 :         pScMod->SetInputMode( SC_INPUT_TABLE );
     206                 :            :     }
     207                 :            : 
     208                 :          0 :     EditView*       pTopView    = pHdl->GetTopView();
     209                 :          0 :     EditView*       pTableView  = pHdl->GetTableView();
     210                 :            :     OSL_ENSURE( pTopView || pTableView, "No EditView" );
     211                 :            : 
     212         [ #  # ]:          0 :     if ( bSelectFirst )
     213                 :            :     {
     214         [ #  # ]:          0 :         if ( pTopView )
     215         [ #  # ]:          0 :             pTopView->SetSelection( ESelection(0,0,0,1) );
     216         [ #  # ]:          0 :         if ( pTableView )
     217         [ #  # ]:          0 :             pTableView->SetSelection( ESelection(0,0,0,1) );
     218                 :            :     }
     219                 :            : 
     220         [ #  # ]:          0 :     pHdl->DataChanging();
     221                 :            : 
     222         [ #  # ]:          0 :     if ( pTopView )
     223                 :            :     {
     224         [ #  # ]:          0 :         pTopView->InsertField( aURLItem );
     225         [ #  # ]:          0 :         lcl_SelectFieldAfterInsert( *pTopView );
     226                 :            :     }
     227         [ #  # ]:          0 :     if ( pTableView )
     228                 :            :     {
     229         [ #  # ]:          0 :         pTableView->InsertField( aURLItem );
     230         [ #  # ]:          0 :         lcl_SelectFieldAfterInsert( *pTableView );
     231                 :            :     }
     232                 :            : 
     233 [ #  # ][ #  # ]:          0 :     pHdl->DataChanged();
         [ #  # ][ #  # ]
                 [ #  # ]
     234                 :            : }
     235                 :            : 
     236                 :          0 : void ScTabViewShell::ExecSearch( SfxRequest& rReq )
     237                 :            : {
     238                 :          0 :     const SfxItemSet*   pReqArgs    = rReq.GetArgs();
     239                 :          0 :     sal_uInt16              nSlot       = rReq.GetSlot();
     240                 :            :     const SfxPoolItem*  pItem;
     241                 :            : 
     242   [ #  #  #  #  :          0 :     switch ( nSlot )
                      # ]
     243                 :            :     {
     244                 :            :         case FID_SEARCH_NOW:
     245                 :            :             {
     246 [ #  # ][ #  # ]:          0 :                 if ( pReqArgs &&
                 [ #  # ]
     247         [ #  # ]:          0 :                      SFX_ITEM_SET == pReqArgs->GetItemState(SID_SEARCH_ITEM, false, &pItem) )
     248                 :            :                 {
     249                 :            :                     OSL_ENSURE( pItem->ISA(SvxSearchItem), "falsches Item" );
     250                 :          0 :                     const SvxSearchItem* pSearchItem = (const SvxSearchItem*) pItem;
     251                 :            : 
     252         [ #  # ]:          0 :                     ScGlobal::SetSearchItem( *pSearchItem );
     253 [ #  # ][ #  # ]:          0 :                     SearchAndReplace( pSearchItem, sal_True, rReq.IsAPI() );
     254         [ #  # ]:          0 :                     rReq.Done();
     255                 :            :                 }
     256                 :            :             }
     257                 :          0 :             break;
     258                 :            : 
     259                 :            :         case SID_SEARCH_ITEM:
     260 [ #  # ][ #  # ]:          0 :             if (pReqArgs && SFX_ITEM_SET ==
                 [ #  # ]
     261         [ #  # ]:          0 :                             pReqArgs->GetItemState(SID_SEARCH_ITEM, false, &pItem))
     262                 :            :             {
     263                 :            :                 //  Search-Item merken
     264                 :            :                 OSL_ENSURE( pItem->ISA(SvxSearchItem), "falsches Item" );
     265         [ #  # ]:          0 :                 ScGlobal::SetSearchItem( *(const SvxSearchItem*) pItem );
     266                 :            :             }
     267                 :            :             else
     268                 :            :             {
     269                 :            :                 OSL_FAIL("SID_SEARCH_ITEM ohne Parameter");
     270                 :            :             }
     271                 :          0 :             break;
     272                 :            :         case FID_SEARCH:
     273                 :            :         case FID_REPLACE:
     274                 :            :         case FID_REPLACE_ALL:
     275                 :            :         case FID_SEARCH_ALL:
     276                 :            :             {
     277 [ #  # ][ #  # ]:          0 :                 if (pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState(nSlot, false, &pItem))
         [ #  # ][ #  # ]
     278                 :            :                 {
     279                 :            :                     //  SearchItem holen
     280                 :            : 
     281 [ #  # ][ #  # ]:          0 :                     SvxSearchItem aSearchItem = ScGlobal::GetSearchItem();
     282                 :            : 
     283                 :            :                     //  SearchItem fuellen
     284                 :            : 
     285         [ #  # ]:          0 :                     aSearchItem.SetSearchString(((SfxStringItem*)pItem)->GetValue());
     286 [ #  # ][ #  # ]:          0 :                     if(SFX_ITEM_SET == pReqArgs->GetItemState(FN_PARAM_1, false, &pItem))
     287         [ #  # ]:          0 :                         aSearchItem.SetReplaceString(((SfxStringItem*)pItem)->GetValue());
     288                 :            : 
     289         [ #  # ]:          0 :                     if (nSlot == FID_SEARCH)
     290                 :          0 :                         aSearchItem.SetCommand(SVX_SEARCHCMD_FIND);
     291         [ #  # ]:          0 :                     else if(nSlot == FID_REPLACE)
     292                 :          0 :                         aSearchItem.SetCommand(SVX_SEARCHCMD_REPLACE);
     293         [ #  # ]:          0 :                     else if(nSlot == FID_REPLACE_ALL)
     294                 :          0 :                         aSearchItem.SetCommand(SVX_SEARCHCMD_REPLACE_ALL);
     295                 :            :                     else
     296                 :          0 :                         aSearchItem.SetCommand(SVX_SEARCHCMD_FIND_ALL);
     297                 :            : 
     298                 :            :                     //  Request ausfuehren (dabei wird das SearchItem gespeichert)
     299                 :            : 
     300                 :          0 :                     aSearchItem.SetWhich(SID_SEARCH_ITEM);
     301         [ #  # ]:          0 :                     GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW,
     302         [ #  # ]:          0 :                             rReq.IsAPI() ? SFX_CALLMODE_API|SFX_CALLMODE_SYNCHRON :
     303                 :            :                                             SFX_CALLMODE_STANDARD,
     304 [ #  # ][ #  # ]:          0 :                             &aSearchItem, 0L );
                 [ #  # ]
     305                 :            :                 }
     306                 :            :                 else
     307                 :            :                 {
     308         [ #  # ]:          0 :                     GetViewData()->GetDispatcher().Execute(
     309         [ #  # ]:          0 :                             SID_SEARCH_DLG, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD );
     310                 :            :                 }
     311                 :            :             }
     312                 :          0 :             break;
     313                 :            :         case FID_REPEAT_SEARCH:
     314                 :            :             {
     315                 :            :                 //  nochmal mit ScGlobal::GetSearchItem()
     316                 :            : 
     317 [ #  # ][ #  # ]:          0 :                 SvxSearchItem aSearchItem = ScGlobal::GetSearchItem();
     318                 :          0 :                 aSearchItem.SetWhich(SID_SEARCH_ITEM);
     319         [ #  # ]:          0 :                 GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW,
     320         [ #  # ]:          0 :                         rReq.IsAPI() ? SFX_CALLMODE_API|SFX_CALLMODE_SYNCHRON :
     321                 :            :                                         SFX_CALLMODE_STANDARD,
     322 [ #  # ][ #  # ]:          0 :                         &aSearchItem, 0L );
                 [ #  # ]
     323                 :            :             }
     324                 :          0 :             break;
     325                 :            : //      case FID_SEARCH_COUNT:
     326                 :            :     }
     327                 :          0 : }
     328                 :            : 
     329                 :            : //--------------------------------------------------------------------
     330                 :            : 
     331                 :            : 
     332                 :            : 
     333                 :            : 
     334                 :            : 
     335                 :            : 
     336                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10