Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/inc/spelleng.hxx
Line
Count
Source
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
#pragma once
20
21
#include <editutil.hxx>
22
#include "selectionstate.hxx"
23
#include "spellparam.hxx"
24
25
class ScViewData;
26
class ScDocShell;
27
class ScDocument;
28
class SfxItemPool;
29
30
namespace weld { class Widget; }
31
32
/** Base class for special type of edit engines, i.e. for spell checker and text conversion. */
33
class ScConversionEngineBase : public ScEditEngineDefaulter
34
{
35
public:
36
    explicit            ScConversionEngineBase(
37
                            SfxItemPool* pEnginePool, ScViewData& rViewData,
38
                            ScDocument* pUndoDoc, ScDocument* pRedoDoc );
39
40
    virtual             ~ScConversionEngineBase() override;
41
42
    /** Derived classes implement to convert all cells in the selection or sheet. */
43
    virtual void        ConvertAll(weld::Widget* pDialogParent, EditView& rEditView) = 0;
44
45
    /** Returns true, if at least one cell has been modified. */
46
0
    bool         IsAnyModified() const { return mbIsAnyModified; }
47
    /** Returns true, if the entire document/selection has been finished. */
48
0
    bool         IsFinished() const { return mbFinished; }
49
50
protected:
51
    /** Implementation of cell iteration. Finds a cell that needs conversion.
52
        @return  true = Current cell needs conversion (i.e. spelling error found). */
53
    bool                FindNextConversionCell();
54
    /** Restores the initial cursor position. */
55
    void                RestoreCursorPos();
56
57
    /** Derived classes return, if the current text needs conversion (i.e. spelling error found).
58
        @return  true = Current edit text needs conversion. */
59
    virtual bool        NeedsConversion() = 0;
60
61
    /** Derived classes may show a query box that asks whether to restart at top of the sheet.
62
        @descr  Default here is no dialog and restart always.
63
        @return  true = Restart at top, false = Stop the conversion. */
64
    virtual bool        ShowTableWrapDialog();
65
    /** Derived classes may show a message box stating that the conversion is finished.
66
        @descr  Default here is no dialog. */
67
    virtual void        ShowFinishDialog();
68
69
private:
70
    /** Fills the edit engine from a document cell. */
71
    void                FillFromCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
72
73
protected:  // for usage in derived classes
74
    ScViewData&         mrViewData;
75
    ScDocShell&         mrDocShell;
76
    ScDocument&         mrDoc;
77
78
private:
79
    ScSelectionState    maSelState;         /// Selection data of the document.
80
    ScDocument*         mpUndoDoc;          /// Document stores all old cells for UNDO action.
81
    ScDocument*         mpRedoDoc;          /// Document stores all new cells for REDO action.
82
    LanguageType        meCurrLang;         /// Current cell language.
83
    SCCOL               mnStartCol;         /// Initial column index.
84
    SCROW               mnStartRow;         /// Initial row index.
85
    SCTAB               mnStartTab;         /// Initial sheet index.
86
    SCCOL               mnCurrCol;          /// Current column index.
87
    SCROW               mnCurrRow;          /// Current row index.
88
    bool                mbIsAnyModified;    /// true = At least one cell has been changed.
89
    bool                mbInitialState;     /// true = Not searched for a cell yet.
90
    bool                mbWrappedInTable;   /// true = Already restarted at top of the sheet.
91
    bool                mbFinished;         /// true = Entire document/selection finished.
92
};
93
94
/** Edit engine for spell checking. */
95
class ScSpellingEngine : public ScConversionEngineBase
96
{
97
public:
98
    explicit            ScSpellingEngine(
99
                            SfxItemPool* pEnginePool,
100
                            ScViewData& rViewData,
101
                            ScDocument* pUndoDoc,
102
                            ScDocument* pRedoDoc,
103
                            css::uno::Reference< css::linguistic2::XSpellChecker1 > const & xSpeller );
104
105
    /** Checks spelling of all cells in the selection or sheet. */
106
    virtual void        ConvertAll(weld::Widget* pDialogParent, EditView& rEditView) override;
107
108
protected:
109
    /** Callback from edit engine to check the next cell. */
110
    virtual bool        SpellNextDocument() override;
111
112
    /** Returns true, if the current text contains a spelling error. */
113
    virtual bool        NeedsConversion() override;
114
115
    /** Show a query box that asks whether to restart at top of the sheet.
116
        @return  true = Restart at top, false = Stop the conversion. */
117
    virtual bool        ShowTableWrapDialog() override;
118
    /** Show a message box stating that spell checking is finished. */
119
    virtual void        ShowFinishDialog() override;
120
121
private:
122
    /** Returns the spelling dialog if it is open. */
123
    weld::Widget*       GetDialogParent();
124
};
125
126
/** Edit engine for text conversion. */
127
class ScTextConversionEngine : public ScConversionEngineBase
128
{
129
public:
130
    explicit            ScTextConversionEngine(
131
                            SfxItemPool* pEnginePool,
132
                            ScViewData& rViewData,
133
                            ScConversionParam aConvParam,
134
                            ScDocument* pUndoDoc,
135
                            ScDocument* pRedoDoc );
136
137
    /** Converts all cells in the selection or sheet according to set language. */
138
    virtual void        ConvertAll(weld::Widget* pDialogParent, EditView& rEditView) override;
139
140
protected:
141
    /** Callback from edit engine to convert the next cell. */
142
    virtual bool        ConvertNextDocument() override;
143
144
    /** Returns true, if the current text contains text to convert. */
145
    virtual bool        NeedsConversion() override;
146
147
private:
148
    ScConversionParam   maConvParam;        /// Conversion parameters.
149
};
150
151
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */