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

Generated by: LCOV version 1.10