1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SC_SOURCE_UI_INC_SPELLENG_HXX
20 #define INCLUDED_SC_SOURCE_UI_INC_SPELLENG_HXX
22 #include "editutil.hxx"
23 #include "selectionstate.hxx"
24 #include "spellparam.hxx"
31 /** Base class for special type of edit engines, i.e. for spell checker and text conversion. */
32 class ScConversionEngineBase
: public ScEditEngineDefaulter
35 explicit ScConversionEngineBase(
36 SfxItemPool
* pEnginePool
, ScViewData
& rViewData
,
37 ScDocument
* pUndoDoc
, ScDocument
* pRedoDoc
);
39 virtual ~ScConversionEngineBase();
41 /** Derived classes implement to convert all cells in the selection or sheet. */
42 virtual void ConvertAll( EditView
& rEditView
) = 0;
44 /** Returns true, if at least one cell has been modified. */
45 inline bool IsAnyModified() const { return mbIsAnyModified
; }
46 /** Returns true, if the entire document/selection has been finished. */
47 inline bool IsFinished() const { return mbFinished
; }
50 /** Implementation of cell iteration. Finds a cell that needs conversion.
51 @return true = Current cell needs conversion (i.e. spelling error found). */
52 bool FindNextConversionCell();
53 /** Restores the initial cursor position. */
54 void RestoreCursorPos();
56 /** Derived classes return, if the current text needs conversion (i.e. spelling error found).
57 @return true = Current edit text needs conversion. */
58 virtual bool NeedsConversion() = 0;
60 /** Derived classes may show a query box that asks whether to restart at top of the sheet.
61 @descr Default here is no dialog and restart always.
62 @return true = Restart at top, false = Stop the conversion. */
63 virtual bool ShowTableWrapDialog();
64 /** Derived classes may show a message box stating that the conversion is finished.
65 @descr Default here is no dialog. */
66 virtual void ShowFinishDialog();
69 /** Fills the edit engine from a document cell. */
70 void FillFromCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
72 protected: // for usage in derived classes
73 ScViewData
& mrViewData
;
74 ScDocShell
& mrDocShell
;
78 ScSelectionState maSelState
; /// Selection data of the document.
79 ScDocument
* mpUndoDoc
; /// Document stores all old cells for UNDO action.
80 ScDocument
* mpRedoDoc
; /// Document stores all new cells for REDO action.
81 LanguageType meCurrLang
; /// Current cell language.
82 SCCOL mnStartCol
; /// Initial column index.
83 SCROW mnStartRow
; /// Initial row index.
84 SCTAB mnStartTab
; /// Initial sheet index.
85 SCCOL mnCurrCol
; /// Current column index.
86 SCROW mnCurrRow
; /// Current row index.
87 bool mbIsAnyModified
; /// true = At least one cell has been changed.
88 bool mbInitialState
; /// true = Not searched for a cell yet.
89 bool mbWrappedInTable
; /// true = Already restarted at top of the sheet.
90 bool mbFinished
; /// true = Entire document/selection finished.
93 /** Edit engine for spell checking. */
94 class ScSpellingEngine
: public ScConversionEngineBase
97 explicit ScSpellingEngine(
98 SfxItemPool
* pEnginePool
,
99 ScViewData
& rViewData
,
100 ScDocument
* pUndoDoc
,
101 ScDocument
* pRedoDoc
,
102 css::uno::Reference
< css::linguistic2::XSpellChecker1
> xSpeller
);
104 /** Checks spelling of all cells in the selection or sheet. */
105 virtual void ConvertAll( EditView
& rEditView
) override
;
108 /** Callback from edit engine to check the next cell. */
109 virtual bool SpellNextDocument() override
;
111 /** Returns true, if the current text contains a spelling error. */
112 virtual bool NeedsConversion() override
;
114 /** Show a query box that asks whether to restart at top of the sheet.
115 @return true = Restart at top, false = Stop the conversion. */
116 virtual bool ShowTableWrapDialog() override
;
117 /** Show a message box stating that spell checking is finished. */
118 virtual void ShowFinishDialog() override
;
121 /** Returns the spelling dialog if it is open. */
122 vcl::Window
* GetDialogParent();
125 /** Edit engine for text conversion. */
126 class ScTextConversionEngine
: public ScConversionEngineBase
129 explicit ScTextConversionEngine(
130 SfxItemPool
* pEnginePool
,
131 ScViewData
& rViewData
,
132 const ScConversionParam
& rConvParam
,
133 ScDocument
* pUndoDoc
,
134 ScDocument
* pRedoDoc
);
136 /** Converts all cells in the selection or sheet according to set language. */
137 virtual void ConvertAll( EditView
& rEditView
) override
;
140 /** Callback from edit engine to convert the next cell. */
141 virtual bool ConvertNextDocument() override
;
143 /** Returns true, if the current text contains text to convert. */
144 virtual bool NeedsConversion() override
;
147 ScConversionParam maConvParam
; /// Conversion parameters.
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */