LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/dialog - SwSpellDialogChildWindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 379 0.3 %
Date: 2012-12-27 Functions: 2 26 7.7 %
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             : 
      21             : #include <SwSpellDialogChildWindow.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <editeng/svxacorr.hxx>
      24             : #include <editeng/acorrcfg.hxx>
      25             : #include <svx/svxids.hrc>
      26             : #include <sfx2/app.hxx>
      27             : #include <sfx2/bindings.hxx>
      28             : #include <sfx2/dispatch.hxx>
      29             : #include <editeng/unolingu.hxx>
      30             : #include <editeng/editeng.hxx>
      31             : #include <editeng/editview.hxx>
      32             : #include <wrtsh.hxx>
      33             : #include <sfx2/printer.hxx>
      34             : #include <svx/svdoutl.hxx>
      35             : #include <svx/svdview.hxx>
      36             : #include <svx/svditer.hxx>
      37             : #include <svx/svdogrp.hxx>
      38             : #include <unotools/linguprops.hxx>
      39             : #include <unotools/lingucfg.hxx>
      40             : #include <doc.hxx>
      41             : #include <docsh.hxx>
      42             : #include <docary.hxx>
      43             : #include <frmfmt.hxx>
      44             : #include <dcontact.hxx>
      45             : #include <edtwin.hxx>
      46             : #include <pam.hxx>
      47             : #include <drawbase.hxx>
      48             : #include <unotextrange.hxx>
      49             : #include <dialog.hrc>
      50             : #include <cmdid.h>
      51             : 
      52             : 
      53             : using namespace ::com::sun::star;
      54             : using namespace ::com::sun::star::uno;
      55             : using namespace ::com::sun::star::text;
      56             : using namespace ::com::sun::star::linguistic2;
      57             : using namespace ::com::sun::star::beans;
      58             : 
      59          20 : SFX_IMPL_CHILDWINDOW_WITHID(SwSpellDialogChildWindow, FN_SPELL_GRAMMAR_DIALOG)
      60             : 
      61             : 
      62             : #define SPELL_START_BODY        0   // body text area
      63             : #define SPELL_START_OTHER       1   // frame, footnote, header, footer
      64             : #define SPELL_START_DRAWTEXT    2   // started in a draw text object
      65             : 
      66             : struct SpellState
      67             : {
      68             :     bool                m_bInitialCall;
      69             :     bool                m_bLockFocus; //lock the focus notification while a modal dialog is active
      70             :     bool                m_bLostFocus;
      71             : 
      72             :     //restart and progress information
      73             :     sal_uInt16              m_SpellStartPosition;
      74             :     bool                m_bBodySpelled;  //body already spelled
      75             :     bool                m_bOtherSpelled; //frames, footnotes, headers and footers spelled
      76             :     bool                m_bStartedInOther; //started the spelling insided of the _other_ area
      77             :     bool                m_bStartedInSelection; // there was an initial text selection
      78             :     SwPaM*              pOtherCursor; // position where the spelling inside the _other_ area started
      79             :     bool                m_bDrawingsSpelled; //all drawings spelled
      80             :     Reference<XTextRange> m_xStartRange; //text range that marks the start of spelling
      81             :     const SdrObject*    m_pStartDrawing; //draw text object spelling started in
      82             :     ESelection          m_aStartDrawingSelection; //draw text start selection
      83             :     bool                m_bRestartDrawing; // the first selected drawing object is found again
      84             : 
      85             :     //lose/get focus information to decide if spelling can be continued
      86             :     ShellModes          m_eSelMode;
      87             :     const SwNode*       m_pPointNode;
      88             :     const SwNode*       m_pMarkNode;
      89             :     xub_StrLen          m_nPointPos;
      90             :     xub_StrLen          m_nMarkPos;
      91             :     const SdrOutliner*  m_pOutliner;
      92             :     ESelection          m_aESelection;
      93             : 
      94             :     //iterating over draw text objects
      95             :     std::list<SdrTextObj*> m_aTextObjects;
      96             :     bool                m_bTextObjectsCollected;
      97             : 
      98           0 :     SpellState() :
      99             :         m_bInitialCall(true),
     100             :         m_bLockFocus(false),
     101             :         m_bLostFocus(false),
     102             :         m_SpellStartPosition(SPELL_START_BODY),
     103             :         m_bBodySpelled(false),
     104             :         m_bOtherSpelled(false),
     105             :         m_bStartedInOther(false),
     106             :         m_bStartedInSelection(false),
     107             :         pOtherCursor(0),
     108             :         m_bDrawingsSpelled(false),
     109             :         m_pStartDrawing(0),
     110             :         m_bRestartDrawing(false),
     111             : 
     112             :         m_eSelMode(SHELL_MODE_OBJECT), //initially invalid
     113             :         m_pPointNode(0),
     114             :         m_pMarkNode(0),
     115             :         m_nPointPos(0),
     116             :         m_nMarkPos(0),
     117             :         m_pOutliner(0),
     118           0 :         m_bTextObjectsCollected(false)
     119           0 :         {}
     120             : 
     121           0 :     ~SpellState() {delete pOtherCursor;}
     122             : 
     123             :     // reset state in ::InvalidateSpellDialog
     124           0 :     void    Reset()
     125           0 :             {   m_bInitialCall = true;
     126           0 :                 m_bBodySpelled = m_bOtherSpelled = m_bDrawingsSpelled = false;
     127           0 :                 m_xStartRange = 0;
     128           0 :                 m_pStartDrawing = 0;
     129           0 :                 m_bRestartDrawing = false;
     130           0 :                 m_bTextObjectsCollected = false;
     131           0 :                 m_aTextObjects.clear();
     132           0 :                 m_bStartedInOther = false;
     133           0 :                 delete pOtherCursor;
     134           0 :                 pOtherCursor = 0;
     135           0 :             }
     136             : };
     137             : 
     138           0 : static void lcl_LeaveDrawText(SwWrtShell& rSh)
     139             : {
     140           0 :     if(rSh.GetDrawView())
     141             :     {
     142           0 :         rSh.GetDrawView()->SdrEndTextEdit( sal_True );
     143           0 :         Point aPt(LONG_MIN, LONG_MIN);
     144             :         //go out of the frame
     145           0 :         rSh.SelectObj(aPt, SW_LEAVE_FRAME);
     146           0 :         rSh.EnterStdMode();
     147           0 :         rSh.GetView().AttrChangedNotify(&rSh);
     148             :     }
     149           0 : }
     150             : 
     151           0 : SwSpellDialogChildWindow::SwSpellDialogChildWindow (
     152             :             Window* _pParent,
     153             :             sal_uInt16 nId,
     154             :             SfxBindings* pBindings,
     155             :             SfxChildWinInfo* pInfo) :
     156             :                 svx::SpellDialogChildWindow (
     157             :                     _pParent, nId, pBindings, pInfo),
     158           0 :                     m_pSpellState(new SpellState)
     159             : {
     160           0 :     rtl::OUString aPropName(UPN_IS_GRAMMAR_INTERACTIVE);
     161           0 :     SvtLinguConfig().GetProperty( aPropName ) >>= m_bIsGrammarCheckingOn;
     162           0 : }
     163             : 
     164           0 : SwSpellDialogChildWindow::~SwSpellDialogChildWindow ()
     165             : {
     166           0 :     SwWrtShell* pWrtShell = GetWrtShell_Impl();
     167           0 :     if(!m_pSpellState->m_bInitialCall && pWrtShell)
     168           0 :         pWrtShell->SpellEnd();
     169           0 :     delete m_pSpellState;
     170           0 : }
     171             : 
     172             : 
     173           0 : SfxChildWinInfo SwSpellDialogChildWindow::GetInfo (void) const
     174             : {
     175           0 :     SfxChildWinInfo aInfo = svx::SpellDialogChildWindow::GetInfo();
     176           0 :     aInfo.bVisible = sal_False;
     177           0 :     return aInfo;
     178             : }
     179             : 
     180             : 
     181           0 : svx::SpellPortions SwSpellDialogChildWindow::GetNextWrongSentence(bool bRecheck)
     182             : {
     183           0 :     svx::SpellPortions aRet;
     184           0 :     SwWrtShell* pWrtShell = GetWrtShell_Impl();
     185           0 :     if(pWrtShell)
     186             :     {
     187           0 :         if (!bRecheck)
     188             :         {
     189             :             // first set continuation point for spell/grammar check to the
     190             :             // end of the current sentence
     191           0 :             pWrtShell->MoveContinuationPosToEndOfCheckedSentence();
     192             :         }
     193             : 
     194           0 :         ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
     195           0 :         bool bDrawText = SHELL_MODE_DRAWTEXT == eSelMode;
     196             :         bool bNormalText =
     197             :             SHELL_MODE_TABLE_TEXT == eSelMode ||
     198             :             SHELL_MODE_LIST_TEXT == eSelMode ||
     199             :             SHELL_MODE_TABLE_LIST_TEXT == eSelMode ||
     200           0 :             SHELL_MODE_TEXT == eSelMode;
     201             :         //Writer text outside of the body
     202           0 :         bool bOtherText = false;
     203             : 
     204           0 :         if( m_pSpellState->m_bInitialCall )
     205             :         {
     206             :             //if no text selection exists the cursor has to be set into the text
     207           0 :             if(!bDrawText && !bNormalText)
     208             :             {
     209           0 :                 if(!MakeTextSelection_Impl(*pWrtShell, eSelMode))
     210           0 :                     return aRet;
     211             :                 else
     212             :                 {
     213             :                     // the selection type has to be checked again - both text types are possible
     214           0 :                     if(0 != (pWrtShell->GetSelectionType()& nsSelectionType::SEL_DRW_TXT))
     215           0 :                         bDrawText = true;
     216           0 :                     bNormalText = !bDrawText;
     217             :                 }
     218             :             }
     219           0 :             if(bNormalText)
     220             :             {
     221             :                 //set cursor to the start of the sentence
     222           0 :                 if(!pWrtShell->HasSelection())
     223           0 :                     pWrtShell->GoStartSentence();
     224             :                 else
     225             :                 {
     226           0 :                     pWrtShell->ExpandToSentenceBorders();
     227           0 :                     m_pSpellState->m_bStartedInSelection = true;
     228             :                 }
     229             :                 //determine if the selection is outside of the body text
     230           0 :                 bOtherText = !(pWrtShell->GetFrmType(0,sal_True) & FRMTYPE_BODY);
     231           0 :                 m_pSpellState->m_SpellStartPosition = bOtherText ? SPELL_START_OTHER : SPELL_START_BODY;
     232           0 :                 if(bOtherText)
     233             :                 {
     234           0 :                     m_pSpellState->pOtherCursor = new SwPaM(*pWrtShell->GetCrsr()->GetPoint());
     235           0 :                     m_pSpellState->m_bStartedInOther = true;
     236           0 :                     pWrtShell->SpellStart( DOCPOS_OTHERSTART, DOCPOS_OTHEREND, DOCPOS_CURR );
     237             :                 }
     238             :                 else
     239             :                 {
     240           0 :                     SwPaM* pCrsr = pWrtShell->GetCrsr();
     241             :                     //mark the start position only if not at start of doc
     242           0 :                     if(!pWrtShell->IsStartOfDoc())
     243             :                     {
     244             :                         m_pSpellState->m_xStartRange =
     245             :                             SwXTextRange::CreateXTextRange(
     246           0 :                                 *pWrtShell->GetDoc(),
     247           0 :                                 *pCrsr->Start(), pCrsr->End());
     248             :                     }
     249           0 :                     pWrtShell->SpellStart( DOCPOS_START, DOCPOS_END, DOCPOS_CURR );
     250             :                 }
     251             :             }
     252             :             else
     253             :             {
     254           0 :                 SdrView* pSdrView = pWrtShell->GetDrawView();
     255           0 :                 m_pSpellState->m_SpellStartPosition = SPELL_START_DRAWTEXT;
     256           0 :                 m_pSpellState->m_pStartDrawing = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
     257           0 :                 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
     258             :                 // start checking at the top of the drawing object
     259           0 :                 pOLV->SetSelection( ESelection() );
     260           0 :                 m_pSpellState->m_aStartDrawingSelection = ESelection();
     261             : /*
     262             : Note: spelling in a selection only, or starting in a mid of a drawing object requires
     263             : further changes elsewhere. (Especially if it should work in sc and sd as well.)
     264             : The code below would only be part of the solution.
     265             : (Keeping it a as a comment for the time being)
     266             :                 ESelection aCurSel( pOLV->GetSelection() );
     267             :                 ESelection aSentenceSel( pOLV->GetEditView().GetEditEngine()->SelectSentence( aCurSel ) );
     268             :                 if (!aCurSel.HasRange())
     269             :                 {
     270             :                     aSentenceSel.nEndPara = aSentenceSel.nStartPara;
     271             :                     aSentenceSel.nEndPos  = aSentenceSel.nStartPos;
     272             :                 }
     273             :                 pOLV->SetSelection( aSentenceSel );
     274             :                 m_pSpellState->m_aStartDrawingSelection = aSentenceSel;
     275             : */
     276             :             }
     277             : 
     278           0 :             m_pSpellState->m_bInitialCall = false;
     279             :         }
     280           0 :         if( bDrawText )
     281             :         {
     282             :             // spell inside of the current draw text
     283           0 :             if(!SpellDrawText_Impl(*pWrtShell, aRet))
     284             :             {
     285           0 :                 if(!FindNextDrawTextError_Impl(*pWrtShell) || !SpellDrawText_Impl(*pWrtShell, aRet))
     286             :                 {
     287           0 :                     lcl_LeaveDrawText(*pWrtShell);
     288             :                     //now the drawings have been spelled
     289           0 :                     m_pSpellState->m_bDrawingsSpelled = true;
     290             :                     //the spelling continues at the other content
     291             :                     //if there's any that has not been spelled yet
     292           0 :                     if(!m_pSpellState->m_bOtherSpelled && pWrtShell->HasOtherCnt())
     293             :                     {
     294           0 :                         pWrtShell->SpellStart(DOCPOS_OTHERSTART, DOCPOS_OTHEREND, DOCPOS_OTHERSTART );
     295           0 :                         if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
     296             :                         {
     297           0 :                             pWrtShell->SpellEnd();
     298           0 :                             m_pSpellState->m_bOtherSpelled = true;
     299             :                         }
     300             :                     }
     301             :                     else
     302           0 :                         m_pSpellState->m_bOtherSpelled = true;
     303             :                     //if no result has been found try at the body text - completely
     304           0 :                     if(!m_pSpellState->m_bBodySpelled && !aRet.size())
     305             :                     {
     306           0 :                         pWrtShell->SpellStart(DOCPOS_START, DOCPOS_END, DOCPOS_START );
     307           0 :                         if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
     308             :                         {
     309           0 :                             m_pSpellState->m_bBodySpelled = true;
     310           0 :                             pWrtShell->SpellEnd();
     311             :                         }
     312             :                     }
     313             : 
     314             :                 }
     315             :             }
     316             :         }
     317             :         else
     318             :         {
     319             :             //spell inside of the Writer text
     320           0 :             if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
     321             :             {
     322             :                 // if there is a selection (within body or header/footer text)
     323             :                 // then spell/grammar checking should not move outside of it.
     324           0 :                 if (!m_pSpellState->m_bStartedInSelection)
     325             :                 {
     326             :                     //find out which text has been spelled body or other
     327           0 :                     bOtherText = !(pWrtShell->GetFrmType(0,sal_True) & FRMTYPE_BODY);
     328           0 :                     if(bOtherText && m_pSpellState->m_bStartedInOther && m_pSpellState->pOtherCursor)
     329             :                     {
     330           0 :                         m_pSpellState->m_bStartedInOther = false;
     331           0 :                         pWrtShell->SetSelection(*m_pSpellState->pOtherCursor);
     332           0 :                         pWrtShell->SpellEnd();
     333           0 :                         delete m_pSpellState->pOtherCursor;
     334           0 :                         m_pSpellState->pOtherCursor = 0;
     335           0 :                         pWrtShell->SpellStart(DOCPOS_OTHERSTART, DOCPOS_CURR, DOCPOS_OTHERSTART );
     336           0 :                         pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn);
     337             :                     }
     338           0 :                     if(!aRet.size())
     339             :                     {
     340             :                         //end spelling
     341           0 :                         pWrtShell->SpellEnd();
     342           0 :                         if(bOtherText)
     343             :                         {
     344           0 :                             m_pSpellState->m_bOtherSpelled = true;
     345             :                             //has the body been spelled?
     346           0 :                             if(!m_pSpellState->m_bBodySpelled)
     347             :                             {
     348           0 :                                 pWrtShell->SpellStart(DOCPOS_START, DOCPOS_END, DOCPOS_START );
     349           0 :                                 if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
     350             :                                 {
     351           0 :                                     m_pSpellState->m_bBodySpelled = true;
     352           0 :                                     pWrtShell->SpellEnd();
     353             :                                 }
     354             :                             }
     355             :                         }
     356             :                         else
     357             :                         {
     358           0 :                              m_pSpellState->m_bBodySpelled = true;
     359           0 :                              if(!m_pSpellState->m_bOtherSpelled && pWrtShell->HasOtherCnt())
     360             :                              {
     361           0 :                                 pWrtShell->SpellStart(DOCPOS_OTHERSTART, DOCPOS_OTHEREND, DOCPOS_OTHERSTART );
     362           0 :                                 if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
     363             :                                 {
     364           0 :                                     pWrtShell->SpellEnd();
     365           0 :                                     m_pSpellState->m_bOtherSpelled = true;
     366             :                                 }
     367             :                              }
     368             :                              else
     369           0 :                                  m_pSpellState->m_bOtherSpelled = true;
     370             :                         }
     371             :                     }
     372             : 
     373             :                     //search for a draw text object that contains error and spell it
     374           0 :                     if(!aRet.size() &&
     375             :                             (m_pSpellState->m_bDrawingsSpelled ||
     376           0 :                             !FindNextDrawTextError_Impl(*pWrtShell) || !SpellDrawText_Impl(*pWrtShell, aRet)))
     377             :                     {
     378           0 :                         lcl_LeaveDrawText(*pWrtShell);
     379           0 :                         m_pSpellState->m_bDrawingsSpelled = true;
     380             :                     }
     381             :                 }
     382             :             }
     383             :         }
     384             :         // now only the rest of the body text can be spelled -
     385             :         // if the spelling started inside of the body
     386             :         //
     387           0 :         bool bCloseMessage = true;
     388           0 :         if(!aRet.size() && !m_pSpellState->m_bStartedInSelection)
     389             :         {
     390             :             OSL_ENSURE(m_pSpellState->m_bDrawingsSpelled &&
     391             :                         m_pSpellState->m_bOtherSpelled && m_pSpellState->m_bBodySpelled,
     392             :                         "not all parts of the document are already spelled");
     393           0 :             if(m_pSpellState->m_xStartRange.is())
     394             :             {
     395           0 :                 LockFocusNotification( true );
     396           0 :                 sal_uInt16 nRet = QueryBox( GetWindow(),  SW_RES(RID_QB_SPELL_CONTINUE)).Execute();
     397           0 :                 if(RET_YES == nRet)
     398             :                 {
     399           0 :                     SwUnoInternalPaM aPam(*pWrtShell->GetDoc());
     400           0 :                     if (::sw::XTextRangeToSwPaM(aPam,
     401           0 :                                 m_pSpellState->m_xStartRange))
     402             :                     {
     403           0 :                         pWrtShell->SetSelection(aPam);
     404           0 :                         pWrtShell->SpellStart(DOCPOS_START, DOCPOS_CURR, DOCPOS_START);
     405           0 :                         if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
     406           0 :                             pWrtShell->SpellEnd();
     407             :                     }
     408           0 :                     m_pSpellState->m_xStartRange = 0;
     409           0 :                     LockFocusNotification( false );
     410             :                     //take care that the now valid selection is stored
     411           0 :                     LoseFocus();
     412             :                 }
     413             :                 else
     414           0 :                     bCloseMessage = false; //no closing message if a wrap around has been denied
     415             :             }
     416             :         }
     417           0 :         if(!aRet.size())
     418             :         {
     419           0 :             if(bCloseMessage)
     420             :             {
     421           0 :                 LockFocusNotification( true );
     422           0 :                 String sInfo(SW_RES(STR_SPELLING_COMPLETED));
     423             :                 //#i84610#
     424           0 :                 Window* pTemp = GetWindow();    // temporary needed for g++ 3.3.5
     425           0 :                 InfoBox(pTemp, sInfo ).Execute();
     426           0 :                 LockFocusNotification( false );
     427             :                 //take care that the now valid selection is stored
     428           0 :                 LoseFocus();
     429             :             }
     430             : 
     431             :             //close the spelling dialog
     432           0 :             GetBindings().GetDispatcher()->Execute(FN_SPELL_GRAMMAR_DIALOG, SFX_CALLMODE_ASYNCHRON);
     433             :         }
     434             :     }
     435           0 :     return aRet;
     436             : 
     437             : }
     438             : 
     439           0 : void SwSpellDialogChildWindow::ApplyChangedSentence(const svx::SpellPortions& rChanged, bool bRecheck)
     440             : {
     441           0 :     SwWrtShell* pWrtShell = GetWrtShell_Impl();
     442             :     OSL_ENSURE(!m_pSpellState->m_bInitialCall, "ApplyChangedSentence in initial call or after resume");
     443           0 :     if(pWrtShell && !m_pSpellState->m_bInitialCall)
     444             :     {
     445           0 :         ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
     446           0 :         bool bDrawText = SHELL_MODE_DRAWTEXT == eSelMode;
     447             :         bool bNormalText =
     448             :             SHELL_MODE_TABLE_TEXT == eSelMode ||
     449             :             SHELL_MODE_LIST_TEXT == eSelMode ||
     450             :             SHELL_MODE_TABLE_LIST_TEXT == eSelMode ||
     451           0 :             SHELL_MODE_TEXT == eSelMode;
     452             : 
     453             :         // evaluate if the same sentence should be rechecked or not.
     454             :         // Sentences that got grammar checked should always be rechecked in order
     455             :         // to detect possible errors that get introduced with the changes
     456           0 :         bRecheck |= pWrtShell->HasLastSentenceGotGrammarChecked();
     457             : 
     458           0 :         if(bNormalText)
     459           0 :             pWrtShell->ApplyChangedSentence(rChanged, bRecheck);
     460           0 :         else if(bDrawText )
     461             :         {
     462           0 :             SdrView* pDrView = pWrtShell->GetDrawView();
     463           0 :             SdrOutliner *pOutliner = pDrView->GetTextEditOutliner();
     464           0 :             pOutliner->ApplyChangedSentence(pDrView->GetTextEditOutlinerView()->GetEditView(), rChanged, bRecheck);
     465             :         }
     466             :     }
     467           0 : }
     468             : 
     469           0 : void SwSpellDialogChildWindow::AddAutoCorrection(
     470             :         const String& rOld, const String& rNew, LanguageType eLanguage)
     471             : {
     472           0 :     SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
     473           0 :     pACorr->PutText( rOld, rNew, eLanguage );
     474           0 : }
     475             : 
     476           0 : bool SwSpellDialogChildWindow::HasAutoCorrection()
     477             : {
     478           0 :     return true;
     479             : }
     480             : 
     481           0 : bool SwSpellDialogChildWindow::HasGrammarChecking()
     482             : {
     483           0 :     return SvtLinguConfig().HasGrammarChecker();
     484             : }
     485             : 
     486           0 : bool SwSpellDialogChildWindow::IsGrammarChecking()
     487             : {
     488           0 :     return m_bIsGrammarCheckingOn;
     489             : }
     490             : 
     491           0 : void SwSpellDialogChildWindow::SetGrammarChecking(bool bOn)
     492             : {
     493           0 :     uno::Any aVal;
     494           0 :     aVal <<= bOn;
     495           0 :     m_bIsGrammarCheckingOn = bOn;
     496           0 :     rtl::OUString aPropName(UPN_IS_GRAMMAR_INTERACTIVE);
     497           0 :     SvtLinguConfig().SetProperty( aPropName, aVal );
     498             :     // set current spell position to the start of the current sentence to
     499             :     // continue with this sentence after grammar checking state has been changed
     500           0 :     SwWrtShell* pWrtShell = GetWrtShell_Impl();
     501           0 :     if(pWrtShell)
     502             :     {
     503           0 :         ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
     504           0 :         bool bDrawText = SHELL_MODE_DRAWTEXT == eSelMode;
     505             :         bool bNormalText =
     506             :             SHELL_MODE_TABLE_TEXT == eSelMode ||
     507             :             SHELL_MODE_LIST_TEXT == eSelMode ||
     508             :             SHELL_MODE_TABLE_LIST_TEXT == eSelMode ||
     509           0 :             SHELL_MODE_TEXT == eSelMode;
     510           0 :         if( bNormalText )
     511           0 :             pWrtShell->PutSpellingToSentenceStart();
     512           0 :         else if( bDrawText )
     513             :         {
     514           0 :             SdrView*     pSdrView = pWrtShell->GetDrawView();
     515           0 :             SdrOutliner* pOutliner = pSdrView ? pSdrView->GetTextEditOutliner() : 0;
     516             :             OSL_ENSURE(pOutliner, "No Outliner in SwSpellDialogChildWindow::SetGrammarChecking");
     517           0 :             if(pOutliner)
     518             :             {
     519           0 :                 pOutliner->PutSpellingToSentenceStart( pSdrView->GetTextEditOutlinerView()->GetEditView() );
     520             :             }
     521             :         }
     522           0 :     }
     523           0 : }
     524             : 
     525           0 : void SwSpellDialogChildWindow::GetFocus()
     526             : {
     527           0 :     if(m_pSpellState->m_bLockFocus)
     528           0 :         return;
     529           0 :     bool bInvalidate = false;
     530           0 :     SwWrtShell* pWrtShell = GetWrtShell_Impl();
     531           0 :     if(pWrtShell && !m_pSpellState->m_bInitialCall)
     532             :     {
     533           0 :         ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
     534           0 :         if(eSelMode != m_pSpellState->m_eSelMode)
     535             :         {
     536             :             //prevent initial invalidation
     537           0 :             if(m_pSpellState->m_bLostFocus)
     538           0 :                 bInvalidate = true;
     539             :         }
     540             :         else
     541             :         {
     542           0 :             switch(m_pSpellState->m_eSelMode)
     543             :             {
     544             :                 case SHELL_MODE_TEXT:
     545             :                 case SHELL_MODE_LIST_TEXT:
     546             :                 case SHELL_MODE_TABLE_TEXT:
     547             :                 case SHELL_MODE_TABLE_LIST_TEXT:
     548             :                 {
     549           0 :                     SwPaM* pCursor = pWrtShell->GetCrsr();
     550           0 :                     if(m_pSpellState->m_pPointNode != pCursor->GetNode(sal_True) ||
     551           0 :                         m_pSpellState->m_pMarkNode != pCursor->GetNode(sal_False)||
     552           0 :                         m_pSpellState->m_nPointPos != pCursor->GetPoint()->nContent.GetIndex()||
     553           0 :                         m_pSpellState->m_nMarkPos != pCursor->GetMark()->nContent.GetIndex())
     554           0 :                             bInvalidate = true;
     555             :                 }
     556           0 :                 break;
     557             :                 case SHELL_MODE_DRAWTEXT:
     558             :                 {
     559           0 :                     SdrView*     pSdrView = pWrtShell->GetDrawView();
     560           0 :                     SdrOutliner* pOutliner = pSdrView ? pSdrView->GetTextEditOutliner() : 0;
     561           0 :                     if(!pOutliner || m_pSpellState->m_pOutliner != pOutliner)
     562           0 :                         bInvalidate = true;
     563             :                     else
     564             :                     {
     565           0 :                         OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
     566             :                         OSL_ENSURE(pOLV, "no OutlinerView in SwSpellDialogChildWindow::GetFocus()");
     567           0 :                         if(!pOLV || !m_pSpellState->m_aESelection.IsEqual(pOLV->GetSelection()))
     568           0 :                             bInvalidate = true;
     569             :                     }
     570             :                 }
     571           0 :                 break;
     572           0 :                 default: bInvalidate = true;
     573             :             }
     574           0 :         }
     575             :     }
     576             :     else
     577             :     {
     578           0 :         bInvalidate = true;
     579             :     }
     580           0 :     if(bInvalidate)
     581           0 :         InvalidateSpellDialog();
     582             : }
     583             : 
     584           0 : void SwSpellDialogChildWindow::LoseFocus()
     585             : {
     586             :     //prevent initial invalidation
     587           0 :     m_pSpellState->m_bLostFocus = true;
     588           0 :     if(m_pSpellState->m_bLockFocus)
     589           0 :         return;
     590           0 :     SwWrtShell* pWrtShell = GetWrtShell_Impl();
     591           0 :     if(pWrtShell)
     592             :     {
     593           0 :         m_pSpellState->m_eSelMode = pWrtShell->GetView().GetShellMode();
     594           0 :         m_pSpellState->m_pPointNode = m_pSpellState->m_pMarkNode = 0;
     595           0 :         m_pSpellState->m_nPointPos = m_pSpellState->m_nMarkPos = 0;
     596           0 :         m_pSpellState->m_pOutliner = 0;
     597             : 
     598           0 :         switch(m_pSpellState->m_eSelMode)
     599             :         {
     600             :             case SHELL_MODE_TEXT:
     601             :             case SHELL_MODE_LIST_TEXT:
     602             :             case SHELL_MODE_TABLE_TEXT:
     603             :             case SHELL_MODE_TABLE_LIST_TEXT:
     604             :             {
     605             :                 //store a node pointer and a pam-position to be able to check on next GetFocus();
     606           0 :                 SwPaM* pCursor = pWrtShell->GetCrsr();
     607           0 :                 m_pSpellState->m_pPointNode = pCursor->GetNode(sal_True);
     608           0 :                 m_pSpellState->m_pMarkNode = pCursor->GetNode(sal_False);
     609           0 :                 m_pSpellState->m_nPointPos = pCursor->GetPoint()->nContent.GetIndex();
     610           0 :                 m_pSpellState->m_nMarkPos = pCursor->GetMark()->nContent.GetIndex();
     611             : 
     612             :             }
     613           0 :             break;
     614             :             case SHELL_MODE_DRAWTEXT:
     615             :             {
     616           0 :                 SdrView*     pSdrView = pWrtShell->GetDrawView();
     617           0 :                 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
     618           0 :                 m_pSpellState->m_pOutliner = pOutliner;
     619           0 :                 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
     620             :                 OSL_ENSURE(pOutliner && pOLV, "no Outliner/OutlinerView in SwSpellDialogChildWindow::LoseFocus()");
     621           0 :                 if(pOLV)
     622             :                 {
     623           0 :                     m_pSpellState->m_aESelection = pOLV->GetSelection();
     624             :                 }
     625             :             }
     626           0 :             break;
     627             :             default:;//prevent warning
     628             :         }
     629             :     }
     630             :     else
     631           0 :         m_pSpellState->m_eSelMode = SHELL_MODE_OBJECT;
     632             : }
     633             : 
     634           0 : void SwSpellDialogChildWindow::InvalidateSpellDialog()
     635             : {
     636           0 :     SwWrtShell* pWrtShell = GetWrtShell_Impl();
     637           0 :     if(!m_pSpellState->m_bInitialCall && pWrtShell)
     638           0 :         pWrtShell->SpellEnd(0, false);
     639           0 :     m_pSpellState->Reset();
     640           0 :     svx::SpellDialogChildWindow::InvalidateSpellDialog();
     641           0 : }
     642             : 
     643           0 : SwWrtShell* SwSpellDialogChildWindow::GetWrtShell_Impl()
     644             : {
     645           0 :     SfxDispatcher* pDispatch = GetBindings().GetDispatcher();
     646           0 :     SwView* pView = 0;
     647           0 :     if(pDispatch)
     648             :     {
     649           0 :         sal_uInt16 nShellIdx = 0;
     650             :         SfxShell* pShell;
     651           0 :         while(0 != (pShell = pDispatch->GetShell(nShellIdx++)))
     652           0 :             if(pShell->ISA(SwView))
     653             :             {
     654           0 :                 pView = static_cast<SwView* >(pShell);
     655           0 :                 break;
     656             :             }
     657             :     }
     658           0 :     return pView ? pView->GetWrtShellPtr(): 0;
     659             : }
     660             : 
     661             : /*-------------------------------------------------------------------------
     662             :     set the cursor into the body text - necessary if any object is selected
     663             :     on start of the spelling dialog
     664             :   -----------------------------------------------------------------------*/
     665           0 : bool SwSpellDialogChildWindow::MakeTextSelection_Impl(SwWrtShell& rShell, ShellModes  eSelMode)
     666             : {
     667           0 :     SwView& rView = rShell.GetView();
     668           0 :     switch(eSelMode)
     669             :     {
     670             :         case SHELL_MODE_TEXT:
     671             :         case SHELL_MODE_LIST_TEXT:
     672             :         case SHELL_MODE_TABLE_TEXT:
     673             :         case SHELL_MODE_TABLE_LIST_TEXT:
     674             :         case SHELL_MODE_DRAWTEXT:
     675             :             OSL_FAIL("text already active in SwSpellDialogChildWindow::MakeTextSelection_Impl()");
     676           0 :         break;
     677             : 
     678             :         case SHELL_MODE_FRAME:
     679             :         {
     680           0 :             rShell.UnSelectFrm();
     681           0 :             rShell.LeaveSelFrmMode();
     682           0 :             rView.AttrChangedNotify(&rShell);
     683             :         }
     684           0 :         break;
     685             : 
     686             :         case SHELL_MODE_DRAW:
     687             :         case SHELL_MODE_DRAW_CTRL:
     688             :         case SHELL_MODE_DRAW_FORM:
     689             :         case SHELL_MODE_BEZIER:
     690           0 :             if(FindNextDrawTextError_Impl(rShell))
     691             :             {
     692           0 :                 rView.AttrChangedNotify(&rShell);
     693           0 :                 break;
     694             :             }
     695             :         //otherwise no break to deselect the object
     696             :         case SHELL_MODE_GRAPHIC:
     697             :         case SHELL_MODE_OBJECT:
     698             :         {
     699           0 :             if ( rShell.IsDrawCreate() )
     700             :             {
     701           0 :                 rView.GetDrawFuncPtr()->BreakCreate();
     702           0 :                 rView.AttrChangedNotify(&rShell);
     703             :             }
     704           0 :             else if ( rShell.HasSelection() || rView.IsDrawMode() )
     705             :             {
     706           0 :                 SdrView *pSdrView = rShell.GetDrawView();
     707           0 :                 if(pSdrView && pSdrView->AreObjectsMarked() &&
     708           0 :                     pSdrView->GetHdlList().GetFocusHdl())
     709             :                 {
     710           0 :                     ((SdrHdlList&)pSdrView->GetHdlList()).ResetFocusHdl();
     711             :                 }
     712             :                 else
     713             :                 {
     714           0 :                     rView.LeaveDrawCreate();
     715           0 :                     Point aPt(LONG_MIN, LONG_MIN);
     716             :                     //go out of the frame
     717           0 :                     rShell.SelectObj(aPt, SW_LEAVE_FRAME);
     718           0 :                     SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
     719           0 :                     rBind.Invalidate( SID_ATTR_SIZE );
     720           0 :                     rShell.EnterStdMode();
     721           0 :                     rView.AttrChangedNotify(&rShell);
     722             :                 }
     723             :             }
     724             :         }
     725           0 :         break;
     726             :         default:; //prevent warning
     727             :     }
     728           0 :     return true;
     729             : }
     730             : /*-------------------------------------------------------------------------
     731             :     select the next draw text object that has a spelling error
     732             :   -----------------------------------------------------------------------*/
     733           0 : bool SwSpellDialogChildWindow::FindNextDrawTextError_Impl(SwWrtShell& rSh)
     734             : {
     735           0 :     bool bNextDoc = false;
     736           0 :     SdrView* pDrView = rSh.GetDrawView();
     737           0 :     if(!pDrView)
     738           0 :         return bNextDoc;
     739           0 :     SwView& rView = rSh.GetView();
     740           0 :     SwDoc* pDoc = rView.GetDocShell()->GetDoc();
     741           0 :     const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
     742             :     //start at the current draw object - if there is any selected
     743           0 :     SdrTextObj* pCurrentTextObj = 0;
     744           0 :     if ( rMarkList.GetMarkCount() == 1 )
     745             :     {
     746           0 :         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
     747           0 :         if( pObj && pObj->ISA(SdrTextObj) )
     748           0 :             pCurrentTextObj = static_cast<SdrTextObj*>(pObj);
     749             :     }
     750             :     //at first fill the list of drawing objects
     751           0 :     if(!m_pSpellState->m_bTextObjectsCollected )
     752             :     {
     753           0 :         m_pSpellState->m_bTextObjectsCollected = true;
     754           0 :         std::list<SdrTextObj*> aTextObjs;
     755           0 :         SwDrawContact::GetTextObjectsFromFmt( aTextObjs, pDoc );
     756           0 :         if(pCurrentTextObj)
     757             :         {
     758           0 :             m_pSpellState->m_aTextObjects.remove(pCurrentTextObj);
     759           0 :             m_pSpellState->m_aTextObjects.push_back(pCurrentTextObj);
     760           0 :                                 }
     761             :                             }
     762           0 :     if(m_pSpellState->m_aTextObjects.size())
     763             :     {
     764           0 :         Reference< XSpellChecker1 >  xSpell( GetSpellChecker() );
     765           0 :         while(!bNextDoc && m_pSpellState->m_aTextObjects.size())
     766             :         {
     767           0 :             std::list<SdrTextObj*>::iterator aStart = m_pSpellState->m_aTextObjects.begin();
     768           0 :             SdrTextObj* pTextObj = *aStart;
     769           0 :             if(m_pSpellState->m_pStartDrawing == pTextObj)
     770           0 :                 m_pSpellState->m_bRestartDrawing = true;
     771           0 :             m_pSpellState->m_aTextObjects.erase(aStart);
     772           0 :             OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
     773           0 :             if ( pParaObj )
     774             :             {
     775           0 :                 bool bHasSpellError = false;
     776             :                 {
     777           0 :                     SdrOutliner aTmpOutliner(pDoc->GetDrawModel()->
     778           0 :                                              GetDrawOutliner().GetEmptyItemSet().GetPool(),
     779           0 :                                                 OUTLINERMODE_TEXTOBJECT );
     780           0 :                     aTmpOutliner.SetRefDevice( pDoc->getPrinter( false ) );
     781           0 :                     MapMode aMapMode (MAP_TWIP);
     782           0 :                     aTmpOutliner.SetRefMapMode(aMapMode);
     783           0 :                     aTmpOutliner.SetPaperSize( pTextObj->GetLogicRect().GetSize() );
     784           0 :                     aTmpOutliner.SetSpeller( xSpell );
     785             : 
     786           0 :                     OutlinerView* pOutlView = new OutlinerView( &aTmpOutliner, &(rView.GetEditWin()) );
     787           0 :                     pOutlView->GetOutliner()->SetRefDevice( rSh.getIDocumentDeviceAccess()->getPrinter( false ) );
     788           0 :                     aTmpOutliner.InsertView( pOutlView );
     789           0 :                     Point aPt;
     790           0 :                     Size aSize(1,1);
     791           0 :                     Rectangle aRect( aPt, aSize );
     792           0 :                     pOutlView->SetOutputArea( aRect );
     793           0 :                     aTmpOutliner.SetText( *pParaObj );
     794           0 :                     aTmpOutliner.ClearModifyFlag();
     795           0 :                     bHasSpellError = EE_SPELL_OK != aTmpOutliner.HasSpellErrors();
     796           0 :                     aTmpOutliner.RemoveView( pOutlView );
     797           0 :                     delete pOutlView;
     798             :                 }
     799           0 :                 if(bHasSpellError)
     800             :                 {
     801             :                     //now the current one has to be deselected
     802           0 :                     if(pCurrentTextObj)
     803           0 :                         pDrView->SdrEndTextEdit( sal_True );
     804             :                     //and the found one should be activated
     805           0 :                     rSh.MakeVisible(pTextObj->GetLogicRect());
     806           0 :                     Point aTmp( 0,0 );
     807           0 :                     rSh.SelectObj( aTmp, 0, pTextObj );
     808           0 :                     SdrPageView* pPV = pDrView->GetSdrPageView();
     809           0 :                     rView.BeginTextEdit( pTextObj, pPV, &rView.GetEditWin(), sal_False, sal_True );
     810           0 :                     rView.AttrChangedNotify(&rSh);
     811           0 :                     bNextDoc = true;
     812             :                 }
     813             :             }
     814           0 :         }
     815             :     }
     816           0 :     return bNextDoc;
     817             : }
     818             : 
     819             : 
     820           0 : bool SwSpellDialogChildWindow::SpellDrawText_Impl(SwWrtShell& rSh, ::svx::SpellPortions& rPortions)
     821             : {
     822           0 :     bool bRet = false;
     823           0 :     SdrView*     pSdrView = rSh.GetDrawView();
     824           0 :     SdrOutliner* pOutliner = pSdrView ? pSdrView->GetTextEditOutliner() : 0;
     825             :     OSL_ENSURE(pOutliner, "No Outliner in SwSpellDialogChildWindow::SpellDrawText_Impl");
     826           0 :     if(pOutliner)
     827             :     {
     828           0 :         bRet = pOutliner->SpellSentence(pSdrView->GetTextEditOutlinerView()->GetEditView(), rPortions, m_bIsGrammarCheckingOn);
     829             :         //find out if the current selection is in the first spelled drawing object
     830             :         //and behind the initial selection
     831           0 :         if(bRet && m_pSpellState->m_bRestartDrawing)
     832             :         {
     833           0 :             OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
     834           0 :             ESelection aCurrentSelection = pOLV->GetSelection();
     835           0 :             if(m_pSpellState->m_aStartDrawingSelection.nEndPara < aCurrentSelection.nEndPara ||
     836             :                (m_pSpellState->m_aStartDrawingSelection.nEndPara ==  aCurrentSelection.nEndPara &&
     837             :                     m_pSpellState->m_aStartDrawingSelection.nEndPos <  aCurrentSelection.nEndPos))
     838             :             {
     839           0 :                 bRet = false;
     840           0 :                 rPortions.clear();
     841             :             }
     842             :         }
     843             :     }
     844           0 :     return bRet;
     845             : }
     846             : 
     847           0 : void SwSpellDialogChildWindow::LockFocusNotification(bool bLock)
     848             : {
     849             :     OSL_ENSURE(m_pSpellState->m_bLockFocus != bLock, "invalid locking - no change of state");
     850           0 :     m_pSpellState->m_bLockFocus = bLock;
     851           0 : }
     852             : 
     853             : 
     854             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10