1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_ACORRECT_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_ACORRECT_HXX
22 
23 #include <memory>
24 
25 #include <svl/itemset.hxx>
26 #include <tools/solar.h>
27 #include <editeng/svxacorr.hxx>
28 
29 class SwEditShell;
30 class SwPaM;
31 class SwNodeIndex;
32 struct SwPosition;
33 class SfxItemSet;
34 
35 class SwDontExpandItem
36 {
37     std::unique_ptr<SfxItemSet> m_pDontExpandItems;
38 
39 public:
SwDontExpandItem()40     SwDontExpandItem() {}
41     ~SwDontExpandItem();
42 
43     void SaveDontExpandItems( const SwPosition& rPos );
44     void RestoreDontExpandItems( const SwPosition& rPos );
45 
46 };
47 
48 class SwAutoCorrDoc final : public SvxAutoCorrDoc
49 {
50     SwEditShell& m_rEditSh;
51     SwPaM& m_rCursor;
52     std::unique_ptr<SwNodeIndex> m_pIndex;
53     int m_nEndUndoCounter;
54     bool    m_bUndoIdInitialized;
55 
56     void DeleteSel( SwPaM& rDelPam );
57     void DeleteSelImpl(SwPaM & rDelPam);
58 
59 public:
60     SwAutoCorrDoc( SwEditShell& rEditShell, SwPaM& rPam, sal_Unicode cIns = 0 );
61     virtual ~SwAutoCorrDoc() override;
62 
63     virtual bool Delete( sal_Int32 nStt, sal_Int32 nEnd ) override;
64     virtual bool Insert( sal_Int32 nPos, const OUString& rText ) override;
65     virtual bool Replace( sal_Int32 nPos, const OUString& rText ) override;
66     virtual bool ReplaceRange( sal_Int32 nPos, sal_Int32 nLen, const OUString& rText ) override;
67 
68     virtual void SetAttr( sal_Int32 nStt, sal_Int32 nEnd, sal_uInt16 nSlotId,
69                             SfxPoolItem& ) override;
70 
71     virtual bool SetINetAttr( sal_Int32 nStt, sal_Int32 nEnd, const OUString& rURL ) override;
72 
73     // return text of a previous paragraph
74     // If it does not exist or if there is nothing before, return blank.
75     //  - true:  paragraph before "normal" insertion position
76     //  - false: paragraph in that the corrected word was inserted
77     //               (does not need to be the same paragraph)
78     virtual OUString const* GetPrevPara(bool bAtNormalPos) override;
79 
80     virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
81                                   SvxAutoCorrect& rACorrect,
82                                   OUString* pPara ) override;
83     virtual bool TransliterateRTLWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
84                                   bool bApply = false ) override;
85 
86     // Will be called after swapping characters by the functions
87     //  - FnCapitalStartWord and
88     //  - FnCapitalStartSentence.
89     // Afterwards the words can be added into exception list if needed.
90     virtual void SaveCpltSttWord( ACFlags nFlag, sal_Int32 nPos,
91                                     const OUString& rExceptWord, sal_Unicode cChar ) override;
92     virtual LanguageType GetLanguage( sal_Int32 nPos ) const override;
93 };
94 
95 class SwAutoCorrExceptWord
96 {
97     OUString m_sWord;
98     sal_uLong m_nNode;
99     ACFlags m_nFlags;
100     sal_Int32 m_nContent;
101     sal_Unicode m_cChar;
102     LanguageType m_eLanguage;
103     bool m_bDeleted;
104 
105 public:
SwAutoCorrExceptWord(ACFlags nAFlags,sal_uLong nNd,sal_Int32 nContent,const OUString & rWord,sal_Unicode cChr,LanguageType eLang)106     SwAutoCorrExceptWord(ACFlags nAFlags, sal_uLong nNd, sal_Int32 nContent,
107                          const OUString& rWord, sal_Unicode cChr,
108                          LanguageType eLang)
109         : m_sWord(rWord), m_nNode(nNd), m_nFlags(nAFlags), m_nContent(nContent),
110           m_cChar(cChr), m_eLanguage(eLang), m_bDeleted(false)
111     {}
112 
IsDeleted() const113     bool IsDeleted() const { return m_bDeleted; }
114     void CheckChar(const SwPosition& rPos, sal_Unicode cChar);
115     bool CheckDelChar(const SwPosition& rPos);
116 };
117 
118 #endif
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
121