2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-04 11:25:41 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
#include <tools/shl.hxx>
|
|
|
|
#include <vcl/wrkwin.hxx>
|
|
|
|
#include <vcl/menu.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#include <vcl/scrbar.hxx>
|
|
|
|
#include <SpellAttrib.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#include <sfx2/bindings.hxx>
|
|
|
|
#include <svl/undo.hxx>
|
|
|
|
#include <unotools/lingucfg.hxx>
|
2012-08-06 20:52:37 +02:00
|
|
|
#include <vcl/textdata.hxx>
|
2013-01-02 22:07:41 +01:00
|
|
|
#include <vcl/graphicfilter.hxx>
|
2010-01-08 18:32:51 +01:00
|
|
|
#include <editeng/unolingu.hxx>
|
|
|
|
#include <editeng/splwrap.hxx>
|
2009-10-31 00:36:06 +01:00
|
|
|
#include <linguistic/lngprops.hxx>
|
|
|
|
#include <linguistic/misc.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
|
|
#include <com/sun/star/lang/XServiceDisplayName.hpp>
|
|
|
|
#include <com/sun/star/linguistic2/SpellFailure.hpp>
|
|
|
|
#include <com/sun/star/frame/XStorable.hpp>
|
2011-10-23 07:35:06 -07:00
|
|
|
#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
|
2012-08-29 07:45:05 +02:00
|
|
|
#include <com/sun/star/system/SystemShellExecute.hpp>
|
2009-10-31 00:36:06 +01:00
|
|
|
#include <sfx2/app.hxx>
|
|
|
|
#include <vcl/help.hxx>
|
|
|
|
#include <vcl/graph.hxx>
|
|
|
|
#include <osl/file.hxx>
|
2009-11-02 20:49:14 +01:00
|
|
|
#include <cuires.hrc>
|
2010-01-13 22:25:07 +01:00
|
|
|
#include <editeng/optitems.hxx>
|
2010-01-08 18:32:51 +01:00
|
|
|
#include <editeng/svxenum.hxx>
|
2009-10-31 00:36:06 +01:00
|
|
|
#include <svx/SpellDialogChildWindow.hxx>
|
|
|
|
#include "SpellDialog.hxx"
|
|
|
|
#include <svx/dlgutil.hxx>
|
|
|
|
#include "optlingu.hxx"
|
2009-11-02 20:49:14 +01:00
|
|
|
#include <dialmgr.hxx>
|
2009-10-31 00:36:06 +01:00
|
|
|
#include <svx/svxerr.hxx>
|
|
|
|
#include "treeopt.hxx"
|
2009-12-10 18:36:58 +01:00
|
|
|
#include <svtools/langtab.hxx>
|
2011-10-23 07:35:06 -07:00
|
|
|
#include <comphelper/anytostring.hxx>
|
|
|
|
#include <cppuhelper/exc_hlp.hxx>
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::linguistic2;
|
|
|
|
|
2010-09-01 13:19:13 +02:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
// struct SpellDialog_Impl ---------------------------------------------
|
|
|
|
|
|
|
|
struct SpellDialog_Impl
|
|
|
|
{
|
|
|
|
Sequence< Reference< XDictionary > > aDics;
|
|
|
|
};
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2010-11-26 14:04:34 +01:00
|
|
|
#define SPELLUNDO_START 200
|
|
|
|
|
|
|
|
#define SPELLUNDO_CHANGE_LANGUAGE (SPELLUNDO_START + 1)
|
|
|
|
#define SPELLUNDO_CHANGE_TEXTENGINE (SPELLUNDO_START + 2)
|
|
|
|
#define SPELLUNDO_CHANGE_NEXTERROR (SPELLUNDO_START + 3)
|
|
|
|
#define SPELLUNDO_CHANGE_ADD_TO_DICTIONARY (SPELLUNDO_START + 4)
|
|
|
|
#define SPELLUNDO_CHANGE_GROUP (SPELLUNDO_START + 5) //undo list
|
|
|
|
#define SPELLUNDO_MOVE_ERROREND (SPELLUNDO_START + 6)
|
|
|
|
#define SPELLUNDO_UNDO_EDIT_MODE (SPELLUNDO_START + 7)
|
|
|
|
#define SPELLUNDO_ADD_IGNORE_RULE (SPELLUNDO_START + 8)
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
namespace svx{
|
|
|
|
class SpellUndoAction_Impl : public SfxUndoAction
|
|
|
|
{
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 m_nId;
|
2009-10-31 00:36:06 +01:00
|
|
|
const Link& m_rActionLink;
|
|
|
|
//undo of button enabling
|
|
|
|
bool m_bEnableChangePB;
|
|
|
|
bool m_bEnableChangeAllPB;
|
|
|
|
//undo of MarkNextError - used in change and change all, ignore and ignore all
|
|
|
|
long m_nNewErrorStart;
|
|
|
|
long m_nNewErrorEnd;
|
|
|
|
long m_nOldErrorStart;
|
|
|
|
long m_nOldErrorEnd;
|
|
|
|
bool m_bIsErrorLanguageSelected;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString m_sRuleId;
|
2009-10-31 00:36:06 +01:00
|
|
|
//undo of AddToDictionary
|
|
|
|
Reference<XDictionary> m_xDictionary;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString m_sAddedWord;
|
2009-10-31 00:36:06 +01:00
|
|
|
//move end of error - ::ChangeMarkedWord()
|
|
|
|
long m_nOffset;
|
|
|
|
|
|
|
|
public:
|
2011-01-14 12:41:27 +01:00
|
|
|
SpellUndoAction_Impl(sal_uInt16 nId, const Link& rActionLink) :
|
2009-10-31 00:36:06 +01:00
|
|
|
m_nId(nId),
|
|
|
|
m_rActionLink( rActionLink),
|
|
|
|
m_bEnableChangePB(false),
|
|
|
|
m_bEnableChangeAllPB(false),
|
|
|
|
m_nNewErrorStart(-1),
|
|
|
|
m_nNewErrorEnd(-1),
|
|
|
|
m_nOldErrorStart(-1),
|
|
|
|
m_nOldErrorEnd(-1),
|
|
|
|
m_bIsErrorLanguageSelected(false),
|
|
|
|
m_nOffset(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~SpellUndoAction_Impl();
|
|
|
|
|
|
|
|
virtual void Undo();
|
2011-01-14 12:41:27 +01:00
|
|
|
virtual sal_uInt16 GetId() const;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
void SetEnableChangePB(){m_bEnableChangePB = true;}
|
|
|
|
bool IsEnableChangePB(){return m_bEnableChangePB;}
|
|
|
|
|
|
|
|
void SetEnableChangeAllPB(){m_bEnableChangeAllPB = true;}
|
|
|
|
bool IsEnableChangeAllPB(){return m_bEnableChangeAllPB;}
|
|
|
|
|
|
|
|
void SetErrorMove(long nNewStart, long nNewEnd, long nOldStart, long nOldEnd)
|
|
|
|
{
|
|
|
|
m_nNewErrorStart = nNewStart;
|
|
|
|
m_nNewErrorEnd = nNewEnd;
|
|
|
|
m_nOldErrorStart = nOldStart;
|
|
|
|
m_nOldErrorEnd = nOldEnd;
|
|
|
|
}
|
|
|
|
long GetNewErrorStart() { return m_nNewErrorStart;}
|
|
|
|
long GetNewErrorEnd() { return m_nNewErrorEnd;}
|
|
|
|
long GetOldErrorStart() { return m_nOldErrorStart;}
|
|
|
|
long GetOldErrorEnd() { return m_nOldErrorEnd;}
|
|
|
|
|
|
|
|
void SetErrorLanguageSelected(bool bSet){ m_bIsErrorLanguageSelected = bSet;}
|
|
|
|
bool IsErrorLanguageSelected() const {return m_bIsErrorLanguageSelected;}
|
|
|
|
|
|
|
|
void SetDictionary(Reference<XDictionary> xDict) { m_xDictionary = xDict; }
|
|
|
|
Reference<XDictionary> GetDictionary() const {return m_xDictionary;}
|
2013-04-07 12:06:47 +02:00
|
|
|
void SetAddedWord(const OUString& rWord) {m_sAddedWord = rWord;}
|
|
|
|
const OUString& GetAddedWord() const { return m_sAddedWord;}
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
void SetOffset(long nSet) {m_nOffset = nSet;}
|
|
|
|
long GetOffset() const {return m_nOffset;}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SetErrorType( const OUString& rId ) { m_sRuleId = rId; }
|
|
|
|
const OUString& GetErrorType() const { return m_sRuleId; }
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
}//namespace svx
|
|
|
|
using namespace ::svx;
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
SpellUndoAction_Impl::~SpellUndoAction_Impl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SpellUndoAction_Impl::Undo()
|
|
|
|
{
|
|
|
|
m_rActionLink.Call(this);
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 SpellUndoAction_Impl::GetId()const
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
return m_nId;
|
|
|
|
}
|
|
|
|
|
|
|
|
// class SvxSpellCheckDialog ---------------------------------------------
|
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
SpellDialog::SpellDialog(SpellDialogChildWindow* pChildWindow,
|
|
|
|
Window * pParent, SfxBindings* _pBindings)
|
|
|
|
: SfxModelessDialog (_pBindings, pChildWindow,
|
|
|
|
pParent, "SpellingDialog", "cui/ui/spellingdialog.ui")
|
|
|
|
, aDialogUndoLink(LINK (this, SpellDialog, DialogUndoHdl))
|
|
|
|
, bModified(false)
|
|
|
|
, bFocusLocked(true)
|
|
|
|
, rParent(*pChildWindow)
|
|
|
|
{
|
|
|
|
m_sTitleSpellingGrammar = GetText();
|
2013-09-02 11:00:05 +01:00
|
|
|
m_sTitleSpelling = get<FixedText>("alttitleft")->GetText();
|
|
|
|
|
|
|
|
// fdo#68794 set initial title for cases where no text has been processed
|
|
|
|
// yet to show its language attributes
|
|
|
|
OUString sTitle = rParent.HasGrammarChecking() ? m_sTitleSpellingGrammar : m_sTitleSpelling;
|
|
|
|
SetText(sTitle.replaceFirst("$LANGUAGE ($LOCATION)", ""));
|
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_sResumeST = get<FixedText>("resumeft")->GetText();
|
|
|
|
m_sNoSuggestionsST = get<FixedText>("nosuggestionsft")->GetText();
|
|
|
|
|
|
|
|
get(m_pLanguageFT, "languageft");
|
|
|
|
get(m_pLanguageLB, "languagelb");
|
|
|
|
get(m_pExplainFT, "explain");
|
|
|
|
get(m_pExplainLink, "explainlink");
|
|
|
|
get(m_pNotInDictFT, "notindictft");
|
|
|
|
get(m_pSentenceED, "sentence");
|
|
|
|
Size aEdSize(LogicToPixel(Size(197, 48), MAP_APPFONT));
|
|
|
|
m_pSentenceED->set_width_request(aEdSize.Width());
|
|
|
|
m_pSentenceED->set_height_request(aEdSize.Height());
|
|
|
|
get(m_pSuggestionFT, "suggestionsft");
|
|
|
|
get(m_pSuggestionLB, "suggestionslb");
|
|
|
|
m_pSuggestionLB->SetDropDownLineCount(5);
|
|
|
|
m_pSuggestionLB->set_width_request(aEdSize.Width());
|
|
|
|
get(m_pIgnorePB, "ignore");
|
|
|
|
m_sIgnoreOnceST = m_pIgnorePB->GetText();
|
|
|
|
get(m_pIgnoreAllPB, "ignoreall");
|
|
|
|
get(m_pIgnoreRulePB, "ignorerule");
|
|
|
|
get(m_pAddToDictPB, "add");
|
|
|
|
get(m_pAddToDictMB, "addmb");
|
|
|
|
m_pAddToDictMB->SetHelpId(m_pAddToDictPB->GetHelpId());
|
|
|
|
get(m_pChangePB, "change");
|
|
|
|
get(m_pChangeAllPB, "changeall");
|
|
|
|
get(m_pAutoCorrPB, "autocorrect");
|
|
|
|
get(m_pCheckGrammarCB, "checkgrammar");
|
|
|
|
get(m_pOptionsPB, "options");
|
|
|
|
get(m_pUndoPB, "undo");
|
|
|
|
get(m_pClosePB, "close");
|
2009-10-31 00:36:06 +01:00
|
|
|
xSpell = LinguMgr::GetSpellChecker();
|
|
|
|
pImpl = new SpellDialog_Impl;
|
|
|
|
|
2011-10-23 07:35:06 -07:00
|
|
|
const StyleSettings& rSettings = GetSettings().GetStyleSettings();
|
|
|
|
Color aCol = rSettings.GetHelpColor();
|
|
|
|
Wallpaper aWall( aCol );
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pExplainLink->SetBackground( aWall );
|
|
|
|
m_pExplainFT->SetBackground( aWall );
|
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
Init_Impl();
|
|
|
|
|
|
|
|
// disable controls if service is missing
|
2012-12-22 13:51:32 +00:00
|
|
|
Enable(xSpell.is());
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
//InitHdl wants to use virtual methods, so it
|
|
|
|
//can't be called during the ctor, so init
|
|
|
|
//it on next event cycle post-ctor
|
2009-10-31 00:36:06 +01:00
|
|
|
Application::PostUserEvent( STATIC_LINK(
|
|
|
|
this, SpellDialog, InitHdl ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
SpellDialog::~SpellDialog()
|
|
|
|
{
|
|
|
|
// save possibly modified user-dictionaries
|
2013-02-04 16:18:01 +02:00
|
|
|
Reference< XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
|
2009-10-31 00:36:06 +01:00
|
|
|
if (xDicList.is())
|
|
|
|
{
|
|
|
|
linguistic::SaveDictionaries( xDicList );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pImpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpellDialog::Init_Impl()
|
|
|
|
{
|
2012-04-15 17:50:21 +02:00
|
|
|
// initialize handler
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pClosePB->SetClickHdl(LINK( this, SpellDialog, CancelHdl ) );
|
|
|
|
m_pChangePB->SetClickHdl(LINK( this, SpellDialog, ChangeHdl ) );
|
|
|
|
m_pChangeAllPB->SetClickHdl(LINK( this, SpellDialog, ChangeAllHdl ) );
|
|
|
|
m_pIgnorePB->SetClickHdl(LINK( this, SpellDialog, IgnoreHdl ) );
|
|
|
|
m_pIgnoreAllPB->SetClickHdl(LINK( this, SpellDialog, IgnoreAllHdl ) );
|
|
|
|
m_pIgnoreRulePB->SetClickHdl(LINK( this, SpellDialog, IgnoreAllHdl ) );
|
|
|
|
m_pUndoPB->SetClickHdl(LINK( this, SpellDialog, UndoHdl ) );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pAutoCorrPB->SetClickHdl( LINK( this, SpellDialog, ExtClickHdl ) );
|
|
|
|
m_pCheckGrammarCB->SetClickHdl( LINK( this, SpellDialog, CheckGrammarHdl ));
|
|
|
|
m_pOptionsPB->SetClickHdl( LINK( this, SpellDialog, ExtClickHdl ) );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->SetDoubleClickHdl( LINK( this, SpellDialog, ChangeHdl ) );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->SetModifyHdl(LINK ( this, SpellDialog, ModifyHdl) );
|
2012-04-14 13:17:04 +02:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pAddToDictMB->SetSelectHdl(LINK ( this, SpellDialog, AddToDictSelectHdl ) );
|
|
|
|
m_pAddToDictPB->SetClickHdl(LINK ( this, SpellDialog, AddToDictClickHdl ) );
|
2012-05-17 14:14:58 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pLanguageLB->SetSelectHdl(LINK( this, SpellDialog, LanguageSelectHdl ) );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pExplainLink->SetClickHdl( LINK( this, SpellDialog, HandleHyperlink ) );
|
2011-10-23 07:35:06 -07:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
// initialize language ListBox
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pLanguageLB->SetLanguageList( LANG_LIST_SPELL_USED, sal_False, sal_False, sal_True );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ClearModifyFlag();
|
2009-10-31 00:36:06 +01:00
|
|
|
SvxGetChangeAllList()->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpellDialog::UpdateBoxes_Impl()
|
|
|
|
{
|
|
|
|
sal_Int32 i;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->Clear();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
LanguageType nAltLanguage = LANGUAGE_NONE;
|
2013-04-07 12:06:47 +02:00
|
|
|
Sequence< OUString > aNewWords;
|
2009-10-31 00:36:06 +01:00
|
|
|
bool bIsGrammarError = false;
|
|
|
|
if( pSpellErrorDescription )
|
|
|
|
{
|
2013-07-13 02:54:05 +02:00
|
|
|
nAltLanguage = LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale );
|
2009-10-31 00:36:06 +01:00
|
|
|
aNewWords = pSpellErrorDescription->aSuggestions;
|
|
|
|
bIsGrammarError = pSpellErrorDescription->bIsGrammarError;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pExplainLink->SetURL( pSpellErrorDescription->sExplanationURL );
|
|
|
|
m_pExplainFT->SetText( pSpellErrorDescription->sExplanation );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
2011-12-16 17:29:07 -02:00
|
|
|
if( pSpellErrorDescription && !pSpellErrorDescription->sDialogTitle.isEmpty() )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
// use this function to apply the correct image to be used...
|
|
|
|
SetTitle_Impl( nAltLanguage );
|
|
|
|
// then change the title to the one to be actually used
|
|
|
|
SetText( pSpellErrorDescription->sDialogTitle );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetTitle_Impl( nAltLanguage );
|
|
|
|
SetSelectedLang_Impl( nAltLanguage );
|
2012-05-17 14:14:58 +01:00
|
|
|
int nDicts = InitUserDicts();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-04-15 17:50:21 +02:00
|
|
|
// enter alternatives
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString *pNewWords = aNewWords.getConstArray();
|
2009-10-31 00:36:06 +01:00
|
|
|
const sal_Int32 nSize = aNewWords.getLength();
|
|
|
|
for ( i = 0; i < nSize; ++i )
|
|
|
|
{
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString aTmp( pNewWords[i] );
|
2012-12-22 13:51:32 +00:00
|
|
|
if ( LISTBOX_ENTRY_NOTFOUND == m_pSuggestionLB->GetEntryPos( aTmp ) )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->InsertEntry( aTmp );
|
|
|
|
m_pSuggestionLB->SetEntryFlags(m_pSuggestionLB->GetEntryCount() - 1, LISTBOX_ENTRY_FLAG_MULTILINE);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!nSize)
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->InsertEntry(m_sNoSuggestionsST);
|
|
|
|
m_pAutoCorrPB->Enable( nSize > 0 );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionFT->Enable(nSize > 0);
|
|
|
|
m_pSuggestionLB->Enable(nSize > 0);
|
2009-10-31 00:36:06 +01:00
|
|
|
if( nSize )
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->SelectEntryPos(0);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pChangePB->Enable( nSize > 0);
|
|
|
|
m_pChangeAllPB->Enable(nSize > 0);
|
2009-10-31 00:36:06 +01:00
|
|
|
bool bShowChangeAll = !bIsGrammarError;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pChangeAllPB->Show( bShowChangeAll );
|
|
|
|
m_pExplainFT->Show( !bShowChangeAll );
|
|
|
|
m_pLanguageLB->Enable( bShowChangeAll );
|
|
|
|
m_pIgnoreAllPB->Show( bShowChangeAll );
|
|
|
|
|
|
|
|
m_pAddToDictMB->Show( bShowChangeAll && nDicts > 1);
|
|
|
|
m_pAddToDictPB->Show( bShowChangeAll && nDicts <= 1);
|
|
|
|
m_pIgnoreRulePB->Show( !bShowChangeAll );
|
|
|
|
m_pIgnoreRulePB->Enable(pSpellErrorDescription && !pSpellErrorDescription->sRuleId.isEmpty());
|
|
|
|
m_pAutoCorrPB->Show( bShowChangeAll && rParent.HasAutoCorrection() );
|
|
|
|
|
|
|
|
bool bOldShowGrammar = m_pCheckGrammarCB->IsVisible();
|
|
|
|
bool bOldShowExplain = m_pExplainLink->IsVisible();
|
|
|
|
|
|
|
|
m_pCheckGrammarCB->Show(rParent.HasGrammarChecking());
|
|
|
|
m_pExplainLink->Show(!m_pExplainLink->GetURL().isEmpty());
|
2013-01-21 14:32:09 +01:00
|
|
|
if (m_pExplainFT->GetText().isEmpty())
|
2012-02-27 17:00:40 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pExplainFT->Hide();
|
|
|
|
m_pExplainLink->Hide();
|
2012-02-27 17:00:40 +01:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:01:00 +02:00
|
|
|
if (bOldShowExplain != (bool) m_pExplainLink->IsVisible() || bOldShowGrammar != (bool) m_pCheckGrammarCB->IsVisible())
|
2013-03-07 14:05:33 +00:00
|
|
|
setOptimalLayoutSize();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2010-04-22 13:08:19 +02:00
|
|
|
void SpellDialog::SpellContinue_Impl(bool bUseSavedSentence, bool bIgnoreCurrentError )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
//initially or after the last error of a sentence MarkNextError will fail
|
|
|
|
//then GetNextSentence() has to be called followed again by MarkNextError()
|
|
|
|
//MarkNextError is not initally called if the UndoEdit mode is active
|
|
|
|
bool bNextSentence = false;
|
2012-12-22 13:51:32 +00:00
|
|
|
if((!m_pSentenceED->IsUndoEditMode() && m_pSentenceED->MarkNextError( bIgnoreCurrentError )) ||
|
|
|
|
true == ( bNextSentence = GetNextSentence_Impl(bUseSavedSentence, m_pSentenceED->IsUndoEditMode()) && m_pSentenceED->MarkNextError( false )))
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
|
2009-10-31 00:36:06 +01:00
|
|
|
if( pSpellErrorDescription )
|
|
|
|
{
|
|
|
|
UpdateBoxes_Impl();
|
|
|
|
Control* aControls[] =
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pNotInDictFT,
|
|
|
|
m_pSentenceED,
|
|
|
|
m_pLanguageFT,
|
2009-10-31 00:36:06 +01:00
|
|
|
0
|
|
|
|
};
|
|
|
|
sal_Int32 nIdx = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
aControls[nIdx]->Enable(sal_True);
|
|
|
|
}
|
|
|
|
while(aControls[++nIdx]);
|
|
|
|
|
|
|
|
}
|
|
|
|
if( bNextSentence )
|
|
|
|
{
|
|
|
|
//remove undo if a new sentence is active
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ResetUndo();
|
|
|
|
m_pUndoPB->Enable(sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-08 00:31:55 +01:00
|
|
|
/* Initialize, asynchronous to prevent virtial calls
|
|
|
|
from a constructor
|
|
|
|
*/
|
2009-10-31 00:36:06 +01:00
|
|
|
IMPL_STATIC_LINK( SpellDialog, InitHdl, SpellDialog *, EMPTYARG )
|
|
|
|
{
|
|
|
|
pThis->SetUpdateMode( sal_False );
|
|
|
|
//show or hide AutoCorrect depending on the modules abilities
|
2012-12-22 13:51:32 +00:00
|
|
|
pThis->m_pAutoCorrPB->Show(pThis->rParent.HasAutoCorrection());
|
2009-10-31 00:36:06 +01:00
|
|
|
pThis->SpellContinue_Impl();
|
2012-12-22 13:51:32 +00:00
|
|
|
pThis->m_pSentenceED->ResetUndo();
|
|
|
|
pThis->m_pUndoPB->Enable(sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2011-08-25 22:13:52 +01:00
|
|
|
// get current language
|
|
|
|
pThis->UpdateBoxes_Impl();
|
|
|
|
|
|
|
|
// fill dictionary PopupMenu
|
|
|
|
pThis->InitUserDicts();
|
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
pThis->LockFocusChanges(true);
|
2012-12-22 13:51:32 +00:00
|
|
|
if( pThis->m_pChangePB->IsEnabled() )
|
|
|
|
pThis->m_pChangePB->GrabFocus();
|
|
|
|
else if( pThis->m_pIgnorePB->IsEnabled() )
|
|
|
|
pThis->m_pIgnorePB->GrabFocus();
|
|
|
|
else if( pThis->m_pClosePB->IsEnabled() )
|
|
|
|
pThis->m_pClosePB->GrabFocus();
|
2009-10-31 00:36:06 +01:00
|
|
|
pThis->LockFocusChanges(false);
|
|
|
|
//show grammar CheckBox depending on the modules abilities
|
2012-12-22 13:51:32 +00:00
|
|
|
pThis->m_pCheckGrammarCB->Check( pThis->rParent.IsGrammarChecking() );
|
2009-10-31 00:36:06 +01:00
|
|
|
pThis->SetUpdateMode( sal_True );
|
|
|
|
pThis->Show();
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPL_LINK( SpellDialog, ExtClickHdl, Button *, pBtn )
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
if (m_pOptionsPB == pBtn)
|
2009-10-31 00:36:06 +01:00
|
|
|
StartSpellOptDlg_Impl();
|
2012-12-22 13:51:32 +00:00
|
|
|
else if (m_pAutoCorrPB == pBtn)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
//get the currently selected wrong word
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString sCurrentErrorText = m_pSentenceED->GetErrorText();
|
2009-10-31 00:36:06 +01:00
|
|
|
//get the wrong word from the XSpellAlternative
|
2012-12-22 13:51:32 +00:00
|
|
|
const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
|
2009-10-31 00:36:06 +01:00
|
|
|
if( pSpellErrorDescription )
|
|
|
|
{
|
2013-09-06 15:32:23 +02:00
|
|
|
OUString sWrong(pSpellErrorDescription->sErrorText);
|
2009-10-31 00:36:06 +01:00
|
|
|
//if the word has not been edited in the MultiLineEdit then
|
|
|
|
//the current suggestion should be used
|
|
|
|
//if it's not the 'no suggestions' entry
|
|
|
|
if(sWrong == sCurrentErrorText &&
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->IsEnabled() && m_pSuggestionLB->GetSelectEntryCount() > 0 &&
|
|
|
|
!m_sNoSuggestionsST.equals(m_pSuggestionLB->GetSelectEntry()))
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
sCurrentErrorText = m_pSuggestionLB->GetSelectEntry();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
if(sWrong != sCurrentErrorText)
|
|
|
|
{
|
|
|
|
SvxPrepareAutoCorrect( sWrong, sCurrentErrorText );
|
|
|
|
LanguageType eLang = GetSelectedLang_Impl();
|
|
|
|
rParent.AddAutoCorrection( sWrong, sCurrentErrorText, eLang );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
IMPL_LINK( SpellDialog, CheckGrammarHdl, CheckBox*, pBox )
|
|
|
|
{
|
|
|
|
rParent.SetGrammarChecking( pBox->IsChecked() );
|
|
|
|
Impl_Restore();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpellDialog::StartSpellOptDlg_Impl()
|
|
|
|
{
|
|
|
|
sal_uInt16 aSpellInfos[] =
|
|
|
|
{
|
|
|
|
SID_ATTR_SPELL,SID_ATTR_SPELL,
|
|
|
|
SID_SPELL_MODIFIED, SID_SPELL_MODIFIED,
|
|
|
|
SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
SfxItemSet aSet( SFX_APP()->GetPool(), aSpellInfos);
|
|
|
|
aSet.Put(SfxSpellCheckItem( xSpell, SID_ATTR_SPELL ));
|
2013-01-24 13:18:00 +00:00
|
|
|
SfxNoLayoutSingleTabDialog* pDlg =
|
|
|
|
new SfxNoLayoutSingleTabDialog( this, aSet, RID_SFXPAGE_LINGU );
|
2009-10-31 00:36:06 +01:00
|
|
|
SfxTabPage* pPage = SvxLinguTabPage::Create( pDlg, aSet );
|
|
|
|
( (SvxLinguTabPage*)pPage )->HideGroups( GROUP_MODULES );
|
|
|
|
pDlg->SetTabPage( pPage );
|
|
|
|
if(RET_OK == pDlg->Execute())
|
|
|
|
{
|
|
|
|
InitUserDicts();
|
|
|
|
const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
|
|
|
|
if(pOutSet)
|
|
|
|
OfaTreeOptionsDialog::ApplyLanguageOptions(*pOutSet);
|
|
|
|
}
|
|
|
|
delete pDlg;
|
2012-05-29 22:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString getDotReplacementString(const OUString &rErrorText, const OUString &rSuggestedReplacement)
|
2012-05-29 22:27:11 +01:00
|
|
|
{
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString aString = rErrorText;
|
2012-05-29 22:27:11 +01:00
|
|
|
|
|
|
|
//dots are sometimes part of the spelled word but they are not necessarily part of the replacement
|
2013-09-26 08:30:52 +02:00
|
|
|
bool bDot = !aString.isEmpty() && aString[aString.getLength() - 1] == '.';
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2012-05-29 22:27:11 +01:00
|
|
|
aString = rSuggestedReplacement;
|
|
|
|
|
2013-09-26 08:30:52 +02:00
|
|
|
if(bDot && (aString.isEmpty() || aString[aString.getLength() - 1] != '.'))
|
|
|
|
aString += ".";
|
2012-05-29 22:27:11 +01:00
|
|
|
|
|
|
|
return aString;
|
|
|
|
}
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2012-05-29 22:27:11 +01:00
|
|
|
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString SpellDialog::getReplacementString() const
|
2011-10-17 15:18:44 +01:00
|
|
|
{
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString sOrigString = m_pSentenceED->GetErrorText();
|
2012-05-29 22:27:11 +01:00
|
|
|
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString sReplacement(sOrigString);
|
2012-05-29 22:27:11 +01:00
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
if(m_pSuggestionLB->IsEnabled() &&
|
|
|
|
m_pSuggestionLB->GetSelectEntryCount()>0 &&
|
|
|
|
!m_sNoSuggestionsST.equals(m_pSuggestionLB->GetSelectEntry()))
|
|
|
|
sReplacement = m_pSuggestionLB->GetSelectEntry();
|
2011-10-17 15:18:44 +01:00
|
|
|
|
2012-05-29 22:27:11 +01:00
|
|
|
return getDotReplacementString(sOrigString, sReplacement);
|
2011-10-17 15:18:44 +01:00
|
|
|
}
|
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SpellDialog, ChangeHdl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
if(m_pSentenceED->IsUndoEditMode())
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
SpellContinue_Impl();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString aString = getReplacementString();
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ChangeMarkedWord(aString, GetSelectedLang_Impl());
|
2009-10-31 00:36:06 +01:00
|
|
|
SpellContinue_Impl();
|
|
|
|
bModified = false;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
2012-12-22 13:51:32 +00:00
|
|
|
if(!m_pChangePB->IsEnabled())
|
|
|
|
m_pIgnorePB->GrabFocus();
|
2009-10-31 00:36:06 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SpellDialog, ChangeAllHdl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString aString = getReplacementString();
|
2009-10-31 00:36:06 +01:00
|
|
|
LanguageType eLang = GetSelectedLang_Impl();
|
|
|
|
|
|
|
|
// add new word to ChangeAll list
|
2013-09-06 15:32:23 +02:00
|
|
|
OUString aOldWord( m_pSentenceED->GetErrorText() );
|
2009-10-31 00:36:06 +01:00
|
|
|
SvxPrepareAutoCorrect( aOldWord, aString );
|
|
|
|
Reference<XDictionary> aXDictionary( SvxGetChangeAllList(), UNO_QUERY );
|
|
|
|
sal_uInt8 nAdded = linguistic::AddEntryToDic( aXDictionary,
|
|
|
|
aOldWord , sal_True,
|
|
|
|
aString, eLang );
|
|
|
|
|
|
|
|
if(nAdded == DIC_ERR_NONE)
|
|
|
|
{
|
|
|
|
SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
|
|
|
|
SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
|
|
|
|
pAction->SetDictionary(aXDictionary);
|
|
|
|
pAction->SetAddedWord(aOldWord);
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->AddUndoAction(pAction);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ChangeMarkedWord(aString, eLang);
|
2009-10-31 00:36:06 +01:00
|
|
|
SpellContinue_Impl();
|
|
|
|
bModified = false;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPL_LINK( SpellDialog, IgnoreAllHdl, Button *, pButton )
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
|
2009-10-31 00:36:06 +01:00
|
|
|
// add word to IgnoreAll list
|
|
|
|
Reference< XDictionary > aXDictionary( SvxGetIgnoreAllList(), UNO_QUERY );
|
|
|
|
//in case the error has been changed manually it has to be restored
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->RestoreCurrentError();
|
|
|
|
if (pButton == m_pIgnoreRulePB)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
const SpellErrorDescription* pSpellErrorDescription = m_pSentenceED->GetAlternatives();
|
2009-10-31 00:36:06 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if( pSpellErrorDescription && pSpellErrorDescription->xGrammarChecker.is() )
|
|
|
|
{
|
|
|
|
pSpellErrorDescription->xGrammarChecker->ignoreRule( pSpellErrorDescription->sRuleId,
|
|
|
|
pSpellErrorDescription->aLocale );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const uno::Exception& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString sErrorText(m_pSentenceED->GetErrorText());
|
2009-10-31 00:36:06 +01:00
|
|
|
sal_uInt8 nAdded = linguistic::AddEntryToDic( aXDictionary,
|
|
|
|
sErrorText, sal_False,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString(), LANGUAGE_NONE );
|
2009-10-31 00:36:06 +01:00
|
|
|
if(nAdded == DIC_ERR_NONE)
|
|
|
|
{
|
|
|
|
SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
|
|
|
|
SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
|
|
|
|
pAction->SetDictionary(aXDictionary);
|
|
|
|
pAction->SetAddedWord(sErrorText);
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->AddUndoAction(pAction);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SpellContinue_Impl();
|
|
|
|
bModified = false;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SpellDialog, UndoHdl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->Undo();
|
|
|
|
if(!m_pSentenceED->GetUndoActionCount())
|
|
|
|
m_pUndoPB->Enable(sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
IMPL_LINK( SpellDialog, DialogUndoHdl, SpellUndoAction_Impl*, pAction )
|
|
|
|
{
|
|
|
|
switch(pAction->GetId())
|
|
|
|
{
|
|
|
|
case SPELLUNDO_CHANGE_TEXTENGINE:
|
|
|
|
{
|
|
|
|
if(pAction->IsEnableChangePB())
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pChangePB->Enable(sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
if(pAction->IsEnableChangeAllPB())
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pChangeAllPB->Enable(sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPELLUNDO_CHANGE_NEXTERROR:
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->MoveErrorMarkTo((sal_uInt16)pAction->GetOldErrorStart(), (sal_uInt16)pAction->GetOldErrorEnd(), false);
|
2009-10-31 00:36:06 +01:00
|
|
|
if(pAction->IsErrorLanguageSelected())
|
|
|
|
{
|
|
|
|
UpdateBoxes_Impl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPELLUNDO_CHANGE_ADD_TO_DICTIONARY:
|
|
|
|
{
|
|
|
|
if(pAction->GetDictionary().is())
|
|
|
|
pAction->GetDictionary()->remove(pAction->GetAddedWord());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPELLUNDO_MOVE_ERROREND :
|
|
|
|
{
|
|
|
|
if(pAction->GetOffset() != 0)
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->MoveErrorEnd(pAction->GetOffset());
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPELLUNDO_UNDO_EDIT_MODE :
|
|
|
|
{
|
|
|
|
//refill the dialog with the currently spelled sentence - throw away all changes
|
|
|
|
SpellContinue_Impl(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPELLUNDO_ADD_IGNORE_RULE:
|
|
|
|
//undo of ignored rules is not supported
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
void SpellDialog::Impl_Restore()
|
|
|
|
{
|
|
|
|
//clear the "ChangeAllList"
|
|
|
|
SvxGetChangeAllList()->clear();
|
|
|
|
//get a new sentence
|
2013-01-21 14:32:09 +01:00
|
|
|
m_pSentenceED->SetText(OUString());
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ResetModified();
|
2011-08-22 11:33:42 +01:00
|
|
|
//Resolves: fdo#39348 refill the dialog with the currently spelled sentence
|
|
|
|
SpellContinue_Impl(true);
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pIgnorePB->SetText(m_sIgnoreOnceST);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SpellDialog, IgnoreHdl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
if (m_sResumeST.equals(m_pIgnorePB->GetText()))
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
Impl_Restore();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-22 13:08:19 +02:00
|
|
|
//in case the error has been changed manually it has to be restored,
|
|
|
|
// since the users choice now was to ignore the error
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->RestoreCurrentError();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
// the word is being ignored
|
2010-04-22 13:08:19 +02:00
|
|
|
SpellContinue_Impl( false, true );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SpellDialog::Close()
|
|
|
|
{
|
|
|
|
GetBindings().GetDispatcher()->
|
|
|
|
Execute(rParent.GetType(),
|
|
|
|
SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpellDialog::SetSelectedLang_Impl( LanguageType nLang )
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pLanguageLB->SelectLanguage( nLang );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
LanguageType SpellDialog::GetSelectedLang_Impl() const
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
sal_Int16 nLang = m_pLanguageLB->GetSelectLanguage();
|
2009-10-31 00:36:06 +01:00
|
|
|
return nLang;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
IMPL_LINK(SpellDialog, LanguageSelectHdl, SvxLanguageBox*, pBox)
|
|
|
|
{
|
2011-08-25 22:13:52 +01:00
|
|
|
//If selected language changes, then add->list should be regenerated to
|
|
|
|
//match
|
|
|
|
InitUserDicts();
|
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
//if currently an error is selected then search for alternatives for
|
|
|
|
//this word and fill the alternatives ListBox accordingly
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString sError = m_pSentenceED->GetErrorText();
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->Clear();
|
2013-09-26 08:30:52 +02:00
|
|
|
if(!sError.isEmpty())
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
LanguageType eLanguage = pBox->GetSelectLanguage();
|
|
|
|
Reference <XSpellAlternatives> xAlt = xSpell->spell( sError, eLanguage,
|
|
|
|
Sequence< PropertyValue >() );
|
|
|
|
if( xAlt.is() )
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->SetAlternatives( xAlt );
|
2009-10-31 00:36:06 +01:00
|
|
|
else
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ChangeMarkedWord( sError, eLanguage );
|
2009-10-31 00:36:06 +01:00
|
|
|
SpellContinue_Impl();
|
|
|
|
}
|
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->AddUndoAction(new SpellUndoAction_Impl(SPELLUNDO_CHANGE_LANGUAGE, aDialogUndoLink));
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
SpellDialog::UpdateBoxes_Impl();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SpellDialog::SetLanguage( sal_uInt16 nLang )
|
2012-04-15 17:50:21 +02:00
|
|
|
/*
|
|
|
|
Description:
|
|
|
|
If the language has been changed in thesaurus,
|
|
|
|
it must be changed here, too.
|
2009-10-31 00:36:06 +01:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
SetTitle_Impl( nLang );
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pLanguageLB->SelectLanguage( nLang );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpellDialog::SetTitle_Impl(LanguageType nLang)
|
|
|
|
{
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString sTitle = rParent.HasGrammarChecking() ? m_sTitleSpellingGrammar : m_sTitleSpelling;
|
|
|
|
sTitle = sTitle.replaceFirst( "$LANGUAGE ($LOCATION)", SvtLanguageTable::GetLanguageString(nLang) );
|
2009-10-31 00:36:06 +01:00
|
|
|
SetText( sTitle );
|
|
|
|
}
|
|
|
|
|
2012-05-17 14:14:58 +01:00
|
|
|
int SpellDialog::InitUserDicts()
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
const LanguageType nLang = m_pLanguageLB->GetSelectLanguage();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
const Reference< XDictionary > *pDic = 0;
|
|
|
|
|
|
|
|
// get list of dictionaries
|
2013-02-04 16:18:01 +02:00
|
|
|
Reference< XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
|
2009-10-31 00:36:06 +01:00
|
|
|
if (xDicList.is())
|
|
|
|
{
|
|
|
|
// add active, positive dictionary to dic-list (if not already done).
|
|
|
|
// This is to ensure that there is at least on dictionary to which
|
|
|
|
// words could be added.
|
|
|
|
Reference< XDictionary > xDic( SvxGetOrCreatePosDic( xDicList ) );
|
|
|
|
if (xDic.is())
|
|
|
|
xDic->setActive( sal_True );
|
|
|
|
|
|
|
|
pImpl->aDics = xDicList->getDictionaries();
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:19:13 +02:00
|
|
|
SvtLinguConfig aCfg;
|
|
|
|
|
|
|
|
// list suitable dictionaries
|
|
|
|
bool bEnable = false;
|
2009-10-31 00:36:06 +01:00
|
|
|
const sal_Int32 nSize = pImpl->aDics.getLength();
|
|
|
|
pDic = pImpl->aDics.getConstArray();
|
2012-12-22 13:51:32 +00:00
|
|
|
PopupMenu* pMenu = m_pAddToDictMB->GetPopupMenu();
|
|
|
|
assert(pMenu);
|
|
|
|
pMenu->Clear();
|
2010-09-01 13:19:13 +02:00
|
|
|
pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nItemId = 1; // menu items should be enumerated from 1 and not 0
|
2010-09-01 13:19:13 +02:00
|
|
|
for (sal_Int32 i = 0; i < nSize; ++i)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-09-01 13:19:13 +02:00
|
|
|
uno::Reference< linguistic2::XDictionary > xDicTmp( pDic[i], uno::UNO_QUERY );
|
|
|
|
if (!xDicTmp.is() || SvxGetIgnoreAllList() == xDicTmp)
|
2009-10-31 00:36:06 +01:00
|
|
|
continue;
|
|
|
|
|
2010-09-01 13:19:13 +02:00
|
|
|
uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
|
2012-11-24 18:54:09 +01:00
|
|
|
LanguageType nActLanguage = LanguageTag( xDicTmp->getLocale() ).getLanguageType();
|
2010-09-01 13:19:13 +02:00
|
|
|
if( xDicTmp->isActive()
|
|
|
|
&& xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
|
|
|
|
&& (nLang == nActLanguage || LANGUAGE_NONE == nActLanguage )
|
|
|
|
&& (!xStor.is() || !xStor->isReadonly()) )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-09-01 13:19:13 +02:00
|
|
|
pMenu->InsertItem( nItemId, xDicTmp->getName() );
|
|
|
|
bEnable = sal_True;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2010-09-01 13:19:13 +02:00
|
|
|
uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
|
|
|
|
if (xSvcInfo.is())
|
|
|
|
{
|
|
|
|
OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
|
2011-03-12 23:58:22 -06:00
|
|
|
xSvcInfo->getImplementationName()) );
|
2011-12-16 17:29:07 -02:00
|
|
|
if (!aDictionaryImageUrl.isEmpty())
|
2010-09-01 13:19:13 +02:00
|
|
|
{
|
2013-10-20 01:43:00 -02:00
|
|
|
Image aImage( aDictionaryImageUrl );
|
2010-09-01 13:19:13 +02:00
|
|
|
pMenu->SetItemImage( nItemId, aImage );
|
|
|
|
}
|
|
|
|
}
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2010-09-01 13:19:13 +02:00
|
|
|
++nItemId;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pAddToDictMB->Enable( bEnable );
|
|
|
|
m_pAddToDictPB->Enable( bEnable );
|
2012-05-17 14:14:58 +01:00
|
|
|
|
|
|
|
int nDicts = nItemId-1;
|
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pAddToDictMB->Show( nDicts > 1 );
|
|
|
|
m_pAddToDictPB->Show( nDicts <= 1 );
|
2012-05-17 14:14:58 +01:00
|
|
|
|
|
|
|
return nDicts;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2012-05-22 16:10:22 +01:00
|
|
|
IMPL_LINK(SpellDialog, AddToDictClickHdl, PushButton*, EMPTYARG )
|
2012-04-14 13:17:04 +02:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
return AddToDictionaryExecute(1, m_pAddToDictMB->GetPopupMenu());
|
2012-04-14 13:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
IMPL_LINK(SpellDialog, AddToDictSelectHdl, MenuButton*, pButton )
|
|
|
|
{
|
|
|
|
return AddToDictionaryExecute(pButton->GetCurItemId(), pButton->GetPopupMenu());
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
int SpellDialog::AddToDictionaryExecute( sal_uInt16 nItemId, PopupMenu *pMenu )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
//GetErrorText() returns the current error even if the text is already
|
|
|
|
//manually changed
|
2013-09-26 08:30:52 +02:00
|
|
|
const OUString aNewWord = m_pSentenceED->GetErrorText();
|
2010-09-01 13:19:13 +02:00
|
|
|
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString aDicName ( pMenu->GetItemText( nItemId ) );
|
2010-09-01 13:19:13 +02:00
|
|
|
|
|
|
|
uno::Reference< linguistic2::XDictionary > xDic;
|
2013-02-04 16:18:01 +02:00
|
|
|
uno::Reference< linguistic2::XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
|
2010-09-01 13:19:13 +02:00
|
|
|
if (xDicList.is())
|
|
|
|
xDic = xDicList->getDictionaryByName( aDicName );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
sal_Int16 nAddRes = DIC_ERR_UNKNOWN;
|
|
|
|
if (xDic.is())
|
|
|
|
{
|
2011-01-14 12:41:27 +01:00
|
|
|
nAddRes = linguistic::AddEntryToDic( xDic, aNewWord, sal_False, OUString(), LANGUAGE_NONE );
|
2010-09-01 13:19:13 +02:00
|
|
|
// save modified user-dictionary if it is persistent
|
|
|
|
uno::Reference< frame::XStorable > xSavDic( xDic, uno::UNO_QUERY );
|
|
|
|
if (xSavDic.is())
|
|
|
|
xSavDic->store();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2010-09-01 13:19:13 +02:00
|
|
|
if (nAddRes == DIC_ERR_NONE)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
|
|
|
|
SPELLUNDO_CHANGE_ADD_TO_DICTIONARY, aDialogUndoLink);
|
2010-09-01 13:19:13 +02:00
|
|
|
pAction->SetDictionary( xDic );
|
|
|
|
pAction->SetAddedWord( aNewWord );
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->AddUndoAction( pAction );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
// failed because there is already an entry?
|
2010-09-01 13:19:13 +02:00
|
|
|
if (DIC_ERR_NONE != nAddRes && xDic->getEntry( aNewWord ).is())
|
2009-10-31 00:36:06 +01:00
|
|
|
nAddRes = DIC_ERR_NONE;
|
|
|
|
}
|
|
|
|
if (DIC_ERR_NONE != nAddRes)
|
|
|
|
{
|
|
|
|
SvxDicError( this, nAddRes );
|
2012-04-15 17:50:21 +02:00
|
|
|
return 0; // don't continue
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// go on
|
|
|
|
SpellContinue_Impl();
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->UndoActionEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
IMPL_LINK(SpellDialog, ModifyHdl, SentenceEditWindow_Impl*, pEd)
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
if (m_pSentenceED == pEd)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
bModified = true;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSuggestionLB->SetNoSelection();
|
|
|
|
m_pSuggestionLB->Disable();
|
2013-01-21 14:32:09 +01:00
|
|
|
OUString sNewText( m_pSentenceED->GetText() );
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pAutoCorrPB->Enable( sNewText != m_pSentenceED->GetText() );
|
2009-10-31 00:36:06 +01:00
|
|
|
SpellUndoAction_Impl* pSpellAction = new SpellUndoAction_Impl(SPELLUNDO_CHANGE_TEXTENGINE, aDialogUndoLink);
|
2012-12-22 13:51:32 +00:00
|
|
|
if(!m_pChangeAllPB->IsEnabled())
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pChangeAllPB->Enable();
|
2009-10-31 00:36:06 +01:00
|
|
|
pSpellAction->SetEnableChangeAllPB();
|
|
|
|
}
|
2012-12-22 13:51:32 +00:00
|
|
|
if(!m_pChangePB->IsEnabled())
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pChangePB->Enable();
|
2009-10-31 00:36:06 +01:00
|
|
|
pSpellAction->SetEnableChangePB();
|
|
|
|
}
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->AddUndoAction(pSpellAction);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(SpellDialog, CancelHdl)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-04-22 13:08:19 +02:00
|
|
|
//apply changes and ignored text parts first - if there are any
|
2012-12-22 13:51:32 +00:00
|
|
|
rParent.ApplyChangedSentence(m_pSentenceED->CreateSpellPortions(true), false);
|
2009-10-31 00:36:06 +01:00
|
|
|
Close();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
long SpellDialog::Notify( NotifyEvent& rNEvt )
|
|
|
|
{
|
|
|
|
/* #i38338#
|
|
|
|
* FIXME: LoseFocus and GetFocus are signals from vcl that
|
|
|
|
* a window actually got/lost the focus, it never should be
|
|
|
|
* forwarded from another window, that is simply wrong.
|
|
|
|
* FIXME: overloading the virtual methods GetFocus and LoseFocus
|
|
|
|
* in SpellDialogChildWindow by making them pure is at least questionable.
|
|
|
|
* The only sensible thing would be to call the new Method differently,
|
|
|
|
* e.g. DialogGot/LostFocus or so.
|
|
|
|
*/
|
|
|
|
if( IsVisible() && !bFocusLocked )
|
|
|
|
{
|
|
|
|
if( rNEvt.GetType() == EVENT_GETFOCUS )
|
|
|
|
{
|
|
|
|
//notify the child window of the focus change
|
|
|
|
rParent.GetFocus();
|
|
|
|
}
|
|
|
|
else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
|
|
|
|
{
|
|
|
|
//notify the child window of the focus change
|
|
|
|
rParent.LoseFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SfxModelessDialog::Notify(rNEvt);
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SpellDialog::InvalidateDialog()
|
|
|
|
{
|
|
|
|
if( bFocusLocked )
|
|
|
|
return;
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pIgnorePB->SetText(m_sResumeST);
|
2009-10-31 00:36:06 +01:00
|
|
|
Window* aDisableArr[] =
|
2012-12-22 13:51:32 +00:00
|
|
|
{
|
|
|
|
m_pNotInDictFT,
|
|
|
|
m_pSentenceED,
|
|
|
|
m_pSuggestionFT,
|
|
|
|
m_pSuggestionLB,
|
|
|
|
m_pLanguageFT,
|
|
|
|
m_pLanguageLB,
|
|
|
|
m_pIgnoreAllPB,
|
|
|
|
m_pIgnoreRulePB,
|
|
|
|
m_pAddToDictMB,
|
|
|
|
m_pAddToDictPB,
|
|
|
|
m_pChangePB,
|
|
|
|
m_pChangeAllPB,
|
|
|
|
m_pAutoCorrPB,
|
|
|
|
m_pUndoPB,
|
|
|
|
0
|
|
|
|
};
|
2009-10-31 00:36:06 +01:00
|
|
|
sal_Int16 i = 0;
|
|
|
|
while(aDisableArr[i])
|
|
|
|
{
|
2011-01-14 12:41:27 +01:00
|
|
|
aDisableArr[i]->Enable(sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
SfxModelessDialog::Deactivate();
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2010-04-22 13:08:19 +02:00
|
|
|
bool SpellDialog::GetNextSentence_Impl(bool bUseSavedSentence, bool bRecheck)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
2010-11-02 13:40:45 +00:00
|
|
|
if(!bUseSavedSentence)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-04-22 13:08:19 +02:00
|
|
|
//apply changes and ignored text parts
|
2012-12-22 13:51:32 +00:00
|
|
|
rParent.ApplyChangedSentence(m_pSentenceED->CreateSpellPortions(true), bRecheck);
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ResetIgnoreErrorsAt();
|
|
|
|
m_pSentenceED->ResetModified();
|
2010-04-22 13:08:19 +02:00
|
|
|
SpellPortions aSentence = bUseSavedSentence ? m_aSavedSentence : rParent.GetNextWrongSentence( bRecheck );
|
2009-10-31 00:36:06 +01:00
|
|
|
if(!bUseSavedSentence)
|
|
|
|
m_aSavedSentence = aSentence;
|
|
|
|
bool bHasReplaced = false;
|
2012-01-21 19:57:19 +01:00
|
|
|
while(!aSentence.empty())
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
//apply all changes that are already part of the "ChangeAllList"
|
|
|
|
//returns true if the list still contains errors after the changes have been applied
|
|
|
|
|
|
|
|
if(!ApplyChangeAllList_Impl(aSentence, bHasReplaced))
|
|
|
|
{
|
2010-04-22 13:08:19 +02:00
|
|
|
rParent.ApplyChangedSentence(aSentence, bRecheck);
|
|
|
|
aSentence = rParent.GetNextWrongSentence( bRecheck );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-21 19:57:19 +01:00
|
|
|
if(!aSentence.empty())
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
SpellPortions::iterator aStart = aSentence.begin();
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sText;
|
2009-10-31 00:36:06 +01:00
|
|
|
while(aStart != aSentence.end())
|
|
|
|
{
|
|
|
|
// hidden text has to be ignored
|
|
|
|
if(!aStart->bIsHidden)
|
|
|
|
sText += aStart->sText;
|
2011-01-01 21:21:56 +00:00
|
|
|
++aStart;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->SetText(sText);
|
2009-10-31 00:36:06 +01:00
|
|
|
aStart = aSentence.begin();
|
|
|
|
sal_Int32 nStartPosition = 0;
|
|
|
|
sal_Int32 nEndPosition = 0;
|
|
|
|
|
|
|
|
while(aStart != aSentence.end())
|
|
|
|
{
|
|
|
|
// hidden text has to be ignored
|
|
|
|
if(!aStart->bIsHidden)
|
|
|
|
{
|
|
|
|
nEndPosition += aStart->sText.getLength();
|
|
|
|
if(aStart->xAlternatives.is())
|
|
|
|
{
|
|
|
|
uno::Reference< container::XNamed > xNamed( aStart->xAlternatives, uno::UNO_QUERY );
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sServiceName;
|
2009-10-31 00:36:06 +01:00
|
|
|
if( xNamed.is() )
|
|
|
|
sServiceName = xNamed->getName();
|
|
|
|
SpellErrorDescription aDesc( false, aStart->xAlternatives->getWord(),
|
|
|
|
aStart->xAlternatives->getLocale(), aStart->xAlternatives->getAlternatives(), 0, sServiceName);
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->SetAttrib( SpellErrorAttrib(aDesc), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
else if(aStart->bIsGrammarError )
|
|
|
|
{
|
2011-10-23 07:35:06 -07:00
|
|
|
beans::PropertyValues aProperties = aStart->aGrammarError.aProperties;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFullCommentURL;
|
2011-10-23 07:35:06 -07:00
|
|
|
sal_Int32 i = 0;
|
2011-12-13 10:18:52 +01:00
|
|
|
while ( sFullCommentURL.isEmpty() && i < aProperties.getLength() )
|
2011-10-23 07:35:06 -07:00
|
|
|
{
|
2012-04-06 15:05:52 +02:00
|
|
|
if ( aProperties[i].Name == "FullCommentURL" )
|
2011-10-23 07:35:06 -07:00
|
|
|
{
|
|
|
|
uno::Any aValue = aProperties[i].Value;
|
|
|
|
aValue >>= sFullCommentURL;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
uno::Reference< lang::XServiceInfo > xInfo( aStart->xGrammarChecker, uno::UNO_QUERY );
|
|
|
|
SpellErrorDescription aDesc( true,
|
|
|
|
aStart->sText,
|
2013-07-13 02:54:05 +02:00
|
|
|
LanguageTag::convertToLocale( aStart->eLanguage ),
|
2009-10-31 00:36:06 +01:00
|
|
|
aStart->aGrammarError.aSuggestions,
|
|
|
|
aStart->xGrammarChecker,
|
|
|
|
xInfo->getImplementationName(),
|
|
|
|
&aStart->sDialogTitle,
|
|
|
|
&aStart->aGrammarError.aFullComment,
|
2011-10-23 07:35:06 -07:00
|
|
|
&aStart->aGrammarError.aRuleIdentifier,
|
|
|
|
&sFullCommentURL );
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->SetAttrib( SpellErrorAttrib(aDesc), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
if(aStart->bIsField)
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->SetAttrib( SpellBackgroundAttrib(COL_LIGHTGRAY), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
|
|
|
|
m_pSentenceED->SetAttrib( SpellLanguageAttrib(aStart->eLanguage), 0, (sal_uInt16) nStartPosition, (sal_uInt16) nEndPosition );
|
2009-10-31 00:36:06 +01:00
|
|
|
nStartPosition = nEndPosition;
|
|
|
|
}
|
2011-01-01 21:21:56 +00:00
|
|
|
++aStart;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
//the edit field needs to be modified to apply the change from the ApplyChangeAllList
|
|
|
|
if(!bHasReplaced)
|
2012-12-22 13:51:32 +00:00
|
|
|
m_pSentenceED->ClearModifyFlag();
|
|
|
|
m_pSentenceED->ResetUndo();
|
|
|
|
m_pUndoPB->Enable(sal_False);
|
2009-10-31 00:36:06 +01:00
|
|
|
bRet = nStartPosition > 0;
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-11-02 13:40:45 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
replace errrors that have a replacement in the ChangeAllList
|
|
|
|
returns false if the result doesn't contain errors after the replacement
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
bool SpellDialog::ApplyChangeAllList_Impl(SpellPortions& rSentence, bool &bHasReplaced)
|
|
|
|
{
|
|
|
|
bHasReplaced = false;
|
|
|
|
bool bRet = true;
|
|
|
|
SpellPortions::iterator aStart = rSentence.begin();
|
|
|
|
Reference<XDictionary> xChangeAll( SvxGetChangeAllList(), UNO_QUERY );
|
|
|
|
if(!xChangeAll->getCount())
|
|
|
|
return bRet;
|
|
|
|
bRet = false;
|
|
|
|
while(aStart != rSentence.end())
|
|
|
|
{
|
|
|
|
if(aStart->xAlternatives.is())
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString &rString = aStart->sText;
|
2011-10-17 15:18:44 +01:00
|
|
|
|
2012-05-29 22:27:11 +01:00
|
|
|
Reference<XDictionaryEntry> xEntry = xChangeAll->getEntry(rString);
|
2011-10-17 15:18:44 +01:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
if(xEntry.is())
|
|
|
|
{
|
2012-05-29 22:27:11 +01:00
|
|
|
aStart->sText = getDotReplacementString(rString, xEntry->getReplacementText());
|
2009-10-31 00:36:06 +01:00
|
|
|
aStart->xAlternatives = 0;
|
|
|
|
bHasReplaced = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
else if( aStart->bIsGrammarError )
|
|
|
|
bRet = true;
|
2011-01-01 21:21:56 +00:00
|
|
|
++aStart;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2012-12-22 13:51:32 +00:00
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
SentenceEditWindow_Impl::SentenceEditWindow_Impl(Window * pParent, WinBits nBits)
|
|
|
|
: MultiLineEdit(pParent, nBits)
|
|
|
|
, m_nErrorStart(0)
|
|
|
|
, m_nErrorEnd(0)
|
|
|
|
, m_bIsUndoEditMode(false)
|
|
|
|
{
|
|
|
|
DisableSelectionOnFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSentenceEditWindow(Window *pParent,
|
|
|
|
VclBuilder::stringmap &)
|
|
|
|
{
|
|
|
|
return new SentenceEditWindow_Impl(pParent, WB_BORDER|WB_VSCROLL|WB_IGNORETAB);
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
SentenceEditWindow_Impl::~SentenceEditWindow_Impl()
|
|
|
|
{
|
|
|
|
}
|
2010-11-02 13:40:45 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
The selection before inputting a key may have a range or not
|
|
|
|
and it may be inside or outside of field or error attributes.
|
|
|
|
A range may include the attribute partially, completely or together
|
|
|
|
with surrounding text. It may also contain more than one attribute
|
|
|
|
or no attribute at all.
|
|
|
|
Depending on this starting conditions some actions are necessary:
|
|
|
|
Attempts to delete a field are only allowed if the selection is the same
|
|
|
|
as the field's selection. Otherwise the field has to be selected and the key
|
|
|
|
input action has to be skipped.
|
|
|
|
Input of text at the start of the field requires the field attribute to be
|
|
|
|
corrected - it is not allowed to grow.
|
|
|
|
|
|
|
|
In case of errors the appending of text should grow the error attribute because
|
|
|
|
that is what the user usually wants to do.
|
|
|
|
|
|
|
|
Backspace at the start of the attribute requires to find out if a field ends
|
|
|
|
directly in front of the cursor position. In case of a field this attribute has to be
|
|
|
|
selected otherwise the key input method is allowed.
|
|
|
|
|
|
|
|
All changes outside of the error attributes switch the dialog mode to a "Undo edit" state that
|
|
|
|
removes all visible attributes and switches off further attribute checks.
|
|
|
|
Undo in this restarts the dialog with a current sentence newly presented.
|
|
|
|
All changes to the sentence are undone including the ones before the "Undo edit state" has been reached
|
|
|
|
|
|
|
|
We end up with 9 types of selection
|
|
|
|
1 (LEFT_NO) - no range, start of attribute - can also be 3 at the same time
|
|
|
|
2 (INSIDE_NO) - no range, inside of attribute
|
|
|
|
3 (RIGHT_NO) - no range, end of attribute - can also be 1 at the same time
|
|
|
|
4 (FULL) - range, same as attribute
|
|
|
|
5 (INSIDE_YES) - range, inside of the attribute
|
|
|
|
6 (BRACE)- range, from outside of the attribute to the inside or
|
|
|
|
including the complete attribute and something outside,
|
|
|
|
maybe more than one attribute
|
|
|
|
7 (OUTSIDE_NO) - no range, not at an attribute
|
|
|
|
8 (OUTSIDE_YES) - range, completely outside of all attributes
|
|
|
|
|
|
|
|
What has to be done depending on the attribute type involved
|
|
|
|
possible actions: UE - Undo edit mode
|
|
|
|
CO - Continue, no additional action is required
|
|
|
|
FS - Field has to be completely selected
|
|
|
|
EX - The attribute has to be expanded to include the added text
|
|
|
|
|
|
|
|
1 - backspace delete any other
|
|
|
|
UE on field FS on error CO on field FS on error CO
|
|
|
|
|
|
|
|
2 - on field FS on error C
|
|
|
|
3 - backspace delete any other
|
|
|
|
on field FS on error CO UE on field UE on error EX
|
|
|
|
|
|
|
|
if 1 and 3 happen to apply both then backspace and other handling is 1 delete is 3
|
|
|
|
|
|
|
|
4 - on field UE and on error CO
|
|
|
|
5 - on field FS and on error CO
|
|
|
|
6 - on field FS and on error UE
|
|
|
|
7 - UE
|
|
|
|
8 - UE
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
#define INVALID 0
|
|
|
|
#define LEFT_NO 1
|
|
|
|
#define INSIDE_NO 2
|
|
|
|
#define RIGHT_NO 3
|
|
|
|
#define FULL 4
|
|
|
|
#define INSIDE_YES 5
|
|
|
|
#define BRACE 6
|
|
|
|
#define OUTSIDE_NO 7
|
|
|
|
#define OUTSIDE_YES 8
|
|
|
|
|
|
|
|
#define ACTION_UNDOEDIT 0
|
|
|
|
#define ACTION_CONTINUE 1
|
|
|
|
#define ACTION_SELECTFIELD 2
|
|
|
|
#define ACTION_EXPAND 3
|
|
|
|
|
|
|
|
long SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
|
|
|
|
{
|
|
|
|
bool bChange = false;
|
|
|
|
const TextCharAttrib* pErrorAttrib = 0;
|
|
|
|
if(rNEvt.GetType() == EVENT_KEYINPUT)
|
|
|
|
{
|
|
|
|
const KeyEvent& rKeyEvt = *rNEvt.GetKeyEvent();
|
|
|
|
bChange = TextEngine::DoesKeyChangeText( rKeyEvt );
|
|
|
|
if(bChange && !IsUndoEditMode() &&
|
|
|
|
rKeyEvt.GetKeyCode().GetCode() != KEY_TAB)
|
|
|
|
{
|
|
|
|
TextEngine* pTextEngine = GetTextEngine();
|
|
|
|
TextView* pTextView = pTextEngine->GetActiveView();
|
|
|
|
const TextSelection& rCurrentSelection = pTextView->GetSelection();
|
|
|
|
//determine if the selection contains a field
|
|
|
|
bool bHasField = false;
|
|
|
|
bool bHasError = false;
|
|
|
|
bool bHasFieldLeft = false;
|
|
|
|
bool bHasErrorLeft = false;
|
|
|
|
|
|
|
|
bool bHasRange = rCurrentSelection.HasRange();
|
|
|
|
sal_uInt8 nSelectionType = 0; // invalid type!
|
|
|
|
|
|
|
|
TextPaM aCursor(rCurrentSelection.GetStart());
|
|
|
|
const TextCharAttrib* pBackAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
|
|
|
|
const TextCharAttrib* pErrorAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
|
|
|
|
const TextCharAttrib* pBackAttrLeft = 0;
|
|
|
|
const TextCharAttrib* pErrorAttrLeft = 0;
|
|
|
|
|
|
|
|
bHasField = pBackAttr != 0 && (bHasRange || pBackAttr->GetEnd() > aCursor.GetIndex());
|
|
|
|
bHasError = pErrorAttr != 0 && (bHasRange || pErrorAttr->GetEnd() > aCursor.GetIndex());
|
|
|
|
if(bHasRange)
|
|
|
|
{
|
|
|
|
if(pBackAttr &&
|
|
|
|
pBackAttr->GetStart() == rCurrentSelection.GetStart().GetIndex() &&
|
|
|
|
pBackAttr->GetEnd() == rCurrentSelection.GetEnd().GetIndex())
|
|
|
|
{
|
|
|
|
nSelectionType = FULL;
|
|
|
|
}
|
|
|
|
else if(pErrorAttr &&
|
|
|
|
pErrorAttr->GetStart() <= rCurrentSelection.GetStart().GetIndex() &&
|
|
|
|
pErrorAttr->GetEnd() >= rCurrentSelection.GetEnd().GetIndex())
|
|
|
|
{
|
|
|
|
nSelectionType = INSIDE_YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nSelectionType = bHasField||bHasError ? BRACE : OUTSIDE_NO;
|
|
|
|
while(aCursor.GetIndex() < rCurrentSelection.GetEnd().GetIndex())
|
|
|
|
{
|
|
|
|
++aCursor.GetIndex();
|
|
|
|
const TextCharAttrib* pIntBackAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
|
|
|
|
const TextCharAttrib* pIntErrorAttr = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
|
|
|
|
//if any attr has been found then BRACE
|
|
|
|
if(pIntBackAttr || pIntErrorAttr)
|
|
|
|
nSelectionType = BRACE;
|
|
|
|
//the field has to be selected
|
|
|
|
if(pIntBackAttr && !pBackAttr)
|
|
|
|
pBackAttr = pIntBackAttr;
|
|
|
|
bHasField |= pIntBackAttr != 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//no range selection: then 1 2 3 and 8 are possible
|
|
|
|
const TextCharAttrib* pCurAttr = pBackAttr ? pBackAttr : pErrorAttr;
|
|
|
|
if(pCurAttr)
|
|
|
|
{
|
|
|
|
nSelectionType = pCurAttr->GetStart() == rCurrentSelection.GetStart().GetIndex() ?
|
|
|
|
LEFT_NO : pCurAttr->GetEnd() == rCurrentSelection.GetEnd().GetIndex() ? RIGHT_NO : INSIDE_NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nSelectionType = OUTSIDE_NO;
|
|
|
|
|
|
|
|
bHasFieldLeft = pBackAttr && pBackAttr->GetEnd() == aCursor.GetIndex();
|
|
|
|
if(bHasFieldLeft)
|
|
|
|
{
|
|
|
|
pBackAttrLeft = pBackAttr;
|
|
|
|
pBackAttr = 0;
|
|
|
|
}
|
|
|
|
bHasErrorLeft = pErrorAttr && pErrorAttr->GetEnd() == aCursor.GetIndex();
|
|
|
|
if(bHasErrorLeft)
|
|
|
|
{
|
|
|
|
pErrorAttrLeft = pErrorAttr;
|
|
|
|
pErrorAttr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check previous position if this exists
|
2013-02-22 09:48:17 +02:00
|
|
|
//that is a redundant in the case the attribute found above already is on the left cursor side
|
2009-10-31 00:36:06 +01:00
|
|
|
//but it's o.k. for two errors/fields side by side
|
|
|
|
if(aCursor.GetIndex())
|
|
|
|
{
|
|
|
|
--aCursor.GetIndex();
|
|
|
|
pBackAttrLeft = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_BACKGROUND );
|
|
|
|
pErrorAttrLeft = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR );
|
|
|
|
bHasFieldLeft = pBackAttrLeft !=0;
|
|
|
|
bHasErrorLeft = pErrorAttrLeft != 0;
|
|
|
|
++aCursor.GetIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Here we have to determine if the error found is the one currently active
|
|
|
|
bool bIsErrorActive = (pErrorAttr && pErrorAttr->GetStart() == m_nErrorStart) ||
|
|
|
|
(pErrorAttrLeft && pErrorAttrLeft->GetStart() == m_nErrorStart);
|
|
|
|
|
2013-03-27 22:27:52 +01:00
|
|
|
SAL_WARN_IF(
|
|
|
|
nSelectionType == INVALID, "cui.dialogs",
|
|
|
|
"selection type not set");
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
|
|
|
|
bool bDelete = rKeyCode.GetCode() == KEY_DELETE;
|
|
|
|
bool bBackspace = rKeyCode.GetCode() == KEY_BACKSPACE;
|
|
|
|
|
|
|
|
sal_Int8 nAction = ACTION_CONTINUE;
|
|
|
|
switch(nSelectionType)
|
|
|
|
{
|
|
|
|
// 1 - backspace delete any other
|
|
|
|
// UE on field FS on error CO on field FS on error CO
|
|
|
|
case LEFT_NO :
|
|
|
|
if(bBackspace)
|
|
|
|
{
|
|
|
|
nAction = bHasFieldLeft ? ACTION_SELECTFIELD : ACTION_UNDOEDIT;
|
|
|
|
//to force the use of pBackAttrLeft
|
|
|
|
pBackAttr = 0;
|
|
|
|
}
|
|
|
|
else if(bDelete)
|
|
|
|
nAction = bHasField ? ACTION_SELECTFIELD : ACTION_CONTINUE;
|
|
|
|
else
|
|
|
|
nAction = bHasError && !aCursor.GetIndex() ? ACTION_CONTINUE :
|
|
|
|
bHasError ? ACTION_EXPAND : bHasErrorLeft ? ACTION_CONTINUE : ACTION_UNDOEDIT;
|
|
|
|
break;
|
|
|
|
// 2 - on field FS on error C
|
|
|
|
case INSIDE_NO :
|
|
|
|
nAction = bHasField ? ACTION_SELECTFIELD :
|
|
|
|
bIsErrorActive ? ACTION_CONTINUE : ACTION_UNDOEDIT;
|
|
|
|
break;
|
|
|
|
// 3 - backspace delete any other
|
|
|
|
// on field FS on error CO UE on field UE on error EX
|
|
|
|
case RIGHT_NO :
|
|
|
|
if(bBackspace)
|
|
|
|
nAction = bHasFieldLeft ? ACTION_SELECTFIELD : ACTION_CONTINUE;
|
|
|
|
else if(bDelete)
|
|
|
|
nAction = bHasFieldLeft && bHasError ? ACTION_CONTINUE : ACTION_UNDOEDIT;
|
|
|
|
else
|
|
|
|
nAction = bHasFieldLeft && bHasError ? ACTION_EXPAND :
|
|
|
|
bHasError ? ACTION_CONTINUE : bHasErrorLeft ? ACTION_EXPAND :ACTION_UNDOEDIT;
|
|
|
|
break;
|
|
|
|
// 4 - on field UE and on error CO
|
|
|
|
case FULL :
|
|
|
|
nAction = bHasField ? ACTION_UNDOEDIT : ACTION_CONTINUE;
|
|
|
|
break;
|
|
|
|
// 5 - on field FS and on error CO
|
|
|
|
case INSIDE_YES :
|
|
|
|
nAction = bHasField ? ACTION_SELECTFIELD : ACTION_CONTINUE;
|
|
|
|
break;
|
|
|
|
// 6 - on field FS and on error UE
|
|
|
|
case BRACE :
|
|
|
|
nAction = bHasField ? ACTION_SELECTFIELD : ACTION_UNDOEDIT;;
|
|
|
|
break;
|
|
|
|
// 7 - UE
|
|
|
|
// 8 - UE
|
|
|
|
case OUTSIDE_NO :
|
|
|
|
case OUTSIDE_YES:
|
|
|
|
nAction = ACTION_UNDOEDIT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//save the current paragraph
|
2013-01-21 14:32:09 +01:00
|
|
|
sal_Int32 nCurrentLen = GetText().getLength();
|
2009-10-31 00:36:06 +01:00
|
|
|
if(nAction != ACTION_SELECTFIELD)
|
|
|
|
pTextView->GetWindow()->KeyInput(rKeyEvt);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const TextCharAttrib* pCharAttr = pBackAttr ? pBackAttr : pBackAttrLeft;
|
|
|
|
if(pCharAttr)
|
|
|
|
{
|
|
|
|
TextPaM aStart(0, pCharAttr->GetStart());
|
|
|
|
TextPaM aEnd(0, pCharAttr->GetEnd());
|
|
|
|
TextSelection aNewSel(aStart, aEnd);
|
|
|
|
pTextView->SetSelection( aNewSel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(nAction == ACTION_EXPAND)
|
|
|
|
{
|
|
|
|
DBG_ASSERT(pErrorAttrLeft || pErrorAttr, "where is the error");
|
|
|
|
//text has been added on the right and only the 'error attribute has to be corrected
|
|
|
|
if(pErrorAttrLeft)
|
|
|
|
{
|
2011-10-19 01:36:59 +02:00
|
|
|
TextAttrib* pNewError = pErrorAttrLeft->GetAttr().Clone();
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nStart = pErrorAttrLeft->GetStart();
|
|
|
|
sal_uInt16 nEnd = pErrorAttrLeft->GetEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
pTextEngine->RemoveAttrib( 0, *pErrorAttrLeft );
|
|
|
|
SetAttrib( *pNewError, 0, nStart, ++nEnd );
|
|
|
|
//only active errors move the mark
|
|
|
|
if(bIsErrorActive)
|
|
|
|
{
|
|
|
|
bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
|
|
|
|
MoveErrorMarkTo(nStart, nEnd, bGrammar);
|
|
|
|
}
|
|
|
|
delete pNewError;
|
|
|
|
}
|
|
|
|
//text has been added on the left then the error attribute has to be expanded and the
|
|
|
|
//field attribute on the right - if any - has to be contracted
|
|
|
|
else if(pErrorAttr)
|
|
|
|
{
|
|
|
|
//determine the change
|
2013-01-21 14:32:09 +01:00
|
|
|
sal_Int32 nAddedChars = GetText().getLength() - nCurrentLen;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2011-10-19 01:36:59 +02:00
|
|
|
TextAttrib* pNewError = pErrorAttr->GetAttr().Clone();
|
2013-01-21 14:32:09 +01:00
|
|
|
sal_Int32 nStart = pErrorAttr->GetStart();
|
|
|
|
sal_Int32 nEnd = pErrorAttr->GetEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
pTextEngine->RemoveAttrib( 0, *pErrorAttr );
|
2013-01-21 21:40:52 +01:00
|
|
|
nStart = nStart - nAddedChars;
|
2009-10-31 00:36:06 +01:00
|
|
|
SetAttrib( *pNewError, 0, nStart - nAddedChars, nEnd );
|
|
|
|
//only if the error is active the mark is moved here
|
|
|
|
if(bIsErrorActive)
|
|
|
|
{
|
|
|
|
bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
|
|
|
|
MoveErrorMarkTo(nStart, nEnd, bGrammar);
|
|
|
|
}
|
|
|
|
delete pNewError;
|
|
|
|
|
|
|
|
if(pBackAttrLeft)
|
|
|
|
{
|
2011-10-19 01:36:59 +02:00
|
|
|
TextAttrib* pNewBack = pBackAttrLeft->GetAttr().Clone();
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 _nStart = pBackAttrLeft->GetStart();
|
|
|
|
sal_uInt16 _nEnd = pBackAttrLeft->GetEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
pTextEngine->RemoveAttrib( 0, *pBackAttrLeft );
|
|
|
|
SetAttrib( *pNewBack, 0, _nStart, _nEnd - nAddedChars);
|
|
|
|
delete pNewBack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(nAction == ACTION_UNDOEDIT)
|
|
|
|
{
|
|
|
|
SetUndoEditMode(true);
|
|
|
|
}
|
|
|
|
//make sure the error positions are correct after text changes
|
|
|
|
//the old attribute may have been deleted
|
|
|
|
//all changes inside of the current error leave the error attribute at the current
|
|
|
|
//start position
|
|
|
|
if(!IsUndoEditMode() && bIsErrorActive)
|
|
|
|
{
|
|
|
|
const TextCharAttrib* pFontColor = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_FONTCOLOR );
|
|
|
|
pErrorAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_ERROR );
|
|
|
|
if(pFontColor && pErrorAttrib )
|
|
|
|
{
|
|
|
|
m_nErrorStart = pFontColor->GetStart();
|
|
|
|
m_nErrorEnd = pFontColor->GetEnd();
|
|
|
|
if(pErrorAttrib->GetStart() != m_nErrorStart || pErrorAttrib->GetEnd() != m_nErrorEnd)
|
|
|
|
{
|
2011-10-19 01:36:59 +02:00
|
|
|
TextAttrib* pNewError = pErrorAttrib->GetAttr().Clone();
|
2009-10-31 00:36:06 +01:00
|
|
|
pTextEngine->RemoveAttrib( 0, *pErrorAttr );
|
|
|
|
SetAttrib( *pNewError, 0, m_nErrorStart, m_nErrorEnd );
|
|
|
|
delete pNewError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//this is not a modification anymore
|
|
|
|
if(nAction != ACTION_SELECTFIELD && !m_bIsUndoEditMode)
|
|
|
|
CallModifyLink();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bChange = false;
|
|
|
|
}
|
|
|
|
long nRet = bChange ? 1 : MultiLineEdit::PreNotify(rNEvt);
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2010-04-22 13:08:19 +02:00
|
|
|
bool SentenceEditWindow_Impl::MarkNextError( bool bIgnoreCurrentError )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-04-22 13:08:19 +02:00
|
|
|
if (bIgnoreCurrentError)
|
|
|
|
m_aIgnoreErrorsAt.insert( m_nErrorStart );
|
2009-10-31 00:36:06 +01:00
|
|
|
ExtTextEngine* pTextEngine = GetTextEngine();
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nTextLen = pTextEngine->GetTextLen(0);
|
2009-10-31 00:36:06 +01:00
|
|
|
if(m_nErrorEnd >= nTextLen - 1)
|
|
|
|
return false;
|
|
|
|
//if it's not already modified the modified flag has to be reset at the and of the marking
|
|
|
|
bool bModified = IsModified();
|
|
|
|
bool bRet = false;
|
2011-01-14 12:41:27 +01:00
|
|
|
const sal_uInt16 nOldErrorStart = m_nErrorStart;
|
|
|
|
const sal_uInt16 nOldErrorEnd = m_nErrorEnd;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
//create a cursor behind the end of the last error
|
|
|
|
//- or at 0 at the start of the sentence
|
|
|
|
TextPaM aCursor(0, m_nErrorEnd ? m_nErrorEnd + 1 : 0);
|
|
|
|
//search for SpellErrorAttrib
|
|
|
|
|
|
|
|
const TextCharAttrib* pNextError = 0;
|
|
|
|
//iterate over the text and search for the next error that maybe has
|
|
|
|
//to be replace by a ChangeAllList replacement
|
|
|
|
bool bGrammarError = false;
|
|
|
|
while(aCursor.GetIndex() < nTextLen)
|
|
|
|
{
|
|
|
|
while(aCursor.GetIndex() < nTextLen &&
|
|
|
|
0 == (pNextError = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR)))
|
|
|
|
{
|
|
|
|
++aCursor.GetIndex();
|
|
|
|
}
|
|
|
|
// maybe the error found here is already in the ChangeAllList and has to be replaced
|
|
|
|
|
|
|
|
Reference<XDictionary> xChangeAll( SvxGetChangeAllList(), UNO_QUERY );
|
|
|
|
Reference<XDictionaryEntry> xEntry;
|
|
|
|
|
|
|
|
const SpellErrorDescription* pSpellErrorDescription = 0;
|
|
|
|
if(pNextError)
|
|
|
|
{
|
|
|
|
pSpellErrorDescription = &static_cast<const SpellErrorAttrib&>(pNextError->GetAttr()).GetErrorDescription();
|
|
|
|
bGrammarError = pSpellErrorDescription->bIsGrammarError;
|
|
|
|
}
|
|
|
|
if(xChangeAll->getCount() && pSpellErrorDescription &&
|
|
|
|
(xEntry = xChangeAll->getEntry( pSpellErrorDescription->sErrorText )).is())
|
|
|
|
{
|
|
|
|
m_nErrorStart = pNextError->GetStart();
|
|
|
|
m_nErrorEnd = pNextError->GetEnd();
|
2012-05-29 22:27:11 +01:00
|
|
|
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString sReplacement(getDotReplacementString(GetErrorText(), xEntry->getReplacementText()));
|
2012-05-29 22:27:11 +01:00
|
|
|
|
2013-07-13 02:54:05 +02:00
|
|
|
ChangeMarkedWord(sReplacement, LanguageTag::convertToLanguageType( pSpellErrorDescription->aLocale ));
|
2012-05-29 22:27:11 +01:00
|
|
|
|
2011-01-14 12:41:27 +01:00
|
|
|
aCursor.GetIndex() = aCursor.GetIndex() + (sal_uInt16)(xEntry->getReplacementText().getLength());
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//if an attrib has been found search for the end of the error string
|
|
|
|
if(aCursor.GetIndex() < nTextLen)
|
|
|
|
{
|
|
|
|
m_nErrorStart = aCursor.GetIndex();
|
|
|
|
m_nErrorEnd = pNextError->GetEnd();
|
|
|
|
MoveErrorMarkTo(m_nErrorStart, m_nErrorEnd, bGrammarError);
|
|
|
|
bRet = true;
|
|
|
|
//add an undo action
|
|
|
|
SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
|
|
|
|
SPELLUNDO_CHANGE_NEXTERROR, GetSpellDialog()->aDialogUndoLink);
|
|
|
|
pAction->SetErrorMove(m_nErrorStart, m_nErrorEnd, nOldErrorStart, nOldErrorEnd);
|
|
|
|
const SpellErrorAttrib* pOldAttrib = static_cast<const SpellErrorAttrib*>(
|
|
|
|
pTextEngine->FindAttrib( TextPaM(0, nOldErrorStart), TEXTATTR_SPELL_ERROR ));
|
|
|
|
pAction->SetErrorLanguageSelected(pOldAttrib && pOldAttrib->GetErrorDescription().aSuggestions.getLength() &&
|
2012-11-24 18:54:09 +01:00
|
|
|
LanguageTag( pOldAttrib->GetErrorDescription().aLocale).getLanguageType() ==
|
2012-12-22 13:51:32 +00:00
|
|
|
GetSpellDialog()->m_pLanguageLB->GetSelectLanguage());
|
2009-10-31 00:36:06 +01:00
|
|
|
AddUndoAction(pAction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_nErrorStart = m_nErrorEnd = nTextLen;
|
|
|
|
if( !bModified )
|
|
|
|
ClearModifyFlag();
|
|
|
|
SpellDialog* pSpellDialog = GetSpellDialog();
|
2012-12-22 13:51:32 +00:00
|
|
|
pSpellDialog->m_pIgnorePB->Enable(bRet);
|
|
|
|
pSpellDialog->m_pIgnoreAllPB->Enable(bRet);
|
|
|
|
pSpellDialog->m_pAutoCorrPB->Enable(bRet);
|
|
|
|
pSpellDialog->m_pAddToDictMB->Enable(bRet);
|
|
|
|
pSpellDialog->m_pAddToDictPB->Enable(bRet);
|
2009-10-31 00:36:06 +01:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2011-01-14 12:41:27 +01:00
|
|
|
void SentenceEditWindow_Impl::MoveErrorMarkTo(sal_uInt16 nStart, sal_uInt16 nEnd, bool bGrammarError)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
TextEngine* pTextEngine = GetTextEngine();
|
2011-01-14 12:41:27 +01:00
|
|
|
pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTCOLOR, sal_True );
|
|
|
|
pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTWEIGHT, sal_True );
|
2009-10-31 00:36:06 +01:00
|
|
|
pTextEngine->SetAttrib( TextAttribFontWeight(WEIGHT_BOLD), 0, nStart, nEnd );
|
|
|
|
pTextEngine->SetAttrib( TextAttribFontColor(bGrammarError ? COL_LIGHTBLUE : COL_LIGHTRED), 0, nStart, nEnd );
|
|
|
|
m_nErrorStart = nStart;
|
|
|
|
m_nErrorEnd = nEnd;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2013-09-26 08:30:52 +02:00
|
|
|
void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, LanguageType eLanguage)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
//calculate length changes
|
2013-09-26 08:30:52 +02:00
|
|
|
long nDiffLen = rNewWord.getLength() - m_nErrorEnd + m_nErrorStart;
|
2009-10-31 00:36:06 +01:00
|
|
|
TextSelection aSel(TextPaM(0, m_nErrorStart), TextPaM(0, m_nErrorEnd));
|
|
|
|
//Remove spell errror attribute
|
|
|
|
ExtTextEngine* pTextEngine = GetTextEngine();
|
2010-11-26 14:04:34 +01:00
|
|
|
pTextEngine->UndoActionStart();
|
2009-10-31 00:36:06 +01:00
|
|
|
const TextCharAttrib* pErrorAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_ERROR );
|
|
|
|
DBG_ASSERT(pErrorAttrib, "no error attribute found");
|
|
|
|
const SpellErrorDescription* pSpellErrorDescription = 0;
|
|
|
|
if(pErrorAttrib)
|
|
|
|
{
|
|
|
|
pTextEngine->RemoveAttrib(0, *pErrorAttrib);
|
|
|
|
pSpellErrorDescription = &static_cast<const SpellErrorAttrib&>(pErrorAttrib->GetAttr()).GetErrorDescription();
|
|
|
|
}
|
|
|
|
const TextCharAttrib* pBackAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_BACKGROUND );
|
|
|
|
pTextEngine->ReplaceText( aSel, rNewWord );
|
2010-11-02 13:40:45 +00:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
if(!m_nErrorStart)
|
|
|
|
{
|
|
|
|
//attributes following an error at the start of the text are not moved but expanded from the
|
|
|
|
//text engine - this is done to keep full-paragraph-attributes
|
|
|
|
//in the current case that handling is not desired
|
|
|
|
const TextCharAttrib* pLangAttrib =
|
|
|
|
pTextEngine->FindCharAttrib(
|
|
|
|
TextPaM(0, m_nErrorEnd), TEXTATTR_SPELL_LANGUAGE );
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nTextLen = pTextEngine->GetTextLen( 0 );
|
2009-10-31 00:36:06 +01:00
|
|
|
if(pLangAttrib && !pLangAttrib->GetStart() && pLangAttrib->GetEnd() ==
|
|
|
|
nTextLen)
|
|
|
|
{
|
|
|
|
SpellLanguageAttrib aNewLangAttrib( static_cast<const SpellLanguageAttrib&>(pLangAttrib->GetAttr()).GetLanguage());
|
|
|
|
pTextEngine->RemoveAttrib(0, *pLangAttrib);
|
2011-01-14 12:41:27 +01:00
|
|
|
pTextEngine->SetAttrib( aNewLangAttrib, 0, (sal_uInt16)(m_nErrorEnd + nDiffLen) , nTextLen );
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// undo expanded attributes!
|
|
|
|
if( pBackAttrib && pBackAttrib->GetStart() < m_nErrorStart && pBackAttrib->GetEnd() == m_nErrorEnd + nDiffLen)
|
|
|
|
{
|
2011-10-19 01:36:59 +02:00
|
|
|
TextAttrib* pNewBackground = pBackAttrib->GetAttr().Clone();
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nStart = pBackAttrib->GetStart();
|
2009-10-31 00:36:06 +01:00
|
|
|
pTextEngine->RemoveAttrib(0, *pBackAttrib);
|
|
|
|
pTextEngine->SetAttrib(*pNewBackground, 0, nStart, m_nErrorStart);
|
|
|
|
delete pNewBackground;
|
|
|
|
}
|
2011-01-14 12:41:27 +01:00
|
|
|
pTextEngine->SetModified(sal_True);
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
//adjust end position
|
|
|
|
long nEndTemp = m_nErrorEnd;
|
|
|
|
nEndTemp += nDiffLen;
|
2011-01-14 12:41:27 +01:00
|
|
|
m_nErrorEnd = (sal_uInt16)nEndTemp;
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
|
|
|
|
SPELLUNDO_MOVE_ERROREND, GetSpellDialog()->aDialogUndoLink);
|
|
|
|
pAction->SetOffset(nDiffLen);
|
|
|
|
AddUndoAction(pAction);
|
|
|
|
if(pSpellErrorDescription)
|
|
|
|
SetAttrib( SpellErrorAttrib(*pSpellErrorDescription), 0, m_nErrorStart, m_nErrorEnd );
|
|
|
|
SetAttrib( SpellLanguageAttrib(eLanguage), 0, m_nErrorStart, m_nErrorEnd );
|
2010-11-26 14:04:34 +01:00
|
|
|
pTextEngine->UndoActionEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-------------------------------------------------
|
2013-09-26 08:30:52 +02:00
|
|
|
OUString SentenceEditWindow_Impl::GetErrorText() const
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
return GetTextEngine()->GetText(TextSelection(TextPaM(0, m_nErrorStart), TextPaM(0, m_nErrorEnd) ));
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
const SpellErrorDescription* SentenceEditWindow_Impl::GetAlternatives()
|
|
|
|
{
|
|
|
|
TextPaM aCursor(0, m_nErrorStart);
|
|
|
|
const SpellErrorAttrib* pAttrib = static_cast<const SpellErrorAttrib*>(
|
|
|
|
GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR));
|
|
|
|
return pAttrib ? &pAttrib->GetErrorDescription() : 0;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SentenceEditWindow_Impl::RestoreCurrentError()
|
|
|
|
{
|
|
|
|
TextPaM aCursor(0, m_nErrorStart);
|
|
|
|
const SpellErrorAttrib* pAttrib = static_cast<const SpellErrorAttrib*>(
|
|
|
|
GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR));
|
|
|
|
if( pAttrib )
|
|
|
|
{
|
|
|
|
const SpellErrorDescription& rDesc = pAttrib->GetErrorDescription();
|
|
|
|
if( !rDesc.sErrorText.equals( GetErrorText() ) )
|
2013-07-13 02:54:05 +02:00
|
|
|
ChangeMarkedWord(rDesc.sErrorText, LanguageTag::convertToLanguageType( rDesc.aLocale ));
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SentenceEditWindow_Impl::SetAlternatives( Reference< XSpellAlternatives> xAlt )
|
|
|
|
{
|
|
|
|
TextPaM aCursor(0, m_nErrorStart);
|
|
|
|
DBG_ASSERT(static_cast<const SpellErrorAttrib*>(
|
|
|
|
GetTextEngine()->FindAttrib( aCursor, TEXTATTR_SPELL_ERROR)), "no error set?");
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aWord;
|
2009-10-31 00:36:06 +01:00
|
|
|
lang::Locale aLocale;
|
2013-04-07 12:06:47 +02:00
|
|
|
uno::Sequence< OUString > aAlts;
|
|
|
|
OUString sServiceName;
|
2009-10-31 00:36:06 +01:00
|
|
|
if (xAlt.is())
|
|
|
|
{
|
|
|
|
aWord = xAlt->getWord();
|
|
|
|
aLocale = xAlt->getLocale();
|
|
|
|
aAlts = xAlt->getAlternatives();
|
|
|
|
uno::Reference< container::XNamed > xNamed( xAlt, uno::UNO_QUERY );
|
|
|
|
if (xNamed.is())
|
|
|
|
sServiceName = xNamed->getName();
|
|
|
|
}
|
|
|
|
SpellErrorDescription aDesc( false, aWord, aLocale, aAlts, 0, sServiceName);
|
|
|
|
GetTextEngine()->SetAttrib( SpellErrorAttrib(aDesc), 0, m_nErrorStart, m_nErrorEnd );
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2011-01-14 12:41:27 +01:00
|
|
|
void SentenceEditWindow_Impl::SetAttrib( const TextAttrib& rAttr, sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
GetTextEngine()->SetAttrib(rAttr, nPara, nStart, nEnd);
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2013-01-21 14:32:09 +01:00
|
|
|
void SentenceEditWindow_Impl::SetText( const OUString& rStr )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
m_nErrorStart = m_nErrorEnd = 0;
|
|
|
|
GetTextEngine()->SetText(rStr);
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
struct LanguagePosition_Impl
|
|
|
|
{
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nPosition;
|
2009-10-31 00:36:06 +01:00
|
|
|
LanguageType eLanguage;
|
|
|
|
|
2011-01-14 12:41:27 +01:00
|
|
|
LanguagePosition_Impl(sal_uInt16 nPos, LanguageType eLang) :
|
2009-10-31 00:36:06 +01:00
|
|
|
nPosition(nPos),
|
|
|
|
eLanguage(eLang)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
typedef std::vector<LanguagePosition_Impl> LanguagePositions_Impl;
|
|
|
|
|
2012-10-12 13:26:46 +02:00
|
|
|
static void lcl_InsertBreakPosition_Impl(
|
2011-01-14 12:41:27 +01:00
|
|
|
LanguagePositions_Impl& rBreakPositions, sal_uInt16 nInsert, LanguageType eLanguage)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
LanguagePositions_Impl::iterator aStart = rBreakPositions.begin();
|
|
|
|
while(aStart != rBreakPositions.end())
|
|
|
|
{
|
|
|
|
if(aStart->nPosition == nInsert)
|
|
|
|
{
|
|
|
|
//the language of following starts has to overwrite
|
|
|
|
//the one of previous ends
|
|
|
|
aStart->eLanguage = eLanguage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(aStart->nPosition > nInsert)
|
|
|
|
{
|
|
|
|
|
|
|
|
rBreakPositions.insert(aStart, LanguagePosition_Impl(nInsert, eLanguage));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++aStart;
|
|
|
|
}
|
|
|
|
rBreakPositions.push_back(LanguagePosition_Impl(nInsert, eLanguage));
|
|
|
|
}
|
2010-11-02 13:40:45 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
Returns the text in spell portions. Each portion contains text with an
|
|
|
|
equal language and attribute. The spell alternatives are empty.
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
svx::SpellPortions SentenceEditWindow_Impl::CreateSpellPortions( bool bSetIgnoreFlag ) const
|
|
|
|
{
|
|
|
|
svx::SpellPortions aRet;
|
|
|
|
ExtTextEngine* pTextEngine = GetTextEngine();
|
2011-01-14 12:41:27 +01:00
|
|
|
const sal_uInt16 nTextLen = pTextEngine->GetTextLen(0);
|
2009-10-31 00:36:06 +01:00
|
|
|
if(nTextLen)
|
|
|
|
{
|
|
|
|
TextPaM aCursor(0, 0);
|
|
|
|
LanguagePositions_Impl aBreakPositions;
|
|
|
|
const TextCharAttrib* pLastLang = 0;
|
|
|
|
const TextCharAttrib* pLastError = 0;
|
|
|
|
LanguageType eLang = LANGUAGE_DONTKNOW;
|
|
|
|
const TextCharAttrib* pError = 0;
|
|
|
|
while(aCursor.GetIndex() < nTextLen)
|
|
|
|
{
|
|
|
|
const TextCharAttrib* pLang = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_LANGUAGE);
|
|
|
|
if(pLang && pLang != pLastLang)
|
|
|
|
{
|
|
|
|
eLang = static_cast<const SpellLanguageAttrib&>(pLang->GetAttr()).GetLanguage();
|
|
|
|
lcl_InsertBreakPosition_Impl(aBreakPositions, pLang->GetStart(), eLang);
|
|
|
|
lcl_InsertBreakPosition_Impl(aBreakPositions, pLang->GetEnd(), eLang);
|
|
|
|
pLastLang = pLang;
|
|
|
|
}
|
|
|
|
pError = pTextEngine->FindCharAttrib( aCursor, TEXTATTR_SPELL_ERROR);
|
|
|
|
if(pError && pLastError != pError)
|
|
|
|
{
|
|
|
|
lcl_InsertBreakPosition_Impl(aBreakPositions, pError->GetStart(), eLang);
|
|
|
|
lcl_InsertBreakPosition_Impl(aBreakPositions, pError->GetEnd(), eLang);
|
|
|
|
pLastError = pError;
|
|
|
|
|
|
|
|
}
|
|
|
|
aCursor.GetIndex()++;
|
|
|
|
}
|
2010-11-02 13:40:45 +00:00
|
|
|
|
2009-10-31 00:36:06 +01:00
|
|
|
if(nTextLen && aBreakPositions.empty())
|
|
|
|
{
|
|
|
|
//if all content has been overwritten the attributes may have been removed, too
|
|
|
|
svx::SpellPortion aPortion1;
|
|
|
|
aPortion1.eLanguage = GetSpellDialog()->GetSelectedLang_Impl();
|
|
|
|
aPortion1.sText = pTextEngine->GetText(
|
|
|
|
TextSelection(TextPaM(0, 0), TextPaM(0, nTextLen)));
|
|
|
|
|
|
|
|
aRet.push_back(aPortion1);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(!aBreakPositions.empty())
|
|
|
|
{
|
|
|
|
LanguagePositions_Impl::iterator aStart = aBreakPositions.begin();
|
|
|
|
//start should always be Null
|
|
|
|
eLang = aStart->eLanguage;
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nStart = aStart->nPosition;
|
2009-10-31 00:36:06 +01:00
|
|
|
DBG_ASSERT(!nStart, "invalid start position - language attribute missing?");
|
|
|
|
++aStart;
|
|
|
|
|
|
|
|
while(aStart != aBreakPositions.end())
|
|
|
|
{
|
|
|
|
svx::SpellPortion aPortion1;
|
|
|
|
aPortion1.eLanguage = eLang;
|
|
|
|
aPortion1.sText = pTextEngine->GetText(
|
|
|
|
TextSelection(TextPaM(0, nStart), TextPaM(0, aStart->nPosition)));
|
2010-04-22 13:08:19 +02:00
|
|
|
bool bIsIgnoreError = m_aIgnoreErrorsAt.find( nStart ) != m_aIgnoreErrorsAt.end();
|
2010-11-02 13:40:45 +00:00
|
|
|
if( bSetIgnoreFlag && bIsIgnoreError )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
aPortion1.bIgnoreThisError = true;
|
|
|
|
}
|
|
|
|
aRet.push_back(aPortion1);
|
|
|
|
nStart = aStart->nPosition;
|
|
|
|
eLang = aStart->eLanguage;
|
|
|
|
++aStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// quick partly fix of #i71318. Correct fix needs to patch the TextEngine itself...
|
|
|
|
// this one will only prevent text from disappearing. It may to not have the
|
|
|
|
// correct language and will probably not spell checked...
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uLong nPara = pTextEngine->GetParagraphCount();
|
2009-10-31 00:36:06 +01:00
|
|
|
if (nPara > 1)
|
|
|
|
{
|
2013-03-13 10:42:57 -03:00
|
|
|
OUString aLeftOverText;
|
2011-01-14 12:41:27 +01:00
|
|
|
for (sal_uLong i = 1; i < nPara; ++i)
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2013-03-13 10:42:57 -03:00
|
|
|
aLeftOverText += "\x0a"; // the manual line break...
|
2009-10-31 00:36:06 +01:00
|
|
|
aLeftOverText += pTextEngine->GetText(i);
|
|
|
|
}
|
|
|
|
if (pError)
|
|
|
|
{ // we need to add a new portion containing the left-over text
|
|
|
|
svx::SpellPortion aPortion2;
|
|
|
|
aPortion2.eLanguage = eLang;
|
|
|
|
aPortion2.sText = aLeftOverText;
|
|
|
|
aRet.push_back( aPortion2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // we just need to append the left-over text to the last portion (which had no errors)
|
|
|
|
aRet[ aRet.size() - 1 ].sText += aLeftOverText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SentenceEditWindow_Impl::Undo()
|
|
|
|
{
|
2010-10-20 14:54:59 +02:00
|
|
|
::svl::IUndoManager& rUndoMgr = GetTextEngine()->GetUndoManager();
|
2009-10-31 00:36:06 +01:00
|
|
|
DBG_ASSERT(GetUndoActionCount(), "no undo actions available" );
|
|
|
|
if(!GetUndoActionCount())
|
|
|
|
return;
|
|
|
|
bool bSaveUndoEdit = IsUndoEditMode();
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 nId;
|
2009-10-31 00:36:06 +01:00
|
|
|
//if the undo edit mode is active then undo all changes until the UNDO_EDIT_MODE action has been found
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nId = rUndoMgr.GetUndoActionId();
|
|
|
|
rUndoMgr.Undo();
|
|
|
|
}while(bSaveUndoEdit && SPELLUNDO_UNDO_EDIT_MODE != nId && GetUndoActionCount());
|
|
|
|
|
|
|
|
if(bSaveUndoEdit || SPELLUNDO_CHANGE_GROUP == nId)
|
|
|
|
GetSpellDialog()->UpdateBoxes_Impl();
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SentenceEditWindow_Impl::ResetUndo()
|
|
|
|
{
|
|
|
|
GetTextEngine()->ResetUndo();
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2011-01-14 12:41:27 +01:00
|
|
|
void SentenceEditWindow_Impl::AddUndoAction( SfxUndoAction *pAction, sal_Bool bTryMerg )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-10-20 14:54:59 +02:00
|
|
|
::svl::IUndoManager& rUndoMgr = GetTextEngine()->GetUndoManager();
|
2009-10-31 00:36:06 +01:00
|
|
|
rUndoMgr.AddUndoAction(pAction, bTryMerg);
|
2012-12-22 13:51:32 +00:00
|
|
|
GetSpellDialog()->m_pUndoPB->Enable();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2011-01-14 12:41:27 +01:00
|
|
|
sal_uInt16 SentenceEditWindow_Impl::GetUndoActionCount()
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
return GetTextEngine()->GetUndoManager().GetUndoActionCount();
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2011-01-14 12:41:27 +01:00
|
|
|
void SentenceEditWindow_Impl::UndoActionStart( sal_uInt16 nId )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
|
|
|
GetTextEngine()->UndoActionStart(nId);
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2010-11-26 14:04:34 +01:00
|
|
|
void SentenceEditWindow_Impl::UndoActionEnd()
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2010-11-26 14:04:34 +01:00
|
|
|
GetTextEngine()->UndoActionEnd();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SentenceEditWindow_Impl::MoveErrorEnd(long nOffset)
|
|
|
|
{
|
|
|
|
if(nOffset > 0)
|
2011-01-14 12:41:27 +01:00
|
|
|
m_nErrorEnd = m_nErrorEnd - (sal_uInt16)nOffset;
|
2009-10-31 00:36:06 +01:00
|
|
|
else
|
2011-01-14 12:41:27 +01:00
|
|
|
m_nErrorEnd = m_nErrorEnd -(sal_uInt16)- nOffset;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2010-11-02 13:40:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
2009-10-31 00:36:06 +01:00
|
|
|
void SentenceEditWindow_Impl::SetUndoEditMode(bool bSet)
|
|
|
|
{
|
|
|
|
DBG_ASSERT(!bSet || m_bIsUndoEditMode != bSet, "SetUndoEditMode with equal values?");
|
|
|
|
m_bIsUndoEditMode = bSet;
|
|
|
|
//disable all buttons except the Change
|
|
|
|
SpellDialog* pSpellDialog = GetSpellDialog();
|
|
|
|
Control* aControls[] =
|
|
|
|
{
|
2012-12-22 13:51:32 +00:00
|
|
|
pSpellDialog->m_pChangeAllPB,
|
|
|
|
pSpellDialog->m_pExplainFT,
|
|
|
|
pSpellDialog->m_pIgnoreAllPB,
|
|
|
|
pSpellDialog->m_pIgnoreRulePB,
|
|
|
|
pSpellDialog->m_pIgnorePB,
|
|
|
|
pSpellDialog->m_pSuggestionLB,
|
|
|
|
pSpellDialog->m_pSuggestionFT,
|
|
|
|
pSpellDialog->m_pLanguageFT,
|
|
|
|
pSpellDialog->m_pLanguageLB,
|
|
|
|
pSpellDialog->m_pAddToDictMB,
|
|
|
|
pSpellDialog->m_pAddToDictPB,
|
|
|
|
pSpellDialog->m_pAutoCorrPB,
|
2009-10-31 00:36:06 +01:00
|
|
|
0
|
|
|
|
};
|
|
|
|
sal_Int32 nIdx = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
aControls[nIdx]->Enable(sal_False);
|
|
|
|
}
|
|
|
|
while(aControls[++nIdx]);
|
|
|
|
|
|
|
|
//remove error marks
|
|
|
|
TextEngine* pTextEngine = GetTextEngine();
|
2011-01-14 12:41:27 +01:00
|
|
|
pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTCOLOR, sal_True );
|
|
|
|
pTextEngine->RemoveAttribs( 0, (sal_uInt16)TEXTATTR_FONTWEIGHT, sal_True );
|
2009-10-31 00:36:06 +01:00
|
|
|
|
|
|
|
//put the appropriate action on the Undo-stack
|
|
|
|
SpellUndoAction_Impl* pAction = new SpellUndoAction_Impl(
|
|
|
|
SPELLUNDO_UNDO_EDIT_MODE, GetSpellDialog()->aDialogUndoLink);
|
|
|
|
AddUndoAction(pAction);
|
2012-12-22 13:51:32 +00:00
|
|
|
pSpellDialog->m_pChangePB->Enable();
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
|
|
|
|
2012-11-10 23:22:47 +00:00
|
|
|
IMPL_LINK( SpellDialog, HandleHyperlink, FixedHyperlink*, pHyperlink )
|
2009-10-31 00:36:06 +01:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sURL=pHyperlink->GetURL();
|
|
|
|
OUString sTitle=GetText();
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2011-12-16 17:29:07 -02:00
|
|
|
if ( sURL.isEmpty() ) // Nothing to do, when the URL is empty
|
2011-10-23 07:35:06 -07:00
|
|
|
return 1;
|
|
|
|
try
|
|
|
|
{
|
2012-09-03 18:27:13 +02:00
|
|
|
uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
|
|
|
|
com::sun::star::system::SystemShellExecute::create(::comphelper::getProcessComponentContext()) );
|
2013-04-07 12:06:47 +02:00
|
|
|
xSystemShellExecute->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
|
2011-10-23 07:35:06 -07:00
|
|
|
}
|
|
|
|
catch ( uno::Exception& )
|
|
|
|
{
|
|
|
|
uno::Any exc( ::cppu::getCaughtException() );
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString msg( ::comphelper::anyToString( exc ) );
|
2011-10-23 07:35:06 -07:00
|
|
|
const SolarMutexGuard guard;
|
|
|
|
ErrorBox aErrorBox( NULL, WB_OK, msg );
|
|
|
|
aErrorBox.SetText( sTitle );
|
|
|
|
aErrorBox.Execute();
|
|
|
|
}
|
2009-10-31 00:36:06 +01:00
|
|
|
|
2011-10-23 07:35:06 -07:00
|
|
|
return 1;
|
2009-10-31 00:36:06 +01:00
|
|
|
}
|
2010-10-12 15:57:08 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|