LCOV - code coverage report
Current view: top level - sc/source/ui/view - spelldialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 126 0.8 %
Date: 2012-08-25 Functions: 2 15 13.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 238 0.4 %

           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 "spelldialog.hxx"
      30                 :            : 
      31                 :            : #include <sfx2/app.hxx>
      32                 :            : #include <sfx2/bindings.hxx>
      33                 :            : #include <sfx2/dispatch.hxx>
      34                 :            : #include <svx/svxids.hrc>
      35                 :            : #include <editeng/editstat.hxx>
      36                 :            : #include <editeng/editview.hxx>
      37                 :            : #include <editeng/unolingu.hxx>
      38                 :            : #include "selectionstate.hxx"
      39                 :            : 
      40                 :            : #include "spelleng.hxx"
      41                 :            : #include "tabvwsh.hxx"
      42                 :            : #include "docsh.hxx"
      43                 :            : #include "scmod.hxx"
      44                 :            : #include "editable.hxx"
      45                 :            : #include "undoblk.hxx"
      46                 :            : 
      47                 :            : // ============================================================================
      48                 :            : 
      49 [ +  - ][ #  # ]:        102 : SFX_IMPL_CHILDWINDOW_WITHID( ScSpellDialogChildWindow, SID_SPELL_DIALOG )
      50                 :            : 
      51                 :          0 : ScSpellDialogChildWindow::ScSpellDialogChildWindow( Window* pParentP, sal_uInt16 nId,
      52                 :            :         SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
      53                 :            :     ::svx::SpellDialogChildWindow( pParentP, nId, pBindings, pInfo ),
      54                 :            :     mpViewShell( 0 ),
      55                 :            :     mpViewData( 0 ),
      56                 :            :     mpDocShell( 0 ),
      57                 :            :     mpDoc( 0 ),
      58                 :            :     mbNeedNextObj( false ),
      59                 :          0 :     mbOldIdleDisabled( false )
      60                 :            : {
      61         [ #  # ]:          0 :     Init();
      62                 :          0 : }
      63                 :            : 
      64 [ #  # ][ #  # ]:          0 : ScSpellDialogChildWindow::~ScSpellDialogChildWindow()
         [ #  # ][ #  # ]
                 [ #  # ]
      65                 :            : {
      66         [ #  # ]:          0 :     Reset();
      67         [ #  # ]:          0 : }
      68                 :            : 
      69                 :          0 : SfxChildWinInfo ScSpellDialogChildWindow::GetInfo() const
      70                 :            : {
      71                 :          0 :     return ::svx::SpellDialogChildWindow::GetInfo();
      72                 :            : }
      73                 :            : 
      74                 :          0 : void ScSpellDialogChildWindow::InvalidateSpellDialog()
      75                 :            : {
      76                 :          0 :     ::svx::SpellDialogChildWindow::InvalidateSpellDialog();
      77                 :          0 : }
      78                 :            : 
      79                 :            : // protected ------------------------------------------------------------------
      80                 :            : 
      81                 :          0 : ::svx::SpellPortions ScSpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ )
      82                 :            : {
      83                 :          0 :     ::svx::SpellPortions aPortions;
      84 [ #  # ][ #  # ]:          0 :     if( mxEngine.get() && mpViewData )
                 [ #  # ]
      85                 :            :     {
      86         [ #  # ]:          0 :         if( EditView* pEditView = mpViewData->GetSpellingView() )
      87                 :            :         {
      88                 :            :             // edit engine handles cell iteration internally
      89         [ #  # ]:          0 :             do
      90                 :            :             {
      91         [ #  # ]:          0 :                 if( mbNeedNextObj )
      92         [ #  # ]:          0 :                     mxEngine->SpellNextDocument();
      93 [ #  # ][ #  # ]:          0 :                 mbNeedNextObj = !mxEngine->IsFinished() && !mxEngine->SpellSentence( *pEditView, aPortions, false );
                 [ #  # ]
      94                 :            :             }
      95                 :            :             while( mbNeedNextObj );
      96                 :            :         }
      97                 :            : 
      98                 :            :         // finished? - close the spelling dialog
      99         [ #  # ]:          0 :         if( mxEngine->IsFinished() )
     100 [ #  # ][ #  # ]:          0 :             GetBindings().GetDispatcher()->Execute( SID_SPELL_DIALOG, SFX_CALLMODE_ASYNCHRON );
     101                 :            :     }
     102                 :          0 :     return aPortions;
     103                 :            : }
     104                 :            : 
     105                 :          0 : void ScSpellDialogChildWindow::ApplyChangedSentence( const ::svx::SpellPortions& rChanged, bool bRecheck )
     106                 :            : {
     107 [ #  # ][ #  # ]:          0 :     if( mxEngine.get() && mpViewData )
                 [ #  # ]
     108         [ #  # ]:          0 :         if( EditView* pEditView = mpViewData->GetSpellingView() )
     109                 :          0 :             mxEngine->ApplyChangedSentence( *pEditView, rChanged, bRecheck );
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : void ScSpellDialogChildWindow::GetFocus()
     113                 :            : {
     114         [ #  # ]:          0 :     if( IsSelectionChanged() )
     115                 :            :     {
     116                 :          0 :         Reset();
     117                 :          0 :         InvalidateSpellDialog();
     118                 :          0 :         Init();
     119                 :            :     }
     120                 :          0 : }
     121                 :            : 
     122                 :          0 : void ScSpellDialogChildWindow::LoseFocus()
     123                 :            : {
     124                 :          0 : }
     125                 :            : 
     126                 :            : // private --------------------------------------------------------------------
     127                 :            : 
     128                 :          0 : void ScSpellDialogChildWindow::Reset()
     129                 :            : {
     130 [ #  # ][ #  # ]:          0 :     if( mpViewShell && (mpViewShell == PTR_CAST( ScTabViewShell, SfxViewShell::Current() )) )
         [ #  # ][ #  # ]
                 [ #  # ]
     131                 :            :     {
     132 [ #  # ][ #  # ]:          0 :         if( mxEngine.get() && mxEngine->IsAnyModified() )
                 [ #  # ]
     133                 :            :         {
     134                 :          0 :             const ScAddress& rCursor = mxOldSel->GetCellCursor();
     135                 :          0 :             SCTAB nTab = rCursor.Tab();
     136                 :          0 :             SCCOL nOldCol = rCursor.Col();
     137                 :          0 :             SCROW nOldRow = rCursor.Row();
     138                 :          0 :             SCCOL nNewCol = mpViewData->GetCurX();
     139                 :          0 :             SCROW nNewRow = mpViewData->GetCurY();
     140                 :          0 :             mpDocShell->GetUndoManager()->AddUndoAction( new ScUndoConversion(
     141                 :          0 :                 mpDocShell, mpViewData->GetMarkData(),
     142                 :          0 :                 nOldCol, nOldRow, nTab, mxUndoDoc.release(),
     143                 :          0 :                 nNewCol, nNewRow, nTab, mxRedoDoc.release(),
     144 [ #  # ][ #  # ]:          0 :                 ScConversionParam( SC_CONVERSION_SPELLCHECK ) ) );
                 [ #  # ]
     145                 :          0 :             mpDoc->SetDirty();
     146                 :          0 :             mpDocShell->SetDocumentModified();
     147                 :            :         }
     148                 :            : 
     149                 :          0 :         mpViewData->SetSpellingView( 0 );
     150                 :          0 :         mpViewShell->KillEditView( sal_True );
     151                 :          0 :         mpDocShell->PostPaintGridAll();
     152                 :          0 :         mpViewShell->UpdateInputHandler();
     153                 :          0 :         mpDoc->DisableIdle( mbOldIdleDisabled );
     154                 :            :     }
     155                 :          0 :     mxEngine.reset();
     156                 :          0 :     mxUndoDoc.reset();
     157                 :          0 :     mxRedoDoc.reset();
     158                 :          0 :     mxOldSel.reset();
     159                 :          0 :     mxOldRangeList.reset();
     160                 :          0 :     mpViewShell = 0;
     161                 :          0 :     mpViewData = 0;
     162                 :          0 :     mpDocShell = 0;
     163                 :          0 :     mpDoc = 0;
     164                 :          0 :     mbNeedNextObj = false;
     165                 :          0 :     mbOldIdleDisabled = false;
     166                 :          0 : }
     167                 :            : 
     168                 :          0 : void ScSpellDialogChildWindow::Init()
     169                 :            : {
     170         [ #  # ]:          0 :     if( mpViewShell )
     171                 :            :         return;
     172 [ #  # ][ #  # ]:          0 :     if( (mpViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() )) == 0 )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     173                 :            :         return;
     174                 :            : 
     175                 :          0 :     mpViewData = mpViewShell->GetViewData();
     176                 :            : 
     177                 :            :     // exit edit mode - TODO support spelling in edit mode
     178         [ #  # ]:          0 :     if( mpViewData->HasEditView( mpViewData->GetActivePart() ) )
     179 [ #  # ][ #  # ]:          0 :         SC_MOD()->InputEnterHandler();
     180                 :            : 
     181 [ #  # ][ #  # ]:          0 :     mxOldSel.reset( new ScSelectionState( *mpViewData ) );
     182                 :            : 
     183                 :          0 :     mpDocShell = mpViewData->GetDocShell();
     184                 :          0 :     mpDoc = mpDocShell->GetDocument();
     185                 :            : 
     186                 :          0 :     const ScAddress& rCursor = mxOldSel->GetCellCursor();
     187                 :          0 :     SCCOL nCol = rCursor.Col();
     188                 :          0 :     SCROW nRow = rCursor.Row();
     189                 :          0 :     SCTAB nTab = rCursor.Tab();
     190                 :            : 
     191         [ #  # ]:          0 :     ScMarkData& rMarkData = mpViewData->GetMarkData();
     192                 :            : 
     193 [ #  # ][ #  # ]:          0 :     mxOldRangeList.reset(new ScRangeList);
     194         [ #  # ]:          0 :     rMarkData.FillRangeListWithMarks(mxOldRangeList.get(), true);
     195                 :            : 
     196         [ #  # ]:          0 :     rMarkData.MarkToMulti();
     197                 :            : 
     198         [ #  # ]:          0 :     switch( mxOldSel->GetSelectionType() )
     199                 :            :     {
     200                 :            :         case SC_SELECTTYPE_NONE:
     201                 :            :         case SC_SELECTTYPE_SHEET:
     202                 :            :         {
     203                 :            :             // test if there is something editable
     204         [ #  # ]:          0 :             ScEditableTester aTester( mpDoc, rMarkData );
     205         [ #  # ]:          0 :             if( !aTester.IsEditable() )
     206                 :            :             {
     207                 :            :                 // #i85751# Don't show a ErrorMessage here, because the vcl
     208                 :            :                 // parent of the InfoBox is not fully initialized yet.
     209                 :            :                 // This leads to problems in the modality behaviour of the
     210                 :            :                 // ScSpellDialogChildWindow.
     211                 :            : 
     212                 :            :                 //mpViewShell->ErrorMessage( aTester.GetMessageId() );
     213                 :            :                 return;
     214         [ #  # ]:          0 :             }
     215                 :            :         }
     216                 :          0 :         break;
     217                 :            : 
     218                 :            :         // edit mode exited, see TODO above
     219                 :            : //        case SC_SELECTTYPE_EDITCELL:
     220                 :            : //        break;
     221                 :            : 
     222                 :            :         default:
     223                 :            :             OSL_FAIL( "ScSpellDialogChildWindow::Init - unknown selection type" );
     224                 :            :     }
     225                 :            : 
     226                 :          0 :     mbOldIdleDisabled = mpDoc->IsIdleDisabled();
     227                 :          0 :     mpDoc->DisableIdle( true );   // stop online spelling
     228                 :            : 
     229                 :            :     // *** create Undo/Redo documents *** -------------------------------------
     230                 :            : 
     231 [ #  # ][ #  # ]:          0 :     mxUndoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
     232         [ #  # ]:          0 :     mxUndoDoc->InitUndo( mpDoc, nTab, nTab );
     233 [ #  # ][ #  # ]:          0 :     mxRedoDoc.reset( new ScDocument( SCDOCMODE_UNDO ) );
     234         [ #  # ]:          0 :     mxRedoDoc->InitUndo( mpDoc, nTab, nTab );
     235                 :            : 
     236 [ #  # ][ #  # ]:          0 :     if ( rMarkData.GetSelectCount() > 1 )
     237                 :            :     {
     238 [ #  # ][ #  # ]:          0 :         ScMarkData::iterator itr = rMarkData.begin(), itrEnd = rMarkData.end();
     239 [ #  # ][ #  # ]:          0 :         for (; itr != itrEnd; ++itr)
                 [ #  # ]
     240                 :            :         {
     241 [ #  # ][ #  # ]:          0 :             if( *itr != nTab )
     242                 :            :             {
     243 [ #  # ][ #  # ]:          0 :                 mxUndoDoc->AddUndoTab( *itr, *itr );
                 [ #  # ]
     244 [ #  # ][ #  # ]:          0 :                 mxRedoDoc->AddUndoTab( *itr, *itr );
                 [ #  # ]
     245                 :            :             }
     246                 :            :         }
     247                 :            :     }
     248                 :            : 
     249                 :            :     // *** create and init the edit engine *** --------------------------------
     250                 :            : 
     251                 :            :     mxEngine.reset( new ScSpellingEngine(
     252 [ #  # ][ #  # ]:          0 :         mpDoc->GetEnginePool(), *mpViewData, mxUndoDoc.get(), mxRedoDoc.get(), LinguMgr::GetSpellChecker() ) );
         [ #  # ][ #  # ]
     253 [ #  # ][ #  # ]:          0 :     mxEngine->SetRefDevice( mpViewData->GetActiveWin() );
     254                 :            : 
     255         [ #  # ]:          0 :     mpViewShell->MakeEditView( mxEngine.get(), nCol, nRow );
     256                 :          0 :     EditView* pEditView = mpViewData->GetEditView( mpViewData->GetActivePart() );
     257                 :          0 :     mpViewData->SetSpellingView( pEditView );
     258         [ #  # ]:          0 :     Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
     259         [ #  # ]:          0 :     pEditView->SetOutputArea( aRect );
     260         [ #  # ]:          0 :     mxEngine->SetControlWord( EE_CNTRL_USECHARATTRIBS );
     261         [ #  # ]:          0 :     mxEngine->EnableUndo( false );
     262 [ #  # ][ #  # ]:          0 :     mxEngine->SetPaperSize( aRect.GetSize() );
     263 [ #  # ][ #  # ]:          0 :     mxEngine->SetText( EMPTY_STRING );
     264         [ #  # ]:          0 :     mxEngine->ClearModifyFlag();
     265                 :            : 
     266                 :          0 :     mbNeedNextObj = true;
     267                 :            : }
     268                 :            : 
     269                 :          0 : bool ScSpellDialogChildWindow::IsSelectionChanged()
     270                 :            : {
     271 [ #  # ][ #  # ]:          0 :     if( !mxOldRangeList.get() || !mpViewShell || (mpViewShell != PTR_CAST( ScTabViewShell, SfxViewShell::Current() )) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     272                 :          0 :         return true;
     273                 :            : 
     274         [ #  # ]:          0 :     if( EditView* pEditView = mpViewData->GetSpellingView() )
     275 [ #  # ][ #  # ]:          0 :         if( pEditView->GetEditEngine() != mxEngine.get() )
                 [ #  # ]
     276                 :          0 :             return true;
     277                 :            : 
     278         [ #  # ]:          0 :     ScRangeList aCurrentRangeList;
     279 [ #  # ][ #  # ]:          0 :     mpViewData->GetMarkData().FillRangeListWithMarks(&aCurrentRangeList, true);
     280                 :            : 
     281 [ #  # ][ #  # ]:          0 :     return (*mxOldRangeList != aCurrentRangeList);
     282                 :            : }
     283                 :            : 
     284                 :            : // ============================================================================
     285                 :            : 
     286                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10