LCOV - code coverage report
Current view: top level - cui/source/dialogs - SpellDialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 1014 0.0 %
Date: 2014-11-03 Functions: 0 100 0.0 %
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 <vcl/wrkwin.hxx>
      21             : #include <vcl/menu.hxx>
      22             : #include <vcl/layout.hxx>
      23             : #include <vcl/scrbar.hxx>
      24             : #include <vcl/settings.hxx>
      25             : #include <SpellAttrib.hxx>
      26             : #include <sfx2/dispatch.hxx>
      27             : #include <sfx2/bindings.hxx>
      28             : #include <svl/undo.hxx>
      29             : #include <unotools/lingucfg.hxx>
      30             : #include <vcl/textdata.hxx>
      31             : #include <vcl/graphicfilter.hxx>
      32             : #include <editeng/unolingu.hxx>
      33             : #include <editeng/splwrap.hxx>
      34             : #include <linguistic/lngprops.hxx>
      35             : #include <linguistic/misc.hxx>
      36             : #include <comphelper/processfactory.hxx>
      37             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      38             : #include <com/sun/star/lang/XServiceInfo.hpp>
      39             : #include <com/sun/star/lang/XServiceDisplayName.hpp>
      40             : #include <com/sun/star/linguistic2/SpellFailure.hpp>
      41             : #include <com/sun/star/frame/XStorable.hpp>
      42             : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
      43             : #include <com/sun/star/system/SystemShellExecute.hpp>
      44             : #include <sfx2/app.hxx>
      45             : #include <vcl/help.hxx>
      46             : #include <vcl/graph.hxx>
      47             : #include <osl/file.hxx>
      48             : #include <cuires.hrc>
      49             : #include <editeng/optitems.hxx>
      50             : #include <editeng/svxenum.hxx>
      51             : #include <svx/SpellDialogChildWindow.hxx>
      52             : #include "SpellDialog.hxx"
      53             : #include <svx/dlgutil.hxx>
      54             : #include "optlingu.hxx"
      55             : #include <dialmgr.hxx>
      56             : #include <svx/svxerr.hxx>
      57             : #include "treeopt.hxx"
      58             : #include <svtools/langtab.hxx>
      59             : #include <comphelper/anytostring.hxx>
      60             : #include <cppuhelper/exc_hlp.hxx>
      61             : #include <boost/scoped_ptr.hpp>
      62             : 
      63             : using namespace ::com::sun::star;
      64             : using namespace ::com::sun::star::uno;
      65             : using namespace ::com::sun::star::beans;
      66             : using namespace ::com::sun::star::linguistic2;
      67             : 
      68             : 
      69             : // struct SpellDialog_Impl ---------------------------------------------
      70             : 
      71           0 : struct SpellDialog_Impl
      72             : {
      73             :     Sequence< Reference< XDictionary >  >   aDics;
      74             : };
      75             : 
      76             : 
      77             : #define SPELLUNDO_START                     200
      78             : 
      79             : #define SPELLUNDO_CHANGE_LANGUAGE           (SPELLUNDO_START + 1)
      80             : #define SPELLUNDO_CHANGE_TEXTENGINE         (SPELLUNDO_START + 2)
      81             : #define SPELLUNDO_CHANGE_NEXTERROR          (SPELLUNDO_START + 3)
      82             : #define SPELLUNDO_CHANGE_ADD_TO_DICTIONARY  (SPELLUNDO_START + 4)
      83             : #define SPELLUNDO_CHANGE_GROUP              (SPELLUNDO_START + 5) //undo list
      84             : #define SPELLUNDO_MOVE_ERROREND             (SPELLUNDO_START + 6)
      85             : #define SPELLUNDO_UNDO_EDIT_MODE            (SPELLUNDO_START + 7)
      86             : #define SPELLUNDO_ADD_IGNORE_RULE           (SPELLUNDO_START + 8)
      87             : 
      88             : namespace svx{
      89             : class SpellUndoAction_Impl : public SfxUndoAction
      90             : {
      91             :     sal_uInt16          m_nId;
      92             :     const Link&     m_rActionLink;
      93             :     //undo of button enabling
      94             :     bool            m_bEnableChangePB;
      95             :     bool            m_bEnableChangeAllPB;
      96             :     //undo of MarkNextError - used in change and change all, ignore and ignore all
      97             :     long            m_nNewErrorStart;
      98             :     long            m_nNewErrorEnd;
      99             :     long            m_nOldErrorStart;
     100             :     long            m_nOldErrorEnd;
     101             :     bool            m_bIsErrorLanguageSelected;
     102             :     //undo of AddToDictionary
     103             :     Reference<XDictionary>  m_xDictionary;
     104             :     OUString                m_sAddedWord;
     105             :     //move end of error - ::ChangeMarkedWord()
     106             :     long            m_nOffset;
     107             : 
     108             : public:
     109           0 :     SpellUndoAction_Impl(sal_uInt16 nId, const Link& rActionLink) :
     110             :         m_nId(nId),
     111             :         m_rActionLink( rActionLink),
     112             :         m_bEnableChangePB(false),
     113             :         m_bEnableChangeAllPB(false),
     114             :         m_nNewErrorStart(-1),
     115             :         m_nNewErrorEnd(-1),
     116             :         m_nOldErrorStart(-1),
     117             :         m_nOldErrorEnd(-1),
     118             :         m_bIsErrorLanguageSelected(false),
     119           0 :         m_nOffset(0)
     120           0 :         {}
     121             : 
     122             :     virtual ~SpellUndoAction_Impl();
     123             : 
     124             :     virtual void            Undo() SAL_OVERRIDE;
     125             :     virtual sal_uInt16          GetId() const SAL_OVERRIDE;
     126             : 
     127           0 :     void                    SetEnableChangePB(){m_bEnableChangePB = true;}
     128           0 :     bool                    IsEnableChangePB(){return m_bEnableChangePB;}
     129             : 
     130           0 :     void                    SetEnableChangeAllPB(){m_bEnableChangeAllPB = true;}
     131           0 :     bool                    IsEnableChangeAllPB(){return m_bEnableChangeAllPB;}
     132             : 
     133           0 :     void                    SetErrorMove(long nNewStart, long nNewEnd, long nOldStart, long nOldEnd)
     134             :                                 {
     135           0 :                                         m_nNewErrorStart = nNewStart;
     136           0 :                                         m_nNewErrorEnd  = nNewEnd;
     137           0 :                                         m_nOldErrorStart = nOldStart;
     138           0 :                                         m_nOldErrorEnd = nOldEnd;
     139           0 :                                 }
     140           0 :     long                    GetOldErrorStart() { return m_nOldErrorStart;}
     141           0 :     long                    GetOldErrorEnd() { return m_nOldErrorEnd;}
     142             : 
     143           0 :     void                    SetErrorLanguageSelected(bool bSet){ m_bIsErrorLanguageSelected = bSet;}
     144           0 :     bool                    IsErrorLanguageSelected() const {return m_bIsErrorLanguageSelected;}
     145             : 
     146           0 :     void                    SetDictionary(Reference<XDictionary> xDict) { m_xDictionary = xDict; }
     147           0 :     Reference<XDictionary>  GetDictionary() const {return m_xDictionary;}
     148           0 :     void                    SetAddedWord(const OUString& rWord) {m_sAddedWord = rWord;}
     149           0 :     const OUString&         GetAddedWord() const { return m_sAddedWord;}
     150             : 
     151           0 :     void                    SetOffset(long nSet) {m_nOffset = nSet;}
     152           0 :     long                    GetOffset() const {return m_nOffset;}
     153             : };
     154             : }//namespace svx
     155             : using namespace ::svx;
     156             : 
     157             : 
     158           0 : SpellUndoAction_Impl::~SpellUndoAction_Impl()
     159             : {
     160           0 : }
     161             : 
     162             : 
     163           0 : void SpellUndoAction_Impl::Undo()
     164             : {
     165           0 :     m_rActionLink.Call(this);
     166           0 : }
     167             : 
     168             : 
     169           0 : sal_uInt16 SpellUndoAction_Impl::GetId()const
     170             : {
     171           0 :     return m_nId;
     172             : }
     173             : 
     174             : // class SvxSpellCheckDialog ---------------------------------------------
     175             : 
     176           0 : SpellDialog::SpellDialog(SpellDialogChildWindow* pChildWindow,
     177             :     vcl::Window * pParent, SfxBindings* _pBindings)
     178             :     : SfxModelessDialog (_pBindings, pChildWindow,
     179             :         pParent, "SpellingDialog", "cui/ui/spellingdialog.ui")
     180             :     , aDialogUndoLink(LINK (this, SpellDialog, DialogUndoHdl))
     181             :     , bModified(false)
     182             :     , bFocusLocked(true)
     183           0 :     , rParent(*pChildWindow)
     184             : {
     185           0 :     m_sTitleSpellingGrammar = GetText();
     186           0 :     m_sTitleSpelling = get<FixedText>("alttitleft")->GetText();
     187             : 
     188             :     // fdo#68794 set initial title for cases where no text has been processed
     189             :     // yet to show its language attributes
     190           0 :     OUString sTitle = rParent.HasGrammarChecking() ? m_sTitleSpellingGrammar : m_sTitleSpelling;
     191           0 :     SetText(sTitle.replaceFirst("$LANGUAGE ($LOCATION)", ""));
     192             : 
     193           0 :     m_sResumeST = get<FixedText>("resumeft")->GetText();
     194           0 :     m_sNoSuggestionsST = get<FixedText>("nosuggestionsft")->GetText();
     195             : 
     196           0 :     get(m_pLanguageFT, "languageft");
     197           0 :     get(m_pLanguageLB, "languagelb");
     198           0 :     get(m_pExplainFT, "explain");
     199           0 :     get(m_pExplainLink, "explainlink");
     200           0 :     get(m_pNotInDictFT, "notindictft");
     201           0 :     get(m_pSentenceED, "sentence");
     202           0 :     Size aEdSize(LogicToPixel(Size(197, 48), MAP_APPFONT));
     203           0 :     m_pSentenceED->set_width_request(aEdSize.Width());
     204           0 :     m_pSentenceED->set_height_request(aEdSize.Height());
     205           0 :     get(m_pSuggestionFT, "suggestionsft");
     206           0 :     get(m_pSuggestionLB, "suggestionslb");
     207           0 :     m_pSuggestionLB->SetDropDownLineCount(5);
     208           0 :     m_pSuggestionLB->set_width_request(aEdSize.Width());
     209           0 :     get(m_pIgnorePB, "ignore");
     210           0 :     m_sIgnoreOnceST = m_pIgnorePB->GetText();
     211           0 :     get(m_pIgnoreAllPB, "ignoreall");
     212           0 :     get(m_pIgnoreRulePB, "ignorerule");
     213           0 :     get(m_pAddToDictPB, "add");
     214           0 :     get(m_pAddToDictMB, "addmb");
     215           0 :     m_pAddToDictMB->SetHelpId(m_pAddToDictPB->GetHelpId());
     216           0 :     get(m_pChangePB, "change");
     217           0 :     get(m_pChangeAllPB, "changeall");
     218           0 :     get(m_pAutoCorrPB, "autocorrect");
     219           0 :     get(m_pCheckGrammarCB, "checkgrammar");
     220           0 :     get(m_pOptionsPB, "options");
     221           0 :     get(m_pUndoPB, "undo");
     222           0 :     get(m_pClosePB, "close");
     223           0 :     xSpell = LinguMgr::GetSpellChecker();
     224           0 :     pImpl = new SpellDialog_Impl;
     225             : 
     226           0 :     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
     227           0 :     Color aCol = rSettings.GetHelpColor();
     228           0 :     Wallpaper aWall( aCol );
     229           0 :     m_pExplainLink->SetBackground( aWall );
     230           0 :     m_pExplainFT->SetBackground( aWall );
     231             : 
     232           0 :     Init_Impl();
     233             : 
     234             :     // disable controls if service is missing
     235           0 :     Enable(xSpell.is());
     236             : 
     237             :     //InitHdl wants to use virtual methods, so it
     238             :     //can't be called during the ctor, so init
     239             :     //it on next event cycle post-ctor
     240             :     Application::PostUserEvent( STATIC_LINK(
     241           0 :                         this, SpellDialog, InitHdl ) );
     242           0 : }
     243             : 
     244             : 
     245             : 
     246           0 : SpellDialog::~SpellDialog()
     247             : {
     248             :     // save possibly modified user-dictionaries
     249           0 :     Reference< XSearchableDictionaryList >  xDicList( SvxGetDictionaryList() );
     250           0 :     if (xDicList.is())
     251             :     {
     252           0 :         linguistic::SaveDictionaries( xDicList );
     253             :     }
     254             : 
     255           0 :     delete pImpl;
     256           0 : }
     257             : 
     258             : 
     259             : 
     260           0 : void SpellDialog::Init_Impl()
     261             : {
     262             :     // initialize handler
     263           0 :     m_pClosePB->SetClickHdl(LINK( this, SpellDialog, CancelHdl ) );
     264           0 :     m_pChangePB->SetClickHdl(LINK( this, SpellDialog, ChangeHdl ) );
     265           0 :     m_pChangeAllPB->SetClickHdl(LINK( this, SpellDialog, ChangeAllHdl ) );
     266           0 :     m_pIgnorePB->SetClickHdl(LINK( this, SpellDialog, IgnoreHdl ) );
     267           0 :     m_pIgnoreAllPB->SetClickHdl(LINK( this, SpellDialog, IgnoreAllHdl ) );
     268           0 :     m_pIgnoreRulePB->SetClickHdl(LINK( this, SpellDialog, IgnoreAllHdl ) );
     269           0 :     m_pUndoPB->SetClickHdl(LINK( this, SpellDialog, UndoHdl ) );
     270             : 
     271           0 :     m_pAutoCorrPB->SetClickHdl( LINK( this, SpellDialog, ExtClickHdl ) );
     272           0 :     m_pCheckGrammarCB->SetClickHdl( LINK( this, SpellDialog, CheckGrammarHdl ));
     273           0 :     m_pOptionsPB->SetClickHdl( LINK( this, SpellDialog, ExtClickHdl ) );
     274             : 
     275           0 :     m_pSuggestionLB->SetDoubleClickHdl( LINK( this, SpellDialog, ChangeHdl ) );
     276             : 
     277           0 :     m_pSentenceED->SetModifyHdl(LINK ( this, SpellDialog, ModifyHdl) );
     278             : 
     279           0 :     m_pAddToDictMB->SetSelectHdl(LINK ( this, SpellDialog, AddToDictSelectHdl ) );
     280           0 :     m_pAddToDictPB->SetClickHdl(LINK ( this, SpellDialog, AddToDictClickHdl ) );
     281             : 
     282           0 :     m_pLanguageLB->SetSelectHdl(LINK( this, SpellDialog, LanguageSelectHdl ) );
     283             : 
     284           0 :     m_pExplainLink->SetClickHdl( LINK( this, SpellDialog, HandleHyperlink ) );
     285             : 
     286             :     // initialize language ListBox
     287           0 :     m_pLanguageLB->SetLanguageList( LANG_LIST_SPELL_USED, false, false, true );
     288             : 
     289           0 :     m_pSentenceED->ClearModifyFlag();
     290           0 :     SvxGetChangeAllList()->clear();
     291           0 : }
     292             : 
     293             : 
     294             : 
     295           0 : void SpellDialog::UpdateBoxes_Impl()
     296             : {
     297             :     sal_Int32 i;
     298           0 :     m_pSuggestionLB->Clear();
     299             : 
     300           0 :     const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
     301             : 
     302           0 :     LanguageType nAltLanguage = LANGUAGE_NONE;
     303           0 :     Sequence< OUString > aNewWords;
     304           0 :     bool bIsGrammarError = false;
     305           0 :     if( pSpellErrorDescription )
     306             :     {
     307           0 :         nAltLanguage    = LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale );
     308           0 :         aNewWords       = pSpellErrorDescription->aSuggestions;
     309           0 :         bIsGrammarError = pSpellErrorDescription->bIsGrammarError;
     310           0 :         m_pExplainLink->SetURL( pSpellErrorDescription->sExplanationURL );
     311           0 :         m_pExplainFT->SetText( pSpellErrorDescription->sExplanation );
     312             :     }
     313           0 :     if( pSpellErrorDescription && !pSpellErrorDescription->sDialogTitle.isEmpty() )
     314             :     {
     315             :         // use this function to apply the correct image to be used...
     316           0 :         SetTitle_Impl( nAltLanguage );
     317             :         // then change the title to the one to be actually used
     318           0 :         SetText( pSpellErrorDescription->sDialogTitle );
     319             :     }
     320             :     else
     321           0 :         SetTitle_Impl( nAltLanguage );
     322           0 :     SetSelectedLang_Impl( nAltLanguage );
     323           0 :     int nDicts = InitUserDicts();
     324             : 
     325             :     // enter alternatives
     326           0 :     const OUString *pNewWords = aNewWords.getConstArray();
     327           0 :     const sal_Int32 nSize = aNewWords.getLength();
     328           0 :     for ( i = 0; i < nSize; ++i )
     329             :     {
     330           0 :         OUString aTmp( pNewWords[i] );
     331           0 :         if ( LISTBOX_ENTRY_NOTFOUND == m_pSuggestionLB->GetEntryPos( aTmp ) )
     332             :         {
     333           0 :             m_pSuggestionLB->InsertEntry( aTmp );
     334           0 :             m_pSuggestionLB->SetEntryFlags(m_pSuggestionLB->GetEntryCount() - 1, LISTBOX_ENTRY_FLAG_MULTILINE);
     335             :         }
     336           0 :     }
     337           0 :     if(!nSize)
     338           0 :         m_pSuggestionLB->InsertEntry(m_sNoSuggestionsST);
     339           0 :     m_pAutoCorrPB->Enable( nSize > 0 );
     340             : 
     341           0 :     m_pSuggestionFT->Enable(nSize > 0);
     342           0 :     m_pSuggestionLB->Enable(nSize > 0);
     343           0 :     if( nSize )
     344             :     {
     345           0 :         m_pSuggestionLB->SelectEntryPos(0);
     346             :     }
     347           0 :     m_pChangePB->Enable( nSize > 0);
     348           0 :     m_pChangeAllPB->Enable(nSize > 0);
     349           0 :     bool bShowChangeAll = !bIsGrammarError;
     350           0 :     m_pChangeAllPB->Show( bShowChangeAll );
     351           0 :     m_pExplainFT->Show( !bShowChangeAll );
     352           0 :     m_pLanguageLB->Enable( bShowChangeAll );
     353           0 :     m_pIgnoreAllPB->Show( bShowChangeAll );
     354             : 
     355           0 :     m_pAddToDictMB->Show( bShowChangeAll && nDicts > 1);
     356           0 :     m_pAddToDictPB->Show( bShowChangeAll && nDicts <= 1);
     357           0 :     m_pIgnoreRulePB->Show( !bShowChangeAll );
     358           0 :     m_pIgnoreRulePB->Enable(pSpellErrorDescription && !pSpellErrorDescription->sRuleId.isEmpty());
     359           0 :     m_pAutoCorrPB->Show( bShowChangeAll && rParent.HasAutoCorrection() );
     360             : 
     361           0 :     bool bOldShowGrammar = m_pCheckGrammarCB->IsVisible();
     362           0 :     bool bOldShowExplain = m_pExplainLink->IsVisible();
     363             : 
     364           0 :     m_pCheckGrammarCB->Show(rParent.HasGrammarChecking());
     365           0 :     m_pExplainLink->Show(!m_pExplainLink->GetURL().isEmpty());
     366           0 :     if (m_pExplainFT->GetText().isEmpty())
     367             :     {
     368           0 :         m_pExplainFT->Hide();
     369           0 :         m_pExplainLink->Hide();
     370             :     }
     371             : 
     372           0 :     if (bOldShowExplain != (bool) m_pExplainLink->IsVisible() || bOldShowGrammar != (bool) m_pCheckGrammarCB->IsVisible())
     373           0 :         setOptimalLayoutSize();
     374           0 : }
     375             : 
     376             : 
     377           0 : void SpellDialog::SpellContinue_Impl(bool bUseSavedSentence, bool bIgnoreCurrentError )
     378             : {
     379             :     //initially or after the last error of a sentence MarkNextError will fail
     380             :     //then GetNextSentence() has to be called followed again by MarkNextError()
     381             :     //MarkNextError is not initially called if the UndoEdit mode is active
     382           0 :     bool bNextSentence = false;
     383           0 :     if((!m_pSentenceED->IsUndoEditMode() && m_pSentenceED->MarkNextError( bIgnoreCurrentError, xSpell )) ||
     384           0 :             true == ( bNextSentence = GetNextSentence_Impl(bUseSavedSentence, m_pSentenceED->IsUndoEditMode()) && m_pSentenceED->MarkNextError( false, xSpell )))
     385             :     {
     386           0 :         const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
     387           0 :         if( pSpellErrorDescription )
     388             :         {
     389           0 :             UpdateBoxes_Impl();
     390             :             Control* aControls[] =
     391             :             {
     392             :                 m_pNotInDictFT,
     393             :                 m_pSentenceED,
     394             :                 m_pLanguageFT,
     395             :                 0
     396           0 :             };
     397           0 :             sal_Int32 nIdx = 0;
     398           0 :             do
     399             :             {
     400           0 :                 aControls[nIdx]->Enable(true);
     401             :             }
     402           0 :             while(aControls[++nIdx]);
     403             : 
     404             :         }
     405           0 :         if( bNextSentence )
     406             :         {
     407             :             //remove undo if a new sentence is active
     408           0 :             m_pSentenceED->ResetUndo();
     409           0 :             m_pUndoPB->Enable(false);
     410             :         }
     411             :     }
     412           0 : }
     413             : /* Initialize, asynchronous to prevent virtial calls
     414             :    from a constructor
     415             :  */
     416           0 : IMPL_STATIC_LINK( SpellDialog, InitHdl, SpellDialog *, EMPTYARG )
     417             : {
     418           0 :     pThis->SetUpdateMode( false );
     419             :     //show or hide AutoCorrect depending on the modules abilities
     420           0 :     pThis->m_pAutoCorrPB->Show(pThis->rParent.HasAutoCorrection());
     421           0 :     pThis->SpellContinue_Impl();
     422           0 :     pThis->m_pSentenceED->ResetUndo();
     423           0 :     pThis->m_pUndoPB->Enable(false);
     424             : 
     425             :     // get current language
     426           0 :     pThis->UpdateBoxes_Impl();
     427             : 
     428             :     // fill dictionary PopupMenu
     429           0 :     pThis->InitUserDicts();
     430             : 
     431           0 :     pThis->LockFocusChanges(true);
     432           0 :     if( pThis->m_pChangePB->IsEnabled() )
     433           0 :         pThis->m_pChangePB->GrabFocus();
     434           0 :     else if( pThis->m_pIgnorePB->IsEnabled() )
     435           0 :         pThis->m_pIgnorePB->GrabFocus();
     436           0 :     else if( pThis->m_pClosePB->IsEnabled() )
     437           0 :         pThis->m_pClosePB->GrabFocus();
     438           0 :     pThis->LockFocusChanges(false);
     439             :     //show grammar CheckBox depending on the modules abilities
     440           0 :     pThis->m_pCheckGrammarCB->Check( pThis->rParent.IsGrammarChecking() );
     441           0 :     pThis->SetUpdateMode( true );
     442           0 :     pThis->Show();
     443           0 :     return 0;
     444             : };
     445             : 
     446             : 
     447             : 
     448           0 : IMPL_LINK( SpellDialog, ExtClickHdl, Button *, pBtn )
     449             : {
     450           0 :     if (m_pOptionsPB == pBtn)
     451           0 :         StartSpellOptDlg_Impl();
     452           0 :     else if (m_pAutoCorrPB == pBtn)
     453             :     {
     454             :         //get the currently selected wrong word
     455           0 :         OUString sCurrentErrorText = m_pSentenceED->GetErrorText();
     456             :         //get the wrong word from the XSpellAlternative
     457           0 :         const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
     458           0 :         if( pSpellErrorDescription )
     459             :         {
     460           0 :             OUString sWrong(pSpellErrorDescription->sErrorText);
     461             :             //if the word has not been edited in the MultiLineEdit then
     462             :             //the current suggestion should be used
     463             :             //if it's not the 'no suggestions' entry
     464           0 :             if(sWrong == sCurrentErrorText &&
     465           0 :                     m_pSuggestionLB->IsEnabled() && m_pSuggestionLB->GetSelectEntryCount() > 0 &&
     466           0 :                     !m_sNoSuggestionsST.equals(m_pSuggestionLB->GetSelectEntry()))
     467             :             {
     468           0 :                 sCurrentErrorText = m_pSuggestionLB->GetSelectEntry();
     469             :             }
     470           0 :             if(sWrong != sCurrentErrorText)
     471             :             {
     472           0 :                 SvxPrepareAutoCorrect( sWrong, sCurrentErrorText );
     473           0 :                 LanguageType eLang = GetSelectedLang_Impl();
     474           0 :                 rParent.AddAutoCorrection( sWrong, sCurrentErrorText, eLang );
     475           0 :             }
     476           0 :         }
     477             :     }
     478           0 :     return 0;
     479             : }
     480             : 
     481           0 : IMPL_LINK( SpellDialog, CheckGrammarHdl, CheckBox*, pBox )
     482             : {
     483           0 :     rParent.SetGrammarChecking( pBox->IsChecked() );
     484           0 :     Impl_Restore();
     485           0 :     return 0;
     486             : }
     487             : 
     488           0 : void SpellDialog::StartSpellOptDlg_Impl()
     489             : {
     490             :     sal_uInt16 aSpellInfos[] =
     491             :     {
     492             :         SID_ATTR_SPELL,SID_ATTR_SPELL,
     493             :         SID_SPELL_MODIFIED, SID_SPELL_MODIFIED,
     494             :         SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
     495             :         0
     496           0 :     };
     497           0 :     SfxItemSet aSet( SfxGetpApp()->GetPool(), aSpellInfos);
     498           0 :     aSet.Put(SfxSpellCheckItem( xSpell, SID_ATTR_SPELL ));
     499             :     boost::scoped_ptr<SfxSingleTabDialog> pDlg(
     500           0 :         new SfxSingleTabDialog(this, aSet, "SpellOptionsDialog", "cui/ui/spelloptionsdialog.ui"));
     501           0 :     SfxTabPage* pPage = SvxLinguTabPage::Create( pDlg->get_content_area(), &aSet );
     502           0 :     static_cast<SvxLinguTabPage*>(pPage)->HideGroups( GROUP_MODULES );
     503           0 :     pDlg->SetTabPage( pPage );
     504           0 :     if(RET_OK == pDlg->Execute())
     505             :     {
     506           0 :         InitUserDicts();
     507           0 :         const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
     508           0 :         if(pOutSet)
     509           0 :             OfaTreeOptionsDialog::ApplyLanguageOptions(*pOutSet);
     510           0 :     }
     511           0 : }
     512             : 
     513             : namespace
     514             : {
     515           0 :     OUString getDotReplacementString(const OUString &rErrorText, const OUString &rSuggestedReplacement)
     516             :     {
     517           0 :         OUString aString = rErrorText;
     518             : 
     519             :         //dots are sometimes part of the spelled word but they are not necessarily part of the replacement
     520           0 :         bool bDot = aString.endsWith(".");
     521             : 
     522           0 :         aString = rSuggestedReplacement;
     523             : 
     524           0 :         if(bDot && (aString.isEmpty() || !aString.endsWith(".")))
     525           0 :             aString += ".";
     526             : 
     527           0 :         return aString;
     528             :     }
     529             : }
     530             : 
     531             : 
     532           0 : OUString SpellDialog::getReplacementString() const
     533             : {
     534           0 :     OUString sOrigString = m_pSentenceED->GetErrorText();
     535             : 
     536           0 :     OUString sReplacement(sOrigString);
     537             : 
     538           0 :     if(m_pSuggestionLB->IsEnabled() &&
     539           0 :             m_pSuggestionLB->GetSelectEntryCount()>0 &&
     540           0 :             !m_sNoSuggestionsST.equals(m_pSuggestionLB->GetSelectEntry()))
     541           0 :         sReplacement = m_pSuggestionLB->GetSelectEntry();
     542             : 
     543           0 :     return getDotReplacementString(sOrigString, sReplacement);
     544             : }
     545             : 
     546             : 
     547             : 
     548           0 : IMPL_LINK_NOARG(SpellDialog, ChangeHdl)
     549             : {
     550           0 :     if(m_pSentenceED->IsUndoEditMode())
     551             :     {
     552           0 :         SpellContinue_Impl();
     553             :     }
     554             :     else
     555             :     {
     556           0 :         m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
     557           0 :         OUString aString = getReplacementString();
     558           0 :         m_pSentenceED->ChangeMarkedWord(aString, GetSelectedLang_Impl());
     559           0 :         SpellContinue_Impl();
     560           0 :         bModified = false;
     561           0 :         m_pSentenceED->UndoActionEnd();
     562             :     }
     563           0 :     if(!m_pChangePB->IsEnabled())
     564           0 :         m_pIgnorePB->GrabFocus();
     565           0 :     return 1;
     566             : }
     567             : 
     568             : 
     569             : 
     570           0 : IMPL_LINK_NOARG(SpellDialog, ChangeAllHdl)
     571             : {
     572           0 :     m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
     573           0 :     OUString aString = getReplacementString();
     574           0 :     LanguageType eLang = GetSelectedLang_Impl();
     575             : 
     576             :     // add new word to ChangeAll list
     577           0 :     OUString  aOldWord( m_pSentenceED->GetErrorText() );
     578           0 :     SvxPrepareAutoCorrect( aOldWord, aString );
     579           0 :     Reference<XDictionary> aXDictionary( SvxGetChangeAllList(), UNO_QUERY );
     580             :     sal_uInt8 nAdded = linguistic::AddEntryToDic( aXDictionary,
     581             :             aOldWord, true,
     582           0 :             aString, eLang );
     583             : 
     584           0 :     if(nAdded == DIC_ERR_NONE)
     585             :     {
     586             :         SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
     587           0 :                         SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
     588           0 :         pAction->SetDictionary(aXDictionary);
     589           0 :         pAction->SetAddedWord(aOldWord);
     590           0 :         m_pSentenceED->AddUndoAction(pAction);
     591             :     }
     592             : 
     593           0 :     m_pSentenceED->ChangeMarkedWord(aString, eLang);
     594           0 :     SpellContinue_Impl();
     595           0 :     bModified = false;
     596           0 :     m_pSentenceED->UndoActionEnd();
     597           0 :     return 1;
     598             : }
     599             : 
     600             : 
     601           0 : IMPL_LINK( SpellDialog, IgnoreAllHdl, Button *, pButton )
     602             : {
     603           0 :     m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
     604             :     // add word to IgnoreAll list
     605           0 :     Reference< XDictionary > aXDictionary( SvxGetIgnoreAllList(), UNO_QUERY );
     606             :     //in case the error has been changed manually it has to be restored
     607           0 :     m_pSentenceED->RestoreCurrentError();
     608           0 :     if (pButton == m_pIgnoreRulePB)
     609             :     {
     610           0 :         const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
     611             :         try
     612             :         {
     613           0 :             if( pSpellErrorDescription && pSpellErrorDescription->xGrammarChecker.is() )
     614             :             {
     615           0 :                 pSpellErrorDescription->xGrammarChecker->ignoreRule( pSpellErrorDescription->sRuleId,
     616           0 :                     pSpellErrorDescription->aLocale );
     617             :                 // refresh the layout (workaround to launch a dictionary event)
     618           0 :                 aXDictionary->setActive(sal_False);
     619           0 :                 aXDictionary->setActive(sal_True);
     620             :             }
     621             :         }
     622           0 :         catch( const uno::Exception& )
     623             :         {
     624             :         }
     625             :     }
     626             :     else
     627             :     {
     628           0 :         OUString sErrorText(m_pSentenceED->GetErrorText());
     629             :         sal_uInt8 nAdded = linguistic::AddEntryToDic( aXDictionary,
     630             :             sErrorText, false,
     631           0 :             OUString(), LANGUAGE_NONE );
     632           0 :         if(nAdded == DIC_ERR_NONE)
     633             :         {
     634             :             SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
     635           0 :                             SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
     636           0 :             pAction->SetDictionary(aXDictionary);
     637           0 :             pAction->SetAddedWord(sErrorText);
     638           0 :             m_pSentenceED->AddUndoAction(pAction);
     639           0 :         }
     640             :     }
     641             : 
     642           0 :     SpellContinue_Impl();
     643           0 :     bModified = false;
     644           0 :     m_pSentenceED->UndoActionEnd();
     645           0 :     return 1;
     646             : }
     647             : 
     648             : 
     649           0 : IMPL_LINK_NOARG(SpellDialog, UndoHdl)
     650             : {
     651           0 :     m_pSentenceED->Undo();
     652           0 :     if(!m_pSentenceED->GetUndoActionCount())
     653           0 :         m_pUndoPB->Enable(false);
     654           0 :     return 0;
     655             : }
     656             : 
     657             : 
     658           0 : IMPL_LINK( SpellDialog, DialogUndoHdl, SpellUndoAction_Impl*, pAction )
     659             : {
     660           0 :     switch(pAction->GetId())
     661             :     {
     662             :         case SPELLUNDO_CHANGE_TEXTENGINE:
     663             :         {
     664           0 :             if(pAction->IsEnableChangePB())
     665           0 :                 m_pChangePB->Enable(false);
     666           0 :             if(pAction->IsEnableChangeAllPB())
     667           0 :                 m_pChangeAllPB->Enable(false);
     668             :         }
     669           0 :         break;
     670             :         case SPELLUNDO_CHANGE_NEXTERROR:
     671             :         {
     672           0 :             m_pSentenceED->MoveErrorMarkTo((sal_uInt16)pAction->GetOldErrorStart(), (sal_uInt16)pAction->GetOldErrorEnd(), false);
     673           0 :             if(pAction->IsErrorLanguageSelected())
     674             :             {
     675           0 :                 UpdateBoxes_Impl();
     676             :             }
     677             :         }
     678           0 :         break;
     679             :         case SPELLUNDO_CHANGE_ADD_TO_DICTIONARY:
     680             :         {
     681           0 :             if(pAction->GetDictionary().is())
     682           0 :                 pAction->GetDictionary()->remove(pAction->GetAddedWord());
     683             :         }
     684           0 :         break;
     685             :         case SPELLUNDO_MOVE_ERROREND :
     686             :         {
     687           0 :             if(pAction->GetOffset() != 0)
     688           0 :                 m_pSentenceED->MoveErrorEnd(pAction->GetOffset());
     689             :         }
     690           0 :         break;
     691             :         case SPELLUNDO_UNDO_EDIT_MODE :
     692             :         {
     693             :             //refill the dialog with the currently spelled sentence - throw away all changes
     694           0 :             SpellContinue_Impl(true);
     695             :         }
     696           0 :         break;
     697             :         case SPELLUNDO_ADD_IGNORE_RULE:
     698             :             //undo of ignored rules is not supported
     699           0 :         break;
     700             :     }
     701             : 
     702           0 :     return 0;
     703             : }
     704             : 
     705           0 : void SpellDialog::Impl_Restore()
     706             : {
     707             :     //clear the "ChangeAllList"
     708           0 :     SvxGetChangeAllList()->clear();
     709             :     //get a new sentence
     710           0 :     m_pSentenceED->SetText(OUString());
     711           0 :     m_pSentenceED->ResetModified();
     712             :     //Resolves: fdo#39348 refill the dialog with the currently spelled sentence
     713           0 :     SpellContinue_Impl(true);
     714           0 :     m_pIgnorePB->SetText(m_sIgnoreOnceST);
     715           0 : }
     716             : 
     717           0 : IMPL_LINK_NOARG(SpellDialog, IgnoreHdl)
     718             : {
     719           0 :     if (m_sResumeST.equals(m_pIgnorePB->GetText()))
     720             :     {
     721           0 :         Impl_Restore();
     722             :     }
     723             :     else
     724             :     {
     725             :         //in case the error has been changed manually it has to be restored,
     726             :         // since the users choice now was to ignore the error
     727           0 :         m_pSentenceED->RestoreCurrentError();
     728             : 
     729             :         // the word is being ignored
     730           0 :         SpellContinue_Impl( false, true );
     731             :     }
     732           0 :     return 1;
     733             : }
     734             : 
     735             : 
     736             : 
     737           0 : bool SpellDialog::Close()
     738             : {
     739           0 :     GetBindings().GetDispatcher()->
     740           0 :         Execute(rParent.GetType(),
     741           0 :         SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
     742           0 :     return true;
     743             : }
     744             : 
     745             : 
     746           0 : void SpellDialog::SetSelectedLang_Impl( LanguageType nLang )
     747             : {
     748           0 :     m_pLanguageLB->SelectLanguage( nLang );
     749           0 : }
     750             : 
     751             : 
     752             : 
     753           0 : LanguageType SpellDialog::GetSelectedLang_Impl() const
     754             : {
     755           0 :     sal_Int16 nLang = m_pLanguageLB->GetSelectLanguage();
     756           0 :     return nLang;
     757             : }
     758             : 
     759             : 
     760           0 : IMPL_LINK(SpellDialog, LanguageSelectHdl, SvxLanguageBox*, pBox)
     761             : {
     762             :     //If selected language changes, then add->list should be regenerated to
     763             :     //match
     764           0 :     InitUserDicts();
     765             : 
     766             :     //if currently an error is selected then search for alternatives for
     767             :     //this word and fill the alternatives ListBox accordingly
     768           0 :     OUString sError = m_pSentenceED->GetErrorText();
     769           0 :     m_pSuggestionLB->Clear();
     770           0 :     if(!sError.isEmpty())
     771             :     {
     772           0 :         LanguageType eLanguage = pBox->GetSelectLanguage();
     773           0 :         Reference <XSpellAlternatives> xAlt = xSpell->spell( sError, eLanguage,
     774           0 :                                             Sequence< PropertyValue >() );
     775           0 :         if( xAlt.is() )
     776           0 :             m_pSentenceED->SetAlternatives( xAlt );
     777             :         else
     778             :         {
     779           0 :             m_pSentenceED->ChangeMarkedWord( sError, eLanguage );
     780           0 :             SpellContinue_Impl();
     781             :         }
     782             : 
     783           0 :          m_pSentenceED->AddUndoAction(new SpellUndoAction_Impl(SPELLUNDO_CHANGE_LANGUAGE, aDialogUndoLink));
     784             :     }
     785           0 :     SpellDialog::UpdateBoxes_Impl();
     786           0 :     return 0;
     787             : }
     788             : 
     789             : 
     790           0 : void SpellDialog::SetLanguage( sal_uInt16 nLang )
     791             : /*
     792             :     Description:
     793             :     If the language has been changed in thesaurus,
     794             :     it must be changed here, too.
     795             : */
     796             : {
     797           0 :     SetTitle_Impl( nLang );
     798           0 :     m_pLanguageLB->SelectLanguage( nLang );
     799           0 : }
     800             : 
     801           0 : void SpellDialog::SetTitle_Impl(LanguageType nLang)
     802             : {
     803           0 :     OUString sTitle = rParent.HasGrammarChecking() ? m_sTitleSpellingGrammar : m_sTitleSpelling;
     804           0 :     sTitle = sTitle.replaceFirst( "$LANGUAGE ($LOCATION)", SvtLanguageTable::GetLanguageString(nLang) );
     805           0 :     SetText( sTitle );
     806           0 : }
     807             : 
     808           0 : int SpellDialog::InitUserDicts()
     809             : {
     810           0 :     const LanguageType nLang = m_pLanguageLB->GetSelectLanguage();
     811             : 
     812           0 :     const Reference< XDictionary >  *pDic = 0;
     813             : 
     814             :     // get list of dictionaries
     815           0 :     Reference< XSearchableDictionaryList >  xDicList( SvxGetDictionaryList() );
     816           0 :     if (xDicList.is())
     817             :     {
     818             :         // add active, positive dictionary to dic-list (if not already done).
     819             :         // This is to ensure that there is at least on dictionary to which
     820             :         // words could be added.
     821           0 :         Reference< XDictionary >  xDic( SvxGetOrCreatePosDic( xDicList ) );
     822           0 :         if (xDic.is())
     823           0 :             xDic->setActive( sal_True );
     824             : 
     825           0 :         pImpl->aDics = xDicList->getDictionaries();
     826             :     }
     827             : 
     828           0 :     SvtLinguConfig aCfg;
     829             : 
     830             :     // list suitable dictionaries
     831           0 :     bool bEnable = false;
     832           0 :     const sal_Int32 nSize = pImpl->aDics.getLength();
     833           0 :     pDic = pImpl->aDics.getConstArray();
     834           0 :     PopupMenu* pMenu = m_pAddToDictMB->GetPopupMenu();
     835             :     assert(pMenu);
     836           0 :     pMenu->Clear();
     837           0 :     pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
     838           0 :     sal_uInt16 nItemId = 1;     // menu items should be enumerated from 1 and not 0
     839           0 :     for (sal_Int32 i = 0; i < nSize; ++i)
     840             :     {
     841           0 :         uno::Reference< linguistic2::XDictionary >  xDicTmp( pDic[i], uno::UNO_QUERY );
     842           0 :         if (!xDicTmp.is() || SvxGetIgnoreAllList() == xDicTmp)
     843           0 :             continue;
     844             : 
     845           0 :         uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
     846           0 :         LanguageType nActLanguage = LanguageTag( xDicTmp->getLocale() ).getLanguageType();
     847           0 :         if( xDicTmp->isActive()
     848           0 :             &&  xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
     849           0 :             && (nLang == nActLanguage || LANGUAGE_NONE == nActLanguage )
     850           0 :             && (!xStor.is() || !xStor->isReadonly()) )
     851             :         {
     852           0 :             pMenu->InsertItem( nItemId, xDicTmp->getName() );
     853           0 :             bEnable = true;
     854             : 
     855           0 :             uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
     856           0 :             if (xSvcInfo.is())
     857             :             {
     858             :                 OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
     859           0 :                         xSvcInfo->getImplementationName()) );
     860           0 :                 if (!aDictionaryImageUrl.isEmpty())
     861             :                 {
     862           0 :                     Image aImage( aDictionaryImageUrl );
     863           0 :                     pMenu->SetItemImage( nItemId, aImage );
     864           0 :                 }
     865             :             }
     866             : 
     867           0 :             ++nItemId;
     868             :         }
     869           0 :     }
     870           0 :     m_pAddToDictMB->Enable( bEnable );
     871           0 :     m_pAddToDictPB->Enable( bEnable );
     872             : 
     873           0 :     int nDicts = nItemId-1;
     874             : 
     875           0 :     m_pAddToDictMB->Show( nDicts > 1 );
     876           0 :     m_pAddToDictPB->Show( nDicts <= 1 );
     877             : 
     878           0 :     return nDicts;
     879             : }
     880             : 
     881             : 
     882           0 : IMPL_LINK(SpellDialog, AddToDictClickHdl, PushButton*, EMPTYARG )
     883             : {
     884           0 :     return AddToDictionaryExecute(1, m_pAddToDictMB->GetPopupMenu());
     885             : }
     886             : 
     887             : 
     888           0 : IMPL_LINK(SpellDialog, AddToDictSelectHdl, MenuButton*, pButton )
     889             : {
     890           0 :     return AddToDictionaryExecute(pButton->GetCurItemId(), pButton->GetPopupMenu());
     891             : }
     892             : 
     893             : 
     894           0 : int SpellDialog::AddToDictionaryExecute( sal_uInt16 nItemId, PopupMenu *pMenu )
     895             : {
     896           0 :     m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
     897             : 
     898             :     //GetErrorText() returns the current error even if the text is already
     899             :     //manually changed
     900           0 :     const OUString aNewWord = m_pSentenceED->GetErrorText();
     901             : 
     902           0 :     OUString aDicName ( pMenu->GetItemText( nItemId ) );
     903             : 
     904           0 :     uno::Reference< linguistic2::XDictionary >      xDic;
     905           0 :     uno::Reference< linguistic2::XSearchableDictionaryList >  xDicList( SvxGetDictionaryList() );
     906           0 :     if (xDicList.is())
     907           0 :         xDic = xDicList->getDictionaryByName( aDicName );
     908             : 
     909           0 :     sal_Int16 nAddRes = DIC_ERR_UNKNOWN;
     910           0 :     if (xDic.is())
     911             :     {
     912           0 :         nAddRes = linguistic::AddEntryToDic( xDic, aNewWord, false, OUString(), LANGUAGE_NONE );
     913             :         // save modified user-dictionary if it is persistent
     914           0 :         uno::Reference< frame::XStorable >  xSavDic( xDic, uno::UNO_QUERY );
     915           0 :         if (xSavDic.is())
     916           0 :             xSavDic->store();
     917             : 
     918           0 :         if (nAddRes == DIC_ERR_NONE)
     919             :         {
     920             :             SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
     921           0 :                             SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
     922           0 :             pAction->SetDictionary( xDic );
     923           0 :             pAction->SetAddedWord( aNewWord );
     924           0 :             m_pSentenceED->AddUndoAction( pAction );
     925             :         }
     926             :         // failed because there is already an entry?
     927           0 :         if (DIC_ERR_NONE != nAddRes && xDic->getEntry( aNewWord ).is())
     928           0 :             nAddRes = DIC_ERR_NONE;
     929             :     }
     930           0 :     if (DIC_ERR_NONE != nAddRes)
     931             :     {
     932           0 :         SvxDicError( this, nAddRes );
     933           0 :         return 0; // don't continue
     934             :     }
     935             : 
     936             :     // go on
     937           0 :     SpellContinue_Impl();
     938           0 :     m_pSentenceED->UndoActionEnd();
     939           0 :     return 0;
     940             : }
     941             : 
     942             : 
     943           0 : IMPL_LINK(SpellDialog, ModifyHdl, SentenceEditWindow_Impl*, pEd)
     944             : {
     945           0 :     if (m_pSentenceED == pEd)
     946             :     {
     947           0 :         bModified = true;
     948           0 :         m_pSuggestionLB->SetNoSelection();
     949           0 :         m_pSuggestionLB->Disable();
     950           0 :         OUString sNewText( m_pSentenceED->GetText() );
     951           0 :         m_pAutoCorrPB->Enable( sNewText != m_pSentenceED->GetText() );
     952           0 :         SpellUndoAction_Impl* pSpellAction = new SpellUndoAction_Impl(SPELLUNDO_CHANGE_TEXTENGINE, aDialogUndoLink);
     953           0 :         if(!m_pChangeAllPB->IsEnabled())
     954             :         {
     955           0 :             m_pChangeAllPB->Enable();
     956           0 :             pSpellAction->SetEnableChangeAllPB();
     957             :         }
     958           0 :         if(!m_pChangePB->IsEnabled())
     959             :         {
     960           0 :             m_pChangePB->Enable();
     961           0 :             pSpellAction->SetEnableChangePB();
     962             :         }
     963           0 :         m_pSentenceED->AddUndoAction(pSpellAction);
     964             :     }
     965           0 :     return 0;
     966             : };
     967             : 
     968             : 
     969           0 : IMPL_LINK_NOARG(SpellDialog, CancelHdl)
     970             : {
     971             :     //apply changes and ignored text parts first - if there are any
     972           0 :     rParent.ApplyChangedSentence(m_pSentenceED->CreateSpellPortions(true), false);
     973           0 :     Close();
     974           0 :     return 0;
     975             : }
     976             : 
     977             : 
     978           0 : bool SpellDialog::Notify( NotifyEvent& rNEvt )
     979             : {
     980             :     /* #i38338#
     981             :     *   FIXME: LoseFocus and GetFocus are signals from vcl that
     982             :     *   a window actually got/lost the focus, it never should be
     983             :     *   forwarded from another window, that is simply wrong.
     984             :     *   FIXME: overloading the virtual methods GetFocus and LoseFocus
     985             :     *   in SpellDialogChildWindow by making them pure is at least questionable.
     986             :     *   The only sensible thing would be to call the new Method differently,
     987             :     *   e.g. DialogGot/LostFocus or so.
     988             :     */
     989           0 :     if( IsVisible() && !bFocusLocked )
     990             :     {
     991           0 :         if( rNEvt.GetType() ==  EVENT_GETFOCUS )
     992             :         {
     993             :             //notify the child window of the focus change
     994           0 :             rParent.GetFocus();
     995             :         }
     996           0 :         else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
     997             :         {
     998             :             //notify the child window of the focus change
     999           0 :             rParent.LoseFocus();
    1000             :         }
    1001             :     }
    1002           0 :     return SfxModelessDialog::Notify(rNEvt);
    1003             : }
    1004             : 
    1005             : 
    1006           0 : void SpellDialog::InvalidateDialog()
    1007             : {
    1008           0 :     if( bFocusLocked )
    1009           0 :         return;
    1010           0 :     m_pIgnorePB->SetText(m_sResumeST);
    1011             :     vcl::Window* aDisableArr[] =
    1012             :     {
    1013             :         m_pNotInDictFT,
    1014             :         m_pSentenceED,
    1015             :         m_pSuggestionFT,
    1016             :         m_pSuggestionLB,
    1017             :         m_pLanguageFT,
    1018             :         m_pLanguageLB,
    1019             :         m_pIgnoreAllPB,
    1020             :         m_pIgnoreRulePB,
    1021             :         m_pAddToDictMB,
    1022             :         m_pAddToDictPB,
    1023             :         m_pChangePB,
    1024             :         m_pChangeAllPB,
    1025             :         m_pAutoCorrPB,
    1026             :         m_pUndoPB,
    1027             :         0
    1028           0 :     };
    1029           0 :     sal_Int16 i = 0;
    1030           0 :     while(aDisableArr[i])
    1031             :     {
    1032           0 :         aDisableArr[i]->Enable(false);
    1033           0 :         i++;
    1034             :     }
    1035           0 :     SfxModelessDialog::Deactivate();
    1036             : }
    1037             : 
    1038             : 
    1039           0 : bool SpellDialog::GetNextSentence_Impl(bool bUseSavedSentence, bool bRecheck)
    1040             : {
    1041           0 :     bool bRet = false;
    1042           0 :     if(!bUseSavedSentence)
    1043             :     {
    1044             :         //apply changes and ignored text parts
    1045           0 :         rParent.ApplyChangedSentence(m_pSentenceED->CreateSpellPortions(true), bRecheck);
    1046             :     }
    1047           0 :     m_pSentenceED->ResetIgnoreErrorsAt();
    1048           0 :     m_pSentenceED->ResetModified();
    1049           0 :     SpellPortions aSentence = bUseSavedSentence ? m_aSavedSentence : rParent.GetNextWrongSentence( bRecheck );
    1050           0 :     if(!bUseSavedSentence)
    1051           0 :         m_aSavedSentence = aSentence;
    1052           0 :     bool bHasReplaced = false;
    1053           0 :     while(!aSentence.empty())
    1054             :     {
    1055             :         //apply all changes that are already part of the "ChangeAllList"
    1056             :         //returns true if the list still contains errors after the changes have been applied
    1057             : 
    1058           0 :         if(!ApplyChangeAllList_Impl(aSentence, bHasReplaced))
    1059             :         {
    1060           0 :             rParent.ApplyChangedSentence(aSentence, bRecheck);
    1061           0 :             aSentence = rParent.GetNextWrongSentence( bRecheck );
    1062             :         }
    1063             :         else
    1064           0 :             break;
    1065             :     }
    1066             : 
    1067           0 :     if(!aSentence.empty())
    1068             :     {
    1069           0 :         SpellPortions::iterator aStart = aSentence.begin();
    1070           0 :         OUString sText;
    1071           0 :         while(aStart != aSentence.end())
    1072             :         {
    1073             :             // hidden text has to be ignored
    1074           0 :             if(!aStart->bIsHidden)
    1075           0 :                 sText += aStart->sText;
    1076           0 :             ++aStart;
    1077             :         }
    1078           0 :         m_pSentenceED->SetText(sText);
    1079           0 :         aStart = aSentence.begin();
    1080           0 :         sal_Int32 nStartPosition = 0;
    1081           0 :         sal_Int32 nEndPosition = 0;
    1082             : 
    1083           0 :         while(aStart != aSentence.end())
    1084             :         {
    1085             :             // hidden text has to be ignored
    1086           0 :             if(!aStart->bIsHidden)
    1087             :             {
    1088           0 :                 nEndPosition += aStart->sText.getLength();
    1089           0 :                 if(aStart->xAlternatives.is())
    1090             :                 {
    1091           0 :                     uno::Reference< container::XNamed > xNamed( aStart->xAlternatives, uno::UNO_QUERY );
    1092           0 :                     OUString sServiceName;
    1093           0 :                     if( xNamed.is() )
    1094           0 :                         sServiceName = xNamed->getName();
    1095           0 :                     SpellErrorDescription aDesc( false, aStart->xAlternatives->getWord(),
    1096           0 :                                     aStart->xAlternatives->getLocale(), aStart->xAlternatives->getAlternatives(), 0, sServiceName);
    1097           0 :                     m_pSentenceED->SetAttrib( SpellErrorAttrib(aDesc), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
    1098             :                 }
    1099           0 :                 else if(aStart->bIsGrammarError )
    1100             :                 {
    1101           0 :                     beans::PropertyValues  aProperties = aStart->aGrammarError.aProperties;
    1102           0 :                     OUString sFullCommentURL;
    1103           0 :                     sal_Int32 i = 0;
    1104           0 :                     while ( sFullCommentURL.isEmpty() && i < aProperties.getLength() )
    1105             :                     {
    1106           0 :                         if ( aProperties[i].Name == "FullCommentURL" )
    1107             :                         {
    1108           0 :                             uno::Any aValue = aProperties[i].Value;
    1109           0 :                             aValue >>= sFullCommentURL;
    1110             :                         }
    1111           0 :                         ++i;
    1112             :                     }
    1113             : 
    1114           0 :                     uno::Reference< lang::XServiceInfo > xInfo( aStart->xGrammarChecker, uno::UNO_QUERY );
    1115             :                     SpellErrorDescription aDesc( true,
    1116           0 :                         aStart->sText,
    1117           0 :                         LanguageTag::convertToLocale( aStart->eLanguage ),
    1118           0 :                         aStart->aGrammarError.aSuggestions,
    1119           0 :                         aStart->xGrammarChecker,
    1120           0 :                         xInfo->getImplementationName(),
    1121           0 :                         &aStart->sDialogTitle,
    1122           0 :                         &aStart->aGrammarError.aFullComment,
    1123           0 :                         &aStart->aGrammarError.aRuleIdentifier,
    1124           0 :                         &sFullCommentURL );
    1125           0 :                     m_pSentenceED->SetAttrib( SpellErrorAttrib(aDesc), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
    1126             :                 }
    1127           0 :                 if(aStart->bIsField)
    1128           0 :                     m_pSentenceED->SetAttrib( SpellBackgroundAttrib(COL_LIGHTGRAY), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
    1129           0 :                 m_pSentenceED->SetAttrib( SpellLanguageAttrib(aStart->eLanguage), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
    1130           0 :                 nStartPosition = nEndPosition;
    1131             :             }
    1132           0 :             ++aStart;
    1133             :         }
    1134             :         //the edit field needs to be modified to apply the change from the ApplyChangeAllList
    1135           0 :         if(!bHasReplaced)
    1136           0 :             m_pSentenceED->ClearModifyFlag();
    1137           0 :         m_pSentenceED->ResetUndo();
    1138           0 :         m_pUndoPB->Enable(false);
    1139           0 :         bRet = nStartPosition > 0;
    1140             :     }
    1141           0 :     return bRet;
    1142             : }
    1143             : /*-------------------------------------------------------------------------
    1144             :     replace errors that have a replacement in the ChangeAllList
    1145             :     returns false if the result doesn't contain errors after the replacement
    1146             :   -----------------------------------------------------------------------*/
    1147           0 : bool SpellDialog::ApplyChangeAllList_Impl(SpellPortions& rSentence, bool &bHasReplaced)
    1148             : {
    1149           0 :     bHasReplaced = false;
    1150           0 :     bool bRet = true;
    1151           0 :     SpellPortions::iterator aStart = rSentence.begin();
    1152           0 :     Reference<XDictionary> xChangeAll( SvxGetChangeAllList(), UNO_QUERY );
    1153           0 :     if(!xChangeAll->getCount())
    1154           0 :         return bRet;
    1155           0 :     bRet = false;
    1156           0 :     while(aStart != rSentence.end())
    1157             :     {
    1158           0 :         if(aStart->xAlternatives.is())
    1159             :         {
    1160           0 :             const OUString &rString = aStart->sText;
    1161             : 
    1162           0 :             Reference<XDictionaryEntry> xEntry = xChangeAll->getEntry(rString);
    1163             : 
    1164           0 :             if(xEntry.is())
    1165             :             {
    1166           0 :                 aStart->sText = getDotReplacementString(rString, xEntry->getReplacementText());
    1167           0 :                 aStart->xAlternatives = 0;
    1168           0 :                 bHasReplaced = true;
    1169             :             }
    1170             :             else
    1171           0 :                 bRet = true;
    1172             :         }
    1173           0 :         else if( aStart->bIsGrammarError )
    1174           0 :             bRet = true;
    1175           0 :         ++aStart;
    1176             :     }
    1177           0 :     return bRet;
    1178             : }
    1179             : 
    1180             : 
    1181           0 : SentenceEditWindow_Impl::SentenceEditWindow_Impl(vcl::Window * pParent, WinBits nBits)
    1182             :     : VclMultiLineEdit(pParent, nBits)
    1183             :     , m_nErrorStart(0)
    1184             :     , m_nErrorEnd(0)
    1185           0 :     , m_bIsUndoEditMode(false)
    1186             : {
    1187           0 :     DisableSelectionOnFocus();
    1188           0 : }
    1189             : 
    1190           0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSentenceEditWindow(vcl::Window *pParent,
    1191             :     VclBuilder::stringmap &)
    1192             : {
    1193           0 :     return new SentenceEditWindow_Impl(pParent, WB_BORDER|WB_VSCROLL|WB_IGNORETAB);
    1194             : }
    1195             : 
    1196             : 
    1197           0 : SentenceEditWindow_Impl::~SentenceEditWindow_Impl()
    1198             : {
    1199           0 : }
    1200             : /*-------------------------------------------------------------------------
    1201             :     The selection before inputting a key may have a range or not
    1202             :     and it may be inside or outside of field or error attributes.
    1203             :     A range may include the attribute partially, completely or together
    1204             :     with surrounding text. It may also contain more than one attribute
    1205             :     or no attribute at all.
    1206             :     Depending on this starting conditions some actions are necessary:
    1207             :     Attempts to delete a field are only allowed if the selection is the same
    1208             :     as the field's selection. Otherwise the field has to be selected and the key
    1209             :     input action has to be skipped.
    1210             :     Input of text at the start of the field requires the field attribute to be
    1211             :     corrected - it is not allowed to grow.
    1212             : 
    1213             :     In case of errors the appending of text should grow the error attribute because
    1214             :     that is what the user usually wants to do.
    1215             : 
    1216             :     Backspace at the start of the attribute requires to find out if a field ends
    1217             :     directly in front of the cursor position. In case of a field this attribute has to be
    1218             :     selected otherwise the key input method is allowed.
    1219             : 
    1220             :     All changes outside of the error attributes switch the dialog mode to a "Undo edit" state that
    1221             :     removes all visible attributes and switches off further attribute checks.
    1222             :     Undo in this restarts the dialog with a current sentence newly presented.
    1223             :     All changes to the sentence are undone including the ones before the "Undo edit state" has been reached
    1224             : 
    1225             :     We end up with 9 types of selection
    1226             :     1 (LEFT_NO)     - no range, start of attribute - can also be 3 at the same time
    1227             :     2 (INSIDE_NO)   - no range, inside of attribute
    1228             :     3 (RIGHT_NO)    - no range, end of attribute - can also be 1 at the same time
    1229             :     4 (FULL)        - range, same as attribute
    1230             :     5 (INSIDE_YES)  - range, inside of the attribute
    1231             :     6 (BRACE)- range, from outside of the attribute to the inside or
    1232             :                 including the complete attribute and something outside,
    1233             :                 maybe more than one attribute
    1234             :     7 (OUTSIDE_NO)  - no range, not at an attribute
    1235             :     8 (OUTSIDE_YES) - range, completely outside of all attributes
    1236             : 
    1237             :     What has to be done depending on the attribute type involved
    1238             :     possible actions:   UE - Undo edit mode
    1239             :                         CO - Continue, no additional action is required
    1240             :                         FS - Field has to be completely selected
    1241             :                         EX - The attribute has to be expanded to include the added text
    1242             : 
    1243             :     1 - backspace                   delete                      any other
    1244             :         UE                          on field FS on error CO     on field FS on error CO
    1245             : 
    1246             :     2 - on field FS on error C
    1247             :     3 - backspace                   delete                      any other
    1248             :         on field FS on error CO     UE                          on field UE on error EX
    1249             : 
    1250             :     if 1 and 3 happen to apply both then backspace and other handling is 1 delete is 3
    1251             : 
    1252             :     4 - on field UE and on error CO
    1253             :     5 - on field FS and on error CO
    1254             :     6 - on field FS and on error UE
    1255             :     7 - UE
    1256             :     8 - UE
    1257             :   -----------------------------------------------------------------------*/
    1258             : #define     INVALID     0
    1259             : #define     LEFT_NO     1
    1260             : #define     INSIDE_NO   2
    1261             : #define     RIGHT_NO    3
    1262             : #define     FULL        4
    1263             : #define     INSIDE_YES  5
    1264             : #define     BRACE       6
    1265             : #define     OUTSIDE_NO  7
    1266             : #define     OUTSIDE_YES 8
    1267             : 
    1268             : #define ACTION_UNDOEDIT    0
    1269             : #define ACTION_CONTINUE    1
    1270             : #define ACTION_SELECTFIELD 2
    1271             : #define ACTION_EXPAND      3
    1272             : 
    1273           0 : bool SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
    1274             : {
    1275           0 :     bool bChange = false;
    1276           0 :     const TextCharAttrib*  pErrorAttrib = 0;
    1277           0 :     if(rNEvt.GetType() == EVENT_KEYINPUT)
    1278             :     {
    1279           0 :         const KeyEvent& rKeyEvt = *rNEvt.GetKeyEvent();
    1280           0 :         bChange = TextEngine::DoesKeyChangeText( rKeyEvt );
    1281           0 :         if(bChange && !IsUndoEditMode() &&
    1282           0 :             rKeyEvt.GetKeyCode().GetCode() != KEY_TAB)
    1283             :         {
    1284           0 :             TextEngine* pTextEngine = GetTextEngine();
    1285           0 :             TextView* pTextView = pTextEngine->GetActiveView();
    1286           0 :             const TextSelection& rCurrentSelection = pTextView->GetSelection();
    1287             :             //determine if the selection contains a field
    1288           0 :             bool bHasField = false;
    1289           0 :             bool bHasError = false;
    1290           0 :             bool bHasFieldLeft = false;
    1291           0 :             bool bHasErrorLeft = false;
    1292             : 
    1293           0 :             bool bHasRange = rCurrentSelection.HasRange();
    1294           0 :             sal_uInt8 nSelectionType = 0; // invalid type!
    1295             : 
    1296           0 :             TextPaM aCursor(rCurrentSelection.GetStart());
    1297           0 :             const TextCharAttrib* pBackAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
    1298           0 :             const TextCharAttrib* pErrorAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
    1299           0 :             const TextCharAttrib* pBackAttrLeft = 0;
    1300           0 :             const TextCharAttrib* pErrorAttrLeft = 0;
    1301             : 
    1302           0 :             bHasField = pBackAttr != 0 && (bHasRange || pBackAttr->GetEnd() > aCursor.GetIndex());
    1303           0 :             bHasError = pErrorAttr != 0 && (bHasRange || pErrorAttr->GetEnd() > aCursor.GetIndex());
    1304           0 :             if(bHasRange)
    1305             :             {
    1306           0 :                 if(pBackAttr &&
    1307           0 :                         pBackAttr->GetStart() == rCurrentSelection.GetStart().GetIndex() &&
    1308           0 :                         pBackAttr->GetEnd() == rCurrentSelection.GetEnd().GetIndex())
    1309             :                 {
    1310           0 :                     nSelectionType = FULL;
    1311             :                 }
    1312           0 :                 else if(pErrorAttr &&
    1313           0 :                         pErrorAttr->GetStart() <= rCurrentSelection.GetStart().GetIndex() &&
    1314           0 :                         pErrorAttr->GetEnd() >= rCurrentSelection.GetEnd().GetIndex())
    1315             :                 {
    1316           0 :                     nSelectionType = INSIDE_YES;
    1317             :                 }
    1318             :                 else
    1319             :                 {
    1320           0 :                     nSelectionType = bHasField||bHasError ? BRACE : OUTSIDE_NO;
    1321           0 :                     while(aCursor.GetIndex() < rCurrentSelection.GetEnd().GetIndex())
    1322             :                     {
    1323           0 :                         ++aCursor.GetIndex();
    1324           0 :                         const TextCharAttrib* pIntBackAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
    1325           0 :                         const TextCharAttrib* pIntErrorAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
    1326             :                         //if any attr has been found then BRACE
    1327           0 :                         if(pIntBackAttr || pIntErrorAttr)
    1328           0 :                             nSelectionType = BRACE;
    1329             :                         //the field has to be selected
    1330           0 :                         if(pIntBackAttr && !pBackAttr)
    1331           0 :                             pBackAttr = pIntBackAttr;
    1332           0 :                         bHasField |= pIntBackAttr != 0;
    1333             :                     }
    1334             :                 }
    1335             :             }
    1336             :             else
    1337             :             {
    1338             :                 //no range selection: then 1 2 3 and 8 are possible
    1339           0 :                 const TextCharAttrib* pCurAttr = pBackAttr ? pBackAttr : pErrorAttr;
    1340           0 :                 if(pCurAttr)
    1341             :                 {
    1342           0 :                     nSelectionType = pCurAttr->GetStart() == rCurrentSelection.GetStart().GetIndex() ?
    1343           0 :                             LEFT_NO : pCurAttr->GetEnd() == rCurrentSelection.GetEnd().GetIndex() ? RIGHT_NO : INSIDE_NO;
    1344             :                 }
    1345             :                 else
    1346           0 :                     nSelectionType = OUTSIDE_NO;
    1347             : 
    1348           0 :                 bHasFieldLeft = pBackAttr && pBackAttr->GetEnd() == aCursor.GetIndex();
    1349           0 :                 if(bHasFieldLeft)
    1350             :                 {
    1351           0 :                     pBackAttrLeft = pBackAttr;
    1352           0 :                     pBackAttr = 0;
    1353             :                 }
    1354           0 :                 bHasErrorLeft = pErrorAttr && pErrorAttr->GetEnd() == aCursor.GetIndex();
    1355           0 :                 if(bHasErrorLeft)
    1356             :                 {
    1357           0 :                     pErrorAttrLeft = pErrorAttr;
    1358           0 :                     pErrorAttr = 0;
    1359             :                 }
    1360             : 
    1361             :                 //check previous position if this exists
    1362             :                 //that is a redundant in the case the attribute found above already is on the left cursor side
    1363             :                 //but it's o.k. for two errors/fields side by side
    1364           0 :                 if(aCursor.GetIndex())
    1365             :                 {
    1366           0 :                     --aCursor.GetIndex();
    1367           0 :                     pBackAttrLeft = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
    1368           0 :                     pErrorAttrLeft = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
    1369           0 :                     bHasFieldLeft = pBackAttrLeft !=0;
    1370           0 :                     bHasErrorLeft = pErrorAttrLeft != 0;
    1371           0 :                     ++aCursor.GetIndex();
    1372             :                 }
    1373             :             }
    1374             :             //Here we have to determine if the error found is the one currently active
    1375           0 :             bool bIsErrorActive = (pErrorAttr && pErrorAttr->GetStart() == m_nErrorStart) ||
    1376           0 :                     (pErrorAttrLeft && pErrorAttrLeft->GetStart() == m_nErrorStart);
    1377             : 
    1378             :             SAL_WARN_IF(
    1379             :                 nSelectionType == INVALID, "cui.dialogs",
    1380             :                 "selection type not set");
    1381             : 
    1382           0 :             const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
    1383           0 :             bool bDelete = rKeyCode.GetCode() == KEY_DELETE;
    1384           0 :             bool bBackspace = rKeyCode.GetCode() == KEY_BACKSPACE;
    1385             : 
    1386           0 :             sal_Int8 nAction = ACTION_CONTINUE;
    1387           0 :             switch(nSelectionType)
    1388             :             {
    1389             : //    1 - backspace                   delete                      any other
    1390             : //        UE                          on field FS on error CO     on field FS on error CO
    1391             :                 case LEFT_NO    :
    1392           0 :                     if(bBackspace)
    1393             :                     {
    1394           0 :                         nAction = bHasFieldLeft ? ACTION_SELECTFIELD : ACTION_UNDOEDIT;
    1395             :                         //to force the use of pBackAttrLeft
    1396           0 :                         pBackAttr = 0;
    1397             :                     }
    1398           0 :                     else if(bDelete)
    1399           0 :                         nAction = bHasField ? ACTION_SELECTFIELD : ACTION_CONTINUE;
    1400             :                     else
    1401           0 :                         nAction = bHasError && !aCursor.GetIndex() ? ACTION_CONTINUE :
    1402           0 :                             bHasError ? ACTION_EXPAND : bHasErrorLeft ? ACTION_CONTINUE : ACTION_UNDOEDIT;
    1403           0 :                 break;
    1404             : //    2 - on field FS on error C
    1405             :                 case INSIDE_NO  :
    1406             :                     nAction =  bHasField ? ACTION_SELECTFIELD :
    1407           0 :                         bIsErrorActive ? ACTION_CONTINUE : ACTION_UNDOEDIT;
    1408           0 :                 break;
    1409             : //    3 - backspace                   delete                      any other
    1410             : //        on field FS on error CO     UE                          on field UE on error EX
    1411             :                 case RIGHT_NO   :
    1412           0 :                     if(bBackspace)
    1413           0 :                         nAction = bHasFieldLeft ? ACTION_SELECTFIELD : ACTION_CONTINUE;
    1414           0 :                     else if(bDelete)
    1415           0 :                         nAction = bHasFieldLeft && bHasError ? ACTION_CONTINUE : ACTION_UNDOEDIT;
    1416             :                     else
    1417           0 :                         nAction = bHasFieldLeft && bHasError ? ACTION_EXPAND :
    1418           0 :                             bHasError ? ACTION_CONTINUE : bHasErrorLeft ? ACTION_EXPAND :ACTION_UNDOEDIT;
    1419           0 :                 break;
    1420             : //    4 - on field UE and on error CO
    1421             :                 case FULL       :
    1422           0 :                     nAction = bHasField ? ACTION_UNDOEDIT : ACTION_CONTINUE;
    1423           0 :                 break;
    1424             : //    5 - on field FS and on error CO
    1425             :                 case INSIDE_YES :
    1426           0 :                     nAction = bHasField ? ACTION_SELECTFIELD : ACTION_CONTINUE;
    1427           0 :                 break;
    1428             : //    6 - on field FS and on error UE
    1429             :                 case BRACE      :
    1430           0 :                     nAction = bHasField ? ACTION_SELECTFIELD : ACTION_UNDOEDIT;;
    1431           0 :                 break;
    1432             : //    7 - UE
    1433             : //    8 - UE
    1434             :                 case OUTSIDE_NO :
    1435             :                 case OUTSIDE_YES:
    1436           0 :                     nAction = ACTION_UNDOEDIT;
    1437           0 :                 break;
    1438             :             }
    1439             :             //save the current paragraph
    1440           0 :             sal_Int32 nCurrentLen = GetText().getLength();
    1441           0 :             if(nAction != ACTION_SELECTFIELD)
    1442           0 :                 pTextView->GetWindow()->KeyInput(rKeyEvt);
    1443             :             else
    1444             :             {
    1445           0 :                 const TextCharAttrib* pCharAttr = pBackAttr ? pBackAttr : pBackAttrLeft;
    1446           0 :                 if(pCharAttr)
    1447             :                 {
    1448           0 :                     TextPaM aStart(0, pCharAttr->GetStart());
    1449           0 :                     TextPaM aEnd(0, pCharAttr->GetEnd());
    1450           0 :                     TextSelection aNewSel(aStart, aEnd);
    1451           0 :                     pTextView->SetSelection( aNewSel);
    1452             :                 }
    1453             :             }
    1454           0 :             if(nAction == ACTION_EXPAND)
    1455             :             {
    1456             :                 DBG_ASSERT(pErrorAttrLeft || pErrorAttr, "where is the error");
    1457             :                 //text has been added on the right and only the 'error attribute has to be corrected
    1458           0 :                 if(pErrorAttrLeft)
    1459             :                 {
    1460           0 :                     boost::scoped_ptr<TextAttrib> pNewError(pErrorAttrLeft->GetAttr().Clone());
    1461           0 :                     sal_uInt16 nStart = pErrorAttrLeft->GetStart();
    1462           0 :                     sal_uInt16 nEnd = pErrorAttrLeft->GetEnd();
    1463           0 :                     pTextEngine->RemoveAttrib( 0, *pErrorAttrLeft );
    1464           0 :                     SetAttrib( *pNewError, 0, nStart, ++nEnd );
    1465             :                     //only active errors move the mark
    1466           0 :                     if(bIsErrorActive)
    1467             :                     {
    1468           0 :                         bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
    1469           0 :                         MoveErrorMarkTo(nStart, nEnd, bGrammar);
    1470           0 :                     }
    1471             :                 }
    1472             :                 //text has been added on the left then the error attribute has to be expanded and the
    1473             :                 //field attribute on the right - if any - has to be contracted
    1474           0 :                 else if(pErrorAttr)
    1475             :                 {
    1476             :                     //determine the change
    1477           0 :                     sal_Int32 nAddedChars = GetText().getLength() - nCurrentLen;
    1478             : 
    1479           0 :                     boost::scoped_ptr<TextAttrib> pNewError(pErrorAttr->GetAttr().Clone());
    1480           0 :                     sal_Int32 nStart = pErrorAttr->GetStart();
    1481           0 :                     sal_Int32 nEnd = pErrorAttr->GetEnd();
    1482           0 :                     pTextEngine->RemoveAttrib( 0, *pErrorAttr );
    1483           0 :                     nStart = nStart - nAddedChars;
    1484           0 :                     SetAttrib( *pNewError, 0, nStart - nAddedChars, nEnd );
    1485             :                     //only if the error is active the mark is moved here
    1486           0 :                     if(bIsErrorActive)
    1487             :                     {
    1488           0 :                         bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
    1489           0 :                         MoveErrorMarkTo(nStart, nEnd, bGrammar);
    1490             :                     }
    1491           0 :                     pNewError.reset();
    1492             : 
    1493           0 :                     if(pBackAttrLeft)
    1494             :                     {
    1495           0 :                         boost::scoped_ptr<TextAttrib> pNewBack(pBackAttrLeft->GetAttr().Clone());
    1496           0 :                         sal_uInt16 _nStart = pBackAttrLeft->GetStart();
    1497           0 :                         sal_uInt16 _nEnd = pBackAttrLeft->GetEnd();
    1498           0 :                         pTextEngine->RemoveAttrib( 0, *pBackAttrLeft );
    1499           0 :                         SetAttrib( *pNewBack, 0, _nStart, _nEnd - nAddedChars);
    1500           0 :                     }
    1501             :                 }
    1502             :             }
    1503           0 :             else if(nAction == ACTION_UNDOEDIT)
    1504             :             {
    1505           0 :                 SetUndoEditMode(true);
    1506             :             }
    1507             :             //make sure the error positions are correct after text changes
    1508             :             //the old attribute may have been deleted
    1509             :             //all changes inside of the current error leave the error attribute at the current
    1510             :             //start position
    1511           0 :             if(!IsUndoEditMode() && bIsErrorActive)
    1512             :             {
    1513           0 :                 const TextCharAttrib* pFontColor = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_FONTCOLOR );
    1514           0 :                 pErrorAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_ERROR );
    1515           0 :                 if(pFontColor && pErrorAttrib )
    1516             :                 {
    1517           0 :                     m_nErrorStart = pFontColor->GetStart();
    1518           0 :                     m_nErrorEnd = pFontColor->GetEnd();
    1519           0 :                     if(pErrorAttrib->GetStart() != m_nErrorStart || pErrorAttrib->GetEnd() != m_nErrorEnd)
    1520             :                     {
    1521           0 :                         boost::scoped_ptr<TextAttrib> pNewError(pErrorAttrib->GetAttr().Clone());
    1522           0 :                         pTextEngine->RemoveAttrib( 0, *pErrorAttr );
    1523           0 :                         SetAttrib( *pNewError, 0, m_nErrorStart, m_nErrorEnd );
    1524             :                     }
    1525             :                 }
    1526             :             }
    1527             :             //this is not a modification anymore
    1528           0 :             if(nAction != ACTION_SELECTFIELD && !m_bIsUndoEditMode)
    1529           0 :                 CallModifyLink();
    1530             :         }
    1531             :         else
    1532           0 :             bChange = false;
    1533             :     }
    1534           0 :     return bChange || VclMultiLineEdit::PreNotify(rNEvt);
    1535             : }
    1536             : 
    1537             : 
    1538           0 : bool SentenceEditWindow_Impl::MarkNextError( bool bIgnoreCurrentError, com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellChecker1> xSpell )
    1539             : {
    1540           0 :     if (bIgnoreCurrentError)
    1541           0 :         m_aIgnoreErrorsAt.insert( m_nErrorStart );
    1542           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1543           0 :     sal_uInt16 nTextLen = pTextEngine->GetTextLen(0);
    1544           0 :     if(m_nErrorEnd >= nTextLen - 1)
    1545           0 :         return false;
    1546             :     //if it's not already modified the modified flag has to be reset at the end of the marking
    1547           0 :     bool bModified = IsModified();
    1548           0 :     bool bRet = false;
    1549           0 :     const sal_uInt16 nOldErrorStart = m_nErrorStart;
    1550           0 :     const sal_uInt16 nOldErrorEnd   = m_nErrorEnd;
    1551             : 
    1552             :     //create a cursor behind the end of the last error
    1553             :     //- or at 0 at the start of the sentence
    1554           0 :     TextPaM aCursor(0, m_nErrorEnd ? m_nErrorEnd + 1 : 0);
    1555             :     //search for SpellErrorAttrib
    1556             : 
    1557           0 :     const TextCharAttrib* pNextError = 0;
    1558             :     //iterate over the text and search for the next error that maybe has
    1559             :     //to be replace by a ChangeAllList replacement
    1560           0 :     bool bGrammarError = false;
    1561           0 :     while(aCursor.GetIndex() < nTextLen)
    1562             :     {
    1563           0 :         while(aCursor.GetIndex() < nTextLen &&
    1564           0 :                 0 == (pNextError = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR)))
    1565             :         {
    1566           0 :             ++aCursor.GetIndex();
    1567             :         }
    1568             :         // maybe the error found here is already in the ChangeAllList and has to be replaced
    1569             : 
    1570           0 :         Reference<XDictionary> xChangeAll( SvxGetChangeAllList(), UNO_QUERY );
    1571           0 :         Reference<XDictionaryEntry> xEntry;
    1572             : 
    1573           0 :         const SpellErrorDescription* pSpellErrorDescription = 0;
    1574           0 :         if(pNextError)
    1575             :         {
    1576           0 :             pSpellErrorDescription = &static_cast<const SpellErrorAttrib&>(pNextError->GetAttr()).GetErrorDescription();
    1577           0 :             bGrammarError = pSpellErrorDescription->bIsGrammarError;
    1578           0 :             m_nErrorStart = pNextError->GetStart();
    1579           0 :             m_nErrorEnd = pNextError->GetEnd();
    1580             :         }
    1581           0 :         if(xChangeAll->getCount() && pSpellErrorDescription &&
    1582           0 :                 (xEntry = xChangeAll->getEntry( pSpellErrorDescription->sErrorText )).is())
    1583             :         {
    1584             : 
    1585           0 :             OUString sReplacement(getDotReplacementString(GetErrorText(), xEntry->getReplacementText()));
    1586             : 
    1587           0 :             ChangeMarkedWord(sReplacement, LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale ));
    1588             : 
    1589           0 :             aCursor.GetIndex() = aCursor.GetIndex() + (sal_uInt16)(xEntry->getReplacementText().getLength());
    1590             :         // maybe the error found here is already added to the dictionary and has to be ignored
    1591           0 :         } else if(pSpellErrorDescription && !bGrammarError && xSpell->isValid( GetErrorText(), LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale ), Sequence< PropertyValue >() )) {
    1592           0 :             aCursor.GetIndex() = aCursor.GetIndex() + 1;
    1593             :         }
    1594             :         else
    1595           0 :             break;
    1596           0 :     }
    1597             : 
    1598             :     //if an attrib has been found search for the end of the error string
    1599           0 :     if(aCursor.GetIndex() < nTextLen)
    1600             :     {
    1601           0 :         m_nErrorStart = aCursor.GetIndex();
    1602           0 :         m_nErrorEnd = pNextError->GetEnd();
    1603           0 :         MoveErrorMarkTo(m_nErrorStart, m_nErrorEnd, bGrammarError);
    1604           0 :         bRet = true;
    1605             :         //add an undo action
    1606             :         SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
    1607           0 :                 SPELLUNDO_CHANGE_NEXTERROR, GetSpellDialog()->aDialogUndoLink);
    1608           0 :         pAction->SetErrorMove(m_nErrorStart, m_nErrorEnd, nOldErrorStart, nOldErrorEnd);
    1609             :         const SpellErrorAttrib* pOldAttrib = static_cast<const SpellErrorAttrib*>(
    1610           0 :                 pTextEngine->FindAttrib( TextPaM(0, nOldErrorStart), TEXTATTR_SPELL_ERROR ));
    1611           0 :         pAction->SetErrorLanguageSelected(pOldAttrib && pOldAttrib->GetErrorDescription().aSuggestions.getLength() &&
    1612           0 :                 LanguageTag( pOldAttrib->GetErrorDescription().aLocale).getLanguageType() ==
    1613           0 :                                         GetSpellDialog()->m_pLanguageLB->GetSelectLanguage());
    1614           0 :         AddUndoAction(pAction);
    1615             :     }
    1616             :     else
    1617           0 :         m_nErrorStart = m_nErrorEnd = nTextLen;
    1618           0 :     if( !bModified )
    1619           0 :         ClearModifyFlag();
    1620           0 :     SpellDialog* pSpellDialog = GetSpellDialog();
    1621           0 :     pSpellDialog->m_pIgnorePB->Enable(bRet);
    1622           0 :     pSpellDialog->m_pIgnoreAllPB->Enable(bRet);
    1623           0 :     pSpellDialog->m_pAutoCorrPB->Enable(bRet);
    1624           0 :     pSpellDialog->m_pAddToDictMB->Enable(bRet);
    1625           0 :     pSpellDialog->m_pAddToDictPB->Enable(bRet);
    1626           0 :     return bRet;
    1627             : }
    1628             : 
    1629             : 
    1630           0 : void SentenceEditWindow_Impl::MoveErrorMarkTo(sal_uInt16 nStart, sal_uInt16 nEnd, bool bGrammarError)
    1631             : {
    1632           0 :     TextEngine* pTextEngine = GetTextEngine();
    1633           0 :     pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTCOLOR, true );
    1634           0 :     pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTWEIGHT, true );
    1635           0 :     pTextEngine->SetAttrib( TextAttribFontWeight(WEIGHT_BOLD), 0, nStart, nEnd );
    1636           0 :     pTextEngine->SetAttrib( TextAttribFontColor(bGrammarError ? COL_LIGHTBLUE : COL_LIGHTRED), 0, nStart, nEnd );
    1637           0 :     m_nErrorStart = nStart;
    1638           0 :     m_nErrorEnd = nEnd;
    1639           0 : }
    1640             : 
    1641             : 
    1642           0 : void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, LanguageType eLanguage)
    1643             : {
    1644             :     //calculate length changes
    1645           0 :     long nDiffLen = rNewWord.getLength() - m_nErrorEnd + m_nErrorStart;
    1646           0 :     TextSelection aSel(TextPaM(0, m_nErrorStart), TextPaM(0, m_nErrorEnd));
    1647             :     //Remove spell error attribute
    1648           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1649           0 :     pTextEngine->UndoActionStart();
    1650           0 :     const TextCharAttrib*  pErrorAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_ERROR );
    1651             :     DBG_ASSERT(pErrorAttrib, "no error attribute found");
    1652           0 :     const SpellErrorDescription* pSpellErrorDescription = 0;
    1653           0 :     if(pErrorAttrib)
    1654             :     {
    1655           0 :         pTextEngine->RemoveAttrib(0, *pErrorAttrib);
    1656           0 :         pSpellErrorDescription = &static_cast<const SpellErrorAttrib&>(pErrorAttrib->GetAttr()).GetErrorDescription();
    1657             :     }
    1658           0 :     const TextCharAttrib*  pBackAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_BACKGROUND );
    1659           0 :     pTextEngine->ReplaceText( aSel, rNewWord );
    1660             : 
    1661           0 :     if(!m_nErrorStart)
    1662             :     {
    1663             :         //attributes following an error at the start of the text are not moved but expanded from the
    1664             :         //text engine - this is done to keep full-paragraph-attributes
    1665             :         //in the current case that handling is not desired
    1666             :         const TextCharAttrib*  pLangAttrib =
    1667             :                 pTextEngine->FindCharAttrib(
    1668           0 :                     TextPaM(0, m_nErrorEnd), TEXTATTR_SPELL_LANGUAGE );
    1669           0 :         sal_uInt16 nTextLen = pTextEngine->GetTextLen( 0 );
    1670           0 :         if(pLangAttrib && !pLangAttrib->GetStart() && pLangAttrib->GetEnd() ==
    1671             :             nTextLen)
    1672             :         {
    1673           0 :             SpellLanguageAttrib aNewLangAttrib( static_cast<const SpellLanguageAttrib&>(pLangAttrib->GetAttr()).GetLanguage());
    1674           0 :             pTextEngine->RemoveAttrib(0, *pLangAttrib);
    1675           0 :             pTextEngine->SetAttrib( aNewLangAttrib, 0, (sal_uInt16)(m_nErrorEnd + nDiffLen) , nTextLen );
    1676             :         }
    1677             :     }
    1678             :     // undo expanded attributes!
    1679           0 :     if( pBackAttrib && pBackAttrib->GetStart() < m_nErrorStart && pBackAttrib->GetEnd() == m_nErrorEnd + nDiffLen)
    1680             :     {
    1681           0 :         boost::scoped_ptr<TextAttrib> pNewBackground(pBackAttrib->GetAttr().Clone());
    1682           0 :         sal_uInt16 nStart = pBackAttrib->GetStart();
    1683           0 :         pTextEngine->RemoveAttrib(0, *pBackAttrib);
    1684           0 :         pTextEngine->SetAttrib(*pNewBackground, 0, nStart, m_nErrorStart);
    1685             :     }
    1686           0 :     pTextEngine->SetModified(true);
    1687             : 
    1688             :     //adjust end position
    1689           0 :     long nEndTemp = m_nErrorEnd;
    1690           0 :     nEndTemp += nDiffLen;
    1691           0 :     m_nErrorEnd = (sal_uInt16)nEndTemp;
    1692             : 
    1693             :     SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
    1694           0 :                     SPELLUNDO_MOVE_ERROREND, GetSpellDialog()->aDialogUndoLink);
    1695           0 :     pAction->SetOffset(nDiffLen);
    1696           0 :     AddUndoAction(pAction);
    1697           0 :     if(pSpellErrorDescription)
    1698           0 :         SetAttrib( SpellErrorAttrib(*pSpellErrorDescription), 0, m_nErrorStart, m_nErrorEnd );
    1699           0 :     SetAttrib( SpellLanguageAttrib(eLanguage), 0, m_nErrorStart, m_nErrorEnd );
    1700           0 :     pTextEngine->UndoActionEnd();
    1701           0 : }
    1702             : 
    1703             : 
    1704           0 : OUString SentenceEditWindow_Impl::GetErrorText() const
    1705             : {
    1706           0 :     return GetTextEngine()->GetText(TextSelection(TextPaM(0, m_nErrorStart), TextPaM(0, m_nErrorEnd) ));
    1707             : }
    1708             : 
    1709             : 
    1710           0 : const SpellErrorDescription* SentenceEditWindow_Impl::GetAlternatives()
    1711             : {
    1712           0 :     TextPaM aCursor(0, m_nErrorStart);
    1713             :     const SpellErrorAttrib* pAttrib = static_cast<const SpellErrorAttrib*>(
    1714           0 :             GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR));
    1715           0 :     return pAttrib ? &pAttrib->GetErrorDescription() : 0;
    1716             : }
    1717             : 
    1718             : 
    1719           0 : void SentenceEditWindow_Impl::RestoreCurrentError()
    1720             : {
    1721           0 :     TextPaM aCursor(0, m_nErrorStart);
    1722             :     const SpellErrorAttrib* pAttrib = static_cast<const SpellErrorAttrib*>(
    1723           0 :             GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR));
    1724           0 :     if( pAttrib )
    1725             :     {
    1726           0 :         const SpellErrorDescription& rDesc = pAttrib->GetErrorDescription();
    1727           0 :         if( !rDesc.sErrorText.equals( GetErrorText() ) )
    1728           0 :             ChangeMarkedWord(rDesc.sErrorText, LanguageTag::convertToLanguageType( rDesc.aLocale ));
    1729             :     }
    1730           0 : }
    1731             : 
    1732             : 
    1733           0 : void SentenceEditWindow_Impl::SetAlternatives( Reference< XSpellAlternatives> xAlt )
    1734             : {
    1735           0 :     TextPaM aCursor(0, m_nErrorStart);
    1736             :     DBG_ASSERT(static_cast<const SpellErrorAttrib*>(
    1737             :             GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR)), "no error set?");
    1738             : 
    1739           0 :     OUString aWord;
    1740           0 :     lang::Locale    aLocale;
    1741           0 :     uno::Sequence< OUString >    aAlts;
    1742           0 :     OUString sServiceName;
    1743           0 :     if (xAlt.is())
    1744             :     {
    1745           0 :         aWord   = xAlt->getWord();
    1746           0 :         aLocale = xAlt->getLocale();
    1747           0 :         aAlts   = xAlt->getAlternatives();
    1748           0 :         uno::Reference< container::XNamed > xNamed( xAlt, uno::UNO_QUERY );
    1749           0 :         if (xNamed.is())
    1750           0 :             sServiceName = xNamed->getName();
    1751             :     }
    1752           0 :     SpellErrorDescription aDesc( false, aWord, aLocale, aAlts, 0, sServiceName);
    1753           0 :     GetTextEngine()->SetAttrib( SpellErrorAttrib(aDesc), 0, m_nErrorStart, m_nErrorEnd );
    1754           0 : }
    1755             : 
    1756             : 
    1757           0 : void SentenceEditWindow_Impl::SetAttrib( const TextAttrib& rAttr, sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd )
    1758             : {
    1759           0 :     GetTextEngine()->SetAttrib(rAttr, nPara, nStart, nEnd);
    1760           0 : }
    1761             : 
    1762             : 
    1763           0 : void SentenceEditWindow_Impl::SetText( const OUString& rStr )
    1764             : {
    1765           0 :     m_nErrorStart = m_nErrorEnd = 0;
    1766           0 :     GetTextEngine()->SetText(rStr);
    1767           0 : }
    1768             : 
    1769             : 
    1770             : struct LanguagePosition_Impl
    1771             : {
    1772             :     sal_uInt16          nPosition;
    1773             :     LanguageType    eLanguage;
    1774             : 
    1775           0 :     LanguagePosition_Impl(sal_uInt16 nPos, LanguageType eLang) :
    1776             :         nPosition(nPos),
    1777           0 :         eLanguage(eLang)
    1778           0 :         {}
    1779             : };
    1780             : typedef std::vector<LanguagePosition_Impl> LanguagePositions_Impl;
    1781             : 
    1782           0 : static void lcl_InsertBreakPosition_Impl(
    1783             :         LanguagePositions_Impl& rBreakPositions, sal_uInt16 nInsert, LanguageType eLanguage)
    1784             : {
    1785           0 :     LanguagePositions_Impl::iterator aStart = rBreakPositions.begin();
    1786           0 :     while(aStart != rBreakPositions.end())
    1787             :     {
    1788           0 :         if(aStart->nPosition == nInsert)
    1789             :         {
    1790             :             //the language of following starts has to overwrite
    1791             :             //the one of previous ends
    1792           0 :             aStart->eLanguage = eLanguage;
    1793           0 :             return;
    1794             :         }
    1795           0 :         else if(aStart->nPosition > nInsert)
    1796             :         {
    1797             : 
    1798           0 :             rBreakPositions.insert(aStart, LanguagePosition_Impl(nInsert, eLanguage));
    1799           0 :             return;
    1800             :         }
    1801             :         else
    1802           0 :             ++aStart;
    1803             :     }
    1804           0 :     rBreakPositions.push_back(LanguagePosition_Impl(nInsert, eLanguage));
    1805             : }
    1806             : /*-------------------------------------------------------------------------
    1807             :     Returns the text in spell portions. Each portion contains text with an
    1808             :     equal language and attribute. The spell alternatives are empty.
    1809             :   -----------------------------------------------------------------------*/
    1810           0 : svx::SpellPortions SentenceEditWindow_Impl::CreateSpellPortions( bool bSetIgnoreFlag ) const
    1811             : {
    1812           0 :     svx::SpellPortions aRet;
    1813           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1814           0 :     const sal_uInt16 nTextLen = pTextEngine->GetTextLen(0);
    1815           0 :     if(nTextLen)
    1816             :     {
    1817           0 :         TextPaM aCursor(0, 0);
    1818           0 :         LanguagePositions_Impl aBreakPositions;
    1819           0 :         const TextCharAttrib* pLastLang = 0;
    1820           0 :         const TextCharAttrib* pLastError = 0;
    1821           0 :         LanguageType eLang = LANGUAGE_DONTKNOW;
    1822           0 :         const TextCharAttrib* pError = 0;
    1823           0 :         while(aCursor.GetIndex() < nTextLen)
    1824             :         {
    1825           0 :             const TextCharAttrib* pLang = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_LANGUAGE);
    1826           0 :             if(pLang && pLang != pLastLang)
    1827             :             {
    1828           0 :                 eLang = static_cast<const SpellLanguageAttrib&>(pLang->GetAttr()).GetLanguage();
    1829           0 :                 lcl_InsertBreakPosition_Impl(aBreakPositions, pLang->GetStart(), eLang);
    1830           0 :                 lcl_InsertBreakPosition_Impl(aBreakPositions, pLang->GetEnd(), eLang);
    1831           0 :                 pLastLang = pLang;
    1832             :             }
    1833           0 :             pError = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR);
    1834           0 :             if(pError && pLastError != pError)
    1835             :             {
    1836           0 :                 lcl_InsertBreakPosition_Impl(aBreakPositions, pError->GetStart(), eLang);
    1837           0 :                 lcl_InsertBreakPosition_Impl(aBreakPositions, pError->GetEnd(), eLang);
    1838           0 :                 pLastError = pError;
    1839             : 
    1840             :             }
    1841           0 :             aCursor.GetIndex()++;
    1842             :         }
    1843             : 
    1844           0 :         if(nTextLen && aBreakPositions.empty())
    1845             :         {
    1846             :             //if all content has been overwritten the attributes may have been removed, too
    1847           0 :             svx::SpellPortion aPortion1;
    1848           0 :             aPortion1.eLanguage = GetSpellDialog()->GetSelectedLang_Impl();
    1849           0 :             aPortion1.sText = pTextEngine->GetText(
    1850           0 :                         TextSelection(TextPaM(0, 0), TextPaM(0, nTextLen)));
    1851             : 
    1852           0 :             aRet.push_back(aPortion1);
    1853             : 
    1854             :         }
    1855           0 :         else if(!aBreakPositions.empty())
    1856             :         {
    1857           0 :             LanguagePositions_Impl::iterator aStart = aBreakPositions.begin();
    1858             :             //start should always be Null
    1859           0 :             eLang = aStart->eLanguage;
    1860           0 :             sal_uInt16 nStart = aStart->nPosition;
    1861             :             DBG_ASSERT(!nStart, "invalid start position - language attribute missing?");
    1862           0 :             ++aStart;
    1863             : 
    1864           0 :             while(aStart != aBreakPositions.end())
    1865             :             {
    1866           0 :                 svx::SpellPortion aPortion1;
    1867           0 :                 aPortion1.eLanguage = eLang;
    1868           0 :                 aPortion1.sText = pTextEngine->GetText(
    1869           0 :                             TextSelection(TextPaM(0, nStart), TextPaM(0, aStart->nPosition)));
    1870           0 :                 bool bIsIgnoreError = m_aIgnoreErrorsAt.find( nStart ) != m_aIgnoreErrorsAt.end();
    1871           0 :                 if( bSetIgnoreFlag && bIsIgnoreError )
    1872             :                 {
    1873           0 :                     aPortion1.bIgnoreThisError = true;
    1874             :                 }
    1875           0 :                 aRet.push_back(aPortion1);
    1876           0 :                 nStart = aStart->nPosition;
    1877           0 :                 eLang = aStart->eLanguage;
    1878           0 :                 ++aStart;
    1879           0 :             }
    1880             :         }
    1881             : 
    1882             :         // quick partly fix of #i71318. Correct fix needs to patch the TextEngine itself...
    1883             :         // this one will only prevent text from disappearing. It may to not have the
    1884             :         // correct language and will probably not spell checked...
    1885           0 :         sal_uLong nPara = pTextEngine->GetParagraphCount();
    1886           0 :         if (nPara > 1)
    1887             :         {
    1888           0 :             OUString aLeftOverText;
    1889           0 :             for (sal_uLong i = 1;  i < nPara;  ++i)
    1890             :             {
    1891           0 :                 aLeftOverText += "\x0a";    // the manual line break...
    1892           0 :                 aLeftOverText += pTextEngine->GetText(i);
    1893             :             }
    1894           0 :             if (pError)
    1895             :             {   // we need to add a new portion containing the left-over text
    1896           0 :                 svx::SpellPortion aPortion2;
    1897           0 :                 aPortion2.eLanguage = eLang;
    1898           0 :                 aPortion2.sText = aLeftOverText;
    1899           0 :                 aRet.push_back( aPortion2 );
    1900             :             }
    1901             :             else
    1902             :             {   // we just need to append the left-over text to the last portion (which had no errors)
    1903           0 :                 aRet[ aRet.size() - 1 ].sText += aLeftOverText;
    1904           0 :             }
    1905           0 :         }
    1906             :    }
    1907           0 :     return aRet;
    1908             : }
    1909             : 
    1910             : 
    1911           0 : void SentenceEditWindow_Impl::Undo()
    1912             : {
    1913           0 :     ::svl::IUndoManager& rUndoMgr = GetTextEngine()->GetUndoManager();
    1914             :     DBG_ASSERT(GetUndoActionCount(), "no undo actions available" );
    1915           0 :     if(!GetUndoActionCount())
    1916           0 :         return;
    1917           0 :     bool bSaveUndoEdit = IsUndoEditMode();
    1918             :     sal_uInt16 nId;
    1919             :     //if the undo edit mode is active then undo all changes until the UNDO_EDIT_MODE action has been found
    1920           0 :     do
    1921             :     {
    1922           0 :         nId = rUndoMgr.GetUndoActionId();
    1923           0 :         rUndoMgr.Undo();
    1924           0 :     }while(bSaveUndoEdit && SPELLUNDO_UNDO_EDIT_MODE != nId && GetUndoActionCount());
    1925             : 
    1926           0 :     if(bSaveUndoEdit || SPELLUNDO_CHANGE_GROUP == nId)
    1927           0 :         GetSpellDialog()->UpdateBoxes_Impl();
    1928             : }
    1929             : 
    1930             : 
    1931           0 : void SentenceEditWindow_Impl::ResetUndo()
    1932             : {
    1933           0 :     GetTextEngine()->ResetUndo();
    1934           0 : }
    1935             : 
    1936             : 
    1937           0 : void SentenceEditWindow_Impl::AddUndoAction( SfxUndoAction *pAction, bool bTryMerg )
    1938             : {
    1939           0 :     ::svl::IUndoManager& rUndoMgr = GetTextEngine()->GetUndoManager();
    1940           0 :     rUndoMgr.AddUndoAction(pAction, bTryMerg);
    1941           0 :     GetSpellDialog()->m_pUndoPB->Enable();
    1942           0 : }
    1943             : 
    1944             : 
    1945           0 : sal_uInt16 SentenceEditWindow_Impl::GetUndoActionCount()
    1946             : {
    1947           0 :     return GetTextEngine()->GetUndoManager().GetUndoActionCount();
    1948             : }
    1949             : 
    1950             : 
    1951           0 : void SentenceEditWindow_Impl::UndoActionStart( sal_uInt16 nId )
    1952             : {
    1953           0 :     GetTextEngine()->UndoActionStart(nId);
    1954           0 : }
    1955             : 
    1956             : 
    1957           0 : void SentenceEditWindow_Impl::UndoActionEnd()
    1958             : {
    1959           0 :     GetTextEngine()->UndoActionEnd();
    1960           0 : }
    1961             : 
    1962             : 
    1963           0 : void SentenceEditWindow_Impl::MoveErrorEnd(long nOffset)
    1964             : {
    1965           0 :     if(nOffset > 0)
    1966           0 :         m_nErrorEnd = m_nErrorEnd - (sal_uInt16)nOffset;
    1967             :     else
    1968           0 :         m_nErrorEnd = m_nErrorEnd -(sal_uInt16)- nOffset;
    1969           0 : }
    1970             : 
    1971             : 
    1972           0 : void  SentenceEditWindow_Impl::SetUndoEditMode(bool bSet)
    1973             : {
    1974             :     DBG_ASSERT(!bSet || m_bIsUndoEditMode != bSet, "SetUndoEditMode with equal values?");
    1975           0 :     m_bIsUndoEditMode = bSet;
    1976             :     //disable all buttons except the Change
    1977           0 :     SpellDialog* pSpellDialog = GetSpellDialog();
    1978             :     Control* aControls[] =
    1979             :     {
    1980             :         pSpellDialog->m_pChangeAllPB,
    1981             :         pSpellDialog->m_pExplainFT,
    1982             :         pSpellDialog->m_pIgnoreAllPB,
    1983             :         pSpellDialog->m_pIgnoreRulePB,
    1984             :         pSpellDialog->m_pIgnorePB,
    1985             :         pSpellDialog->m_pSuggestionLB,
    1986             :         pSpellDialog->m_pSuggestionFT,
    1987             :         pSpellDialog->m_pLanguageFT,
    1988             :         pSpellDialog->m_pLanguageLB,
    1989             :         pSpellDialog->m_pAddToDictMB,
    1990             :         pSpellDialog->m_pAddToDictPB,
    1991             :         pSpellDialog->m_pAutoCorrPB,
    1992             :         0
    1993           0 :     };
    1994           0 :     sal_Int32 nIdx = 0;
    1995           0 :     do
    1996             :     {
    1997           0 :         aControls[nIdx]->Enable(false);
    1998             :     }
    1999           0 :     while(aControls[++nIdx]);
    2000             : 
    2001             :     //remove error marks
    2002           0 :     TextEngine* pTextEngine = GetTextEngine();
    2003           0 :     pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTCOLOR, true );
    2004           0 :     pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTWEIGHT, true );
    2005             : 
    2006             :     //put the appropriate action on the Undo-stack
    2007             :     SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
    2008           0 :                         SPELLUNDO_UNDO_EDIT_MODE, GetSpellDialog()->aDialogUndoLink);
    2009           0 :     AddUndoAction(pAction);
    2010           0 :     pSpellDialog->m_pChangePB->Enable();
    2011           0 : }
    2012             : 
    2013           0 : IMPL_LINK( SpellDialog, HandleHyperlink, FixedHyperlink*, pHyperlink )
    2014             : {
    2015           0 :     OUString sURL=pHyperlink->GetURL();
    2016           0 :     OUString sTitle=GetText();
    2017             : 
    2018           0 :     if ( sURL.isEmpty() ) // Nothing to do, when the URL is empty
    2019           0 :         return 1;
    2020             :     try
    2021             :     {
    2022             :         uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
    2023           0 :             com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext()) );
    2024           0 :         xSystemShellExecute->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
    2025             :     }
    2026           0 :     catch ( uno::Exception& )
    2027             :     {
    2028           0 :         uno::Any exc( ::cppu::getCaughtException() );
    2029           0 :         OUString msg( ::comphelper::anyToString( exc ) );
    2030           0 :         const SolarMutexGuard guard;
    2031           0 :         MessageDialog aErrorBox(NULL, msg);
    2032           0 :         aErrorBox.SetText(sTitle);
    2033           0 :         aErrorBox.Execute();
    2034             :     }
    2035             : 
    2036           0 :     return 1;
    2037           0 : }
    2038             : 
    2039             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10