LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - spelleng.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 177 0.6 %
Date: 2013-07-09 Functions: 2 24 8.3 %
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 "spelleng.hxx"
      21             : #include <com/sun/star/i18n/TextConversionOption.hpp>
      22             : 
      23             : #include <memory>
      24             : 
      25             : #include "scitems.hxx"
      26             : #include <editeng/eeitem.hxx>
      27             : 
      28             : 
      29             : #include <editeng/langitem.hxx>
      30             : #include <editeng/editobj.hxx>
      31             : #include <editeng/editview.hxx>
      32             : #include <sfx2/viewfrm.hxx>
      33             : #include <vcl/msgbox.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : 
      36             : #include "spelldialog.hxx"
      37             : #include "tabvwsh.hxx"
      38             : #include "docsh.hxx"
      39             : #include "formulacell.hxx"
      40             : #include "patattr.hxx"
      41             : #include "waitoff.hxx"
      42             : #include "globstr.hrc"
      43             : #include "markdata.hxx"
      44             : 
      45             : #include <boost/scoped_ptr.hpp>
      46             : 
      47             : using namespace ::com::sun::star;
      48             : 
      49           0 : ScConversionEngineBase::ScConversionEngineBase(
      50             :         SfxItemPool* pEnginePoolP, ScViewData& rViewData,
      51             :         ScDocument* pUndoDoc, ScDocument* pRedoDoc ) :
      52             :     ScEditEngineDefaulter( pEnginePoolP ),
      53             :     mrViewData( rViewData ),
      54           0 :     mrDocShell( *rViewData.GetDocShell() ),
      55           0 :     mrDoc( *rViewData.GetDocShell()->GetDocument() ),
      56             :     maSelState( rViewData ),
      57             :     mpUndoDoc( pUndoDoc ),
      58             :     mpRedoDoc( pRedoDoc ),
      59             :     meCurrLang( LANGUAGE_ENGLISH_US ),
      60             :     mbIsAnyModified( false ),
      61             :     mbInitialState( true ),
      62             :     mbWrappedInTable( false ),
      63           0 :     mbFinished( false )
      64             : {
      65           0 :     maSelState.GetCellCursor().GetVars( mnStartCol, mnStartRow, mnStartTab );
      66             :     // start with cell A1 in cell/range/multi-selection, will seek to first selected
      67           0 :     if( maSelState.GetSelectionType() == SC_SELECTTYPE_SHEET )
      68             :     {
      69           0 :         mnStartCol = 0;
      70           0 :         mnStartRow = 0;
      71             :     }
      72           0 :     mnCurrCol = mnStartCol;
      73           0 :     mnCurrRow = mnStartRow;
      74           0 : }
      75             : 
      76           0 : ScConversionEngineBase::~ScConversionEngineBase()
      77             : {
      78           0 : }
      79             : 
      80           0 : bool ScConversionEngineBase::FindNextConversionCell()
      81             : {
      82           0 :     ScMarkData& rMark = mrViewData.GetMarkData();
      83           0 :     ScTabViewShell* pViewShell = mrViewData.GetViewShell();
      84           0 :     const ScPatternAttr* pPattern = NULL;
      85           0 :     const ScPatternAttr* pLastPattern = NULL;
      86             : 
      87           0 :     boost::scoped_ptr<SfxItemSet> pEditDefaults(new SfxItemSet(GetEmptyItemSet()));
      88             : 
      89           0 :     if( IsModified() )
      90             :     {
      91           0 :         mbIsAnyModified = true;
      92             : 
      93           0 :         String aNewStr = GetText();
      94             : 
      95           0 :         bool bMultiTab = (rMark.GetSelectCount() > 1);
      96           0 :         OUString aVisibleStr;
      97           0 :         if( bMultiTab )
      98           0 :             aVisibleStr = mrDoc.GetString(mnCurrCol, mnCurrRow, mnStartTab);
      99             : 
     100           0 :         for( SCTAB nTab = 0, nTabCount = mrDoc.GetTableCount(); nTab < nTabCount; ++nTab )
     101             :         {
     102             :             //  always change the cell on the visible tab,
     103             :             //  on the other selected tabs only if they contain the same text
     104             : 
     105           0 :             if ((nTab == mnStartTab) ||
     106           0 :                 (bMultiTab && rMark.GetTableSelect(nTab) && mrDoc.GetString(mnCurrCol, mnCurrRow, nTab) == aVisibleStr))
     107             :             {
     108           0 :                 ScAddress aPos( mnCurrCol, mnCurrRow, nTab );
     109           0 :                 CellType eCellType = mrDoc.GetCellType( aPos );
     110           0 :                 bool bEmptyCell = eCellType == CELLTYPE_NONE;
     111             : 
     112           0 :                 if (mpUndoDoc && !bEmptyCell)
     113           0 :                     mrDoc.CopyCellToDocument(aPos, aPos, *mpUndoDoc);
     114             : 
     115           0 :                 if (eCellType == CELLTYPE_EDIT)
     116             :                 {
     117           0 :                     boost::scoped_ptr<EditTextObject> pEditObj(CreateTextObject());
     118           0 :                     mrDoc.SetEditText(aPos, *pEditObj, GetEditTextObjectPool());
     119             :                 }
     120             :                 else
     121           0 :                     mrDoc.SetString(aPos, aNewStr);
     122             : 
     123           0 :                 if (mpRedoDoc && !bEmptyCell)
     124           0 :                     mrDoc.CopyCellToDocument(aPos, aPos, *mpRedoDoc);
     125             : 
     126           0 :                 mrDocShell.PostPaintCell(aPos);
     127             :             }
     128           0 :         }
     129             :     }
     130             : 
     131           0 :     SCCOL nNewCol = mnCurrCol;
     132           0 :     SCROW nNewRow = mnCurrRow;
     133             : 
     134           0 :     if( mbInitialState )
     135             :     {
     136             :         /*  On very first call, decrement row to let GetNextSpellingCell() find
     137             :             the first cell of current range. */
     138           0 :         mbInitialState = false;
     139           0 :         --nNewRow;
     140             :     }
     141             : 
     142           0 :     bool bSheetSel = maSelState.GetSelectionType() == SC_SELECTTYPE_SHEET;
     143           0 :     bool bLoop = true;
     144           0 :     bool bFound = false;
     145           0 :     while( bLoop && !bFound )
     146             :     {
     147           0 :         bLoop = mrDoc.GetNextSpellingCell( nNewCol, nNewRow, mnStartTab, bSheetSel, rMark );
     148           0 :         if( bLoop )
     149             :         {
     150           0 :             FillFromCell( mnCurrCol, mnCurrRow, mnStartTab );
     151             : 
     152           0 :             if( mbWrappedInTable && ((nNewCol > mnStartCol) || ((nNewCol == mnStartCol) && (nNewRow >= mnStartRow))) )
     153             :             {
     154           0 :                 ShowFinishDialog();
     155           0 :                 bLoop = false;
     156           0 :                 mbFinished = true;
     157             :             }
     158           0 :             else if( nNewCol > MAXCOL )
     159             :             {
     160             :                 // no more cells in the sheet - try to restart at top of sheet
     161             : 
     162           0 :                 if( bSheetSel || ((mnStartCol == 0) && (mnStartRow == 0)) )
     163             :                 {
     164             :                     // conversion started at cell A1 or in selection, do not query to restart at top
     165           0 :                     ShowFinishDialog();
     166           0 :                     bLoop = false;
     167           0 :                     mbFinished = true;
     168             :                 }
     169           0 :                 else if( ShowTableWrapDialog() )
     170             :                 {
     171             :                     // conversion started anywhere but in cell A1, user wants to restart
     172           0 :                     nNewRow = MAXROW + 2;
     173           0 :                     mbWrappedInTable = true;
     174             :                 }
     175             :                 else
     176             :                 {
     177           0 :                     bLoop = false;
     178           0 :                     mbFinished = true;
     179             :                 }
     180             :             }
     181             :             else
     182             :             {
     183           0 :                 pPattern = mrDoc.GetPattern( nNewCol, nNewRow, mnStartTab );
     184           0 :                 if( pPattern && (pPattern != pLastPattern) )
     185             :                 {
     186           0 :                     pPattern->FillEditItemSet( pEditDefaults.get() );
     187           0 :                     SetDefaults( *pEditDefaults );
     188           0 :                     pLastPattern = pPattern;
     189             :                 }
     190             : 
     191             :                 // language changed?
     192           0 :                 const SfxPoolItem* pItem = mrDoc.GetAttr( nNewCol, nNewRow, mnStartTab, ATTR_FONT_LANGUAGE );
     193           0 :                 if( const SvxLanguageItem* pLangItem = PTR_CAST( SvxLanguageItem, pItem ) )
     194             :                 {
     195           0 :                     LanguageType eLang = static_cast< LanguageType >( pLangItem->GetValue() );
     196           0 :                     if( eLang == LANGUAGE_SYSTEM )
     197           0 :                         eLang = Application::GetSettings().GetLanguageTag().getLanguageType();   // never use SYSTEM for spelling
     198           0 :                     if( eLang != meCurrLang )
     199             :                     {
     200           0 :                         meCurrLang = eLang;
     201           0 :                         SetDefaultLanguage( eLang );
     202             :                     }
     203             :                 }
     204             : 
     205           0 :                 FillFromCell( nNewCol, nNewRow, mnStartTab );
     206             : 
     207           0 :                 bFound = bLoop && NeedsConversion();
     208             :             }
     209             :         }
     210             :     }
     211             : 
     212           0 :     if( bFound )
     213             :     {
     214           0 :         pViewShell->AlignToCursor( nNewCol, nNewRow, SC_FOLLOW_JUMP );
     215           0 :         pViewShell->SetCursor( nNewCol, nNewRow, sal_True );
     216           0 :         mrViewData.GetView()->MakeEditView( this, nNewCol, nNewRow );
     217           0 :         EditView* pEditView = mrViewData.GetSpellingView();
     218             :         // maSelState.GetEditSelection() returns (0,0) if not in edit mode -> ok
     219           0 :         pEditView->SetSelection( maSelState.GetEditSelection() );
     220             : 
     221           0 :         ClearModifyFlag();
     222           0 :         mnCurrCol = nNewCol;
     223           0 :         mnCurrRow = nNewRow;
     224             :     }
     225             : 
     226           0 :     return bFound;
     227             : }
     228             : 
     229           0 : void ScConversionEngineBase::RestoreCursorPos()
     230             : {
     231           0 :     const ScAddress& rPos = maSelState.GetCellCursor();
     232           0 :     mrViewData.GetViewShell()->SetCursor( rPos.Col(), rPos.Row() );
     233           0 : }
     234             : 
     235           0 : bool ScConversionEngineBase::ShowTableWrapDialog()
     236             : {
     237             :     // default: no dialog, always restart at top
     238           0 :     return true;
     239             : }
     240             : 
     241           0 : void ScConversionEngineBase::ShowFinishDialog()
     242             : {
     243             :     // default: no dialog
     244           0 : }
     245             : 
     246             : // private --------------------------------------------------------------------
     247             : 
     248           0 : void ScConversionEngineBase::FillFromCell( SCCOL nCol, SCROW nRow, SCTAB nTab )
     249             : {
     250           0 :     ScAddress aPos(nCol, nRow, nTab);
     251             : 
     252           0 :     switch (mrDoc.GetCellType(aPos))
     253             :     {
     254             :         case CELLTYPE_STRING:
     255             :         {
     256           0 :             OUString aText = mrDoc.GetString(aPos);
     257           0 :             SetText( aText );
     258             :         }
     259           0 :         break;
     260             :         case CELLTYPE_EDIT:
     261             :         {
     262           0 :             const EditTextObject* pNewEditObj = mrDoc.GetEditText(aPos);
     263           0 :             if (pNewEditObj)
     264           0 :                 SetText(*pNewEditObj);
     265             :         }
     266           0 :         break;
     267             :         default:
     268           0 :             SetText(EMPTY_OUSTRING);
     269             :     }
     270           0 : }
     271             : 
     272             : // ============================================================================
     273             : 
     274           0 : ScSpellingEngine::ScSpellingEngine(
     275             :         SfxItemPool* pEnginePoolP, ScViewData& rViewData,
     276             :         ScDocument* pUndoDoc, ScDocument* pRedoDoc,
     277             :         XSpellCheckerRef xSpeller ) :
     278           0 :     ScConversionEngineBase( pEnginePoolP, rViewData, pUndoDoc, pRedoDoc )
     279             : {
     280           0 :     SetSpeller( xSpeller );
     281           0 : }
     282             : 
     283           0 : void ScSpellingEngine::ConvertAll( EditView& rEditView )
     284             : {
     285           0 :     EESpellState eState = EE_SPELL_OK;
     286           0 :     if( FindNextConversionCell() )
     287           0 :         eState = rEditView.StartSpeller( static_cast< sal_Bool >( sal_True ) );
     288             : 
     289             :     OSL_ENSURE( eState != EE_SPELL_NOSPELLER, "ScSpellingEngine::Convert - no spell checker" );
     290           0 :     if( eState == EE_SPELL_NOLANGUAGE )
     291             :     {
     292           0 :         Window* pParent = GetDialogParent();
     293           0 :         ScWaitCursorOff aWaitOff( pParent );
     294           0 :         InfoBox( pParent, ScGlobal::GetRscString( STR_NOLANGERR ) ).Execute();
     295             :     }
     296           0 : }
     297             : 
     298           0 : sal_Bool ScSpellingEngine::SpellNextDocument()
     299             : {
     300           0 :     return FindNextConversionCell();
     301             : }
     302             : 
     303           0 : bool ScSpellingEngine::NeedsConversion()
     304             : {
     305           0 :     return HasSpellErrors() != EE_SPELL_OK;
     306             : }
     307             : 
     308           0 : bool ScSpellingEngine::ShowTableWrapDialog()
     309             : {
     310           0 :     Window* pParent = GetDialogParent();
     311           0 :     ScWaitCursorOff aWaitOff( pParent );
     312             :     MessBox aMsgBox( pParent, WinBits( WB_YES_NO | WB_DEF_YES ),
     313           0 :         ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ),
     314           0 :         ScGlobal::GetRscString( STR_SPELLING_BEGIN_TAB) );
     315           0 :     return aMsgBox.Execute() == RET_YES;
     316             : }
     317             : 
     318           0 : void ScSpellingEngine::ShowFinishDialog()
     319             : {
     320           0 :     Window* pParent = GetDialogParent();
     321           0 :     ScWaitCursorOff aWaitOff( pParent );
     322           0 :     InfoBox( pParent, ScGlobal::GetRscString( STR_SPELLING_STOP_OK ) ).Execute();
     323           0 : }
     324             : 
     325           0 : Window* ScSpellingEngine::GetDialogParent()
     326             : {
     327           0 :     sal_uInt16 nWinId = ScSpellDialogChildWindow::GetChildWindowId();
     328           0 :     SfxViewFrame* pViewFrm = mrViewData.GetViewShell()->GetViewFrame();
     329           0 :     if( pViewFrm->HasChildWindow( nWinId ) )
     330           0 :         if( SfxChildWindow* pChild = pViewFrm->GetChildWindow( nWinId ) )
     331           0 :             if( Window* pWin = pChild->GetWindow() )
     332           0 :                 if( pWin->IsVisible() )
     333           0 :                     return pWin;
     334             : 
     335             :     // fall back to standard dialog parent
     336           0 :     return mrDocShell.GetActiveDialogParent();
     337             : }
     338             : 
     339             : // ============================================================================
     340             : 
     341           0 : ScConversionParam::ScConversionParam( ScConversionType eConvType ) :
     342             :     meConvType( eConvType ),
     343             :     meSourceLang( LANGUAGE_NONE ),
     344             :     meTargetLang( LANGUAGE_NONE ),
     345             :     mnOptions( 0 ),
     346             :     mbUseTargetFont( false ),
     347           0 :     mbIsInteractive( false )
     348             : {
     349           0 : }
     350             : 
     351           0 : ScConversionParam::ScConversionParam( ScConversionType eConvType,
     352             :         LanguageType eLang, sal_Int32 nOptions, bool bIsInteractive ) :
     353             :     meConvType( eConvType ),
     354             :     meSourceLang( eLang ),
     355             :     meTargetLang( eLang ),
     356             :     mnOptions( nOptions ),
     357             :     mbUseTargetFont( false ),
     358           0 :     mbIsInteractive( bIsInteractive )
     359             : {
     360           0 :     if (LANGUAGE_KOREAN == eLang)
     361           0 :         mnOptions = i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
     362           0 : }
     363             : 
     364           0 : ScConversionParam::ScConversionParam( ScConversionType eConvType,
     365             :         LanguageType eSourceLang, LanguageType eTargetLang, const Font& rTargetFont,
     366             :         sal_Int32 nOptions, bool bIsInteractive ) :
     367             :     meConvType( eConvType ),
     368             :     meSourceLang( eSourceLang ),
     369             :     meTargetLang( eTargetLang ),
     370             :     maTargetFont( rTargetFont ),
     371             :     mnOptions( nOptions ),
     372             :     mbUseTargetFont( true ),
     373           0 :     mbIsInteractive( bIsInteractive )
     374             : {
     375           0 :     if (LANGUAGE_KOREAN == meSourceLang && LANGUAGE_KOREAN == meTargetLang)
     376           0 :         mnOptions = i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
     377           0 : }
     378             : 
     379             : // ----------------------------------------------------------------------------
     380             : 
     381           0 : ScTextConversionEngine::ScTextConversionEngine(
     382             :         SfxItemPool* pEnginePoolP, ScViewData& rViewData,
     383             :         const ScConversionParam& rConvParam,
     384             :         ScDocument* pUndoDoc, ScDocument* pRedoDoc ) :
     385             :     ScConversionEngineBase( pEnginePoolP, rViewData, pUndoDoc, pRedoDoc ),
     386           0 :     maConvParam( rConvParam )
     387             : {
     388           0 : }
     389             : 
     390           0 : void ScTextConversionEngine::ConvertAll( EditView& rEditView )
     391             : {
     392           0 :     if( FindNextConversionCell() )
     393             :     {
     394             :         rEditView.StartTextConversion(
     395           0 :             maConvParam.GetSourceLang(), maConvParam.GetTargetLang(), maConvParam.GetTargetFont(),
     396           0 :             maConvParam.GetOptions(), maConvParam.IsInteractive(), sal_True );
     397             :         // #i34769# restore initial cursor position
     398           0 :         RestoreCursorPos();
     399             :     }
     400           0 : }
     401             : 
     402           0 : sal_Bool ScTextConversionEngine::ConvertNextDocument()
     403             : {
     404           0 :     return FindNextConversionCell();
     405             : }
     406             : 
     407           0 : bool ScTextConversionEngine::NeedsConversion()
     408             : {
     409           0 :     return HasConvertibleTextPortion( maConvParam.GetSourceLang() );
     410          93 : }
     411             : 
     412             : // ============================================================================
     413             : 
     414             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10