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 SC_SPELLENG_HXX
20 #define SC_SPELLENG_HXX
22 #include "editutil.hxx"
23 #include "selectionstate.hxx"
24 #include "spellparam.hxx"
31 // ============================================================================
33 /** Base class for special type of edit engines, i.e. for spell checker and text conversion. */
34 class ScConversionEngineBase
: public ScEditEngineDefaulter
37 explicit ScConversionEngineBase(
38 SfxItemPool
* pEnginePool
, ScViewData
& rViewData
,
39 ScDocument
* pUndoDoc
, ScDocument
* pRedoDoc
);
41 virtual ~ScConversionEngineBase();
43 /** Derived classes implement to convert all cells in the selection or sheet. */
44 virtual void ConvertAll( EditView
& rEditView
) = 0;
46 /** Returns true, if at least one cell has been modified. */
47 inline bool IsAnyModified() const { return mbIsAnyModified
; }
48 /** Returns true, if the entire document/selection has been finished. */
49 inline bool IsFinished() const { return mbFinished
; }
52 /** Implementation of cell iteration. Finds a cell that needs conversion.
53 @return true = Current cell needs conversion (i.e. spelling error found). */
54 bool FindNextConversionCell();
55 /** Restores the initial cursor position. */
56 void RestoreCursorPos();
58 /** Derived classes return, if the current text needs conversion (i.e. spelling error found).
59 @return true = Current edit text needs conversion. */
60 virtual bool NeedsConversion() = 0;
62 /** Derived classes may show a query box that asks whether to restart at top of the sheet.
63 @descr Default here is no dialog and restart always.
64 @return true = Restart at top, false = Stop the conversion. */
65 virtual bool ShowTableWrapDialog();
66 /** Derived classes may show a message box stating that the conversion is finished.
67 @descr Default here is no dialog. */
68 virtual void ShowFinishDialog();
71 /** Fills the edit engine from a document cell. */
72 void FillFromCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
74 protected: // for usage in derived classes
75 ScViewData
& mrViewData
;
76 ScDocShell
& mrDocShell
;
80 ScSelectionState maSelState
; /// Selection data of the document.
81 ScDocument
* mpUndoDoc
; /// Document stores all old cells for UNDO action.
82 ScDocument
* mpRedoDoc
; /// Document stores all new cells for REDO action.
83 LanguageType meCurrLang
; /// Current cell language.
84 SCCOL mnStartCol
; /// Initial column index.
85 SCROW mnStartRow
; /// Initial row index.
86 SCTAB mnStartTab
; /// Initial sheet index.
87 SCCOL mnCurrCol
; /// Current column index.
88 SCROW mnCurrRow
; /// Current row index.
89 bool mbIsAnyModified
; /// true = At least one cell has been changed.
90 bool mbInitialState
; /// true = Not searched for a cell yet.
91 bool mbWrappedInTable
; /// true = Already restarted at top of the sheet.
92 bool mbFinished
; /// true = Entire document/selection finished.
95 // ============================================================================
97 /** Edit engine for spell checking. */
98 class ScSpellingEngine
: public ScConversionEngineBase
101 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XSpellChecker1
> XSpellCheckerRef
;
103 explicit ScSpellingEngine(
104 SfxItemPool
* pEnginePool
,
105 ScViewData
& rViewData
,
106 ScDocument
* pUndoDoc
,
107 ScDocument
* pRedoDoc
,
108 XSpellCheckerRef xSpeller
);
110 /** Checks spelling of all cells in the selection or sheet. */
111 virtual void ConvertAll( EditView
& rEditView
);
114 /** Callback from edit engine to check the next cell. */
115 virtual sal_Bool
SpellNextDocument();
117 /** Returns true, if the current text contains a spelling error. */
118 virtual bool NeedsConversion();
120 /** Show a query box that asks whether to restart at top of the sheet.
121 @return true = Restart at top, false = Stop the conversion. */
122 virtual bool ShowTableWrapDialog();
123 /** Show a message box stating that spell checking is finished. */
124 virtual void ShowFinishDialog();
127 /** Returns the spelling dialog if it is open. */
128 Window
* GetDialogParent();
131 // ============================================================================
133 /** Edit engine for text conversion. */
134 class ScTextConversionEngine
: public ScConversionEngineBase
137 explicit ScTextConversionEngine(
138 SfxItemPool
* pEnginePool
,
139 ScViewData
& rViewData
,
140 const ScConversionParam
& rConvParam
,
141 ScDocument
* pUndoDoc
,
142 ScDocument
* pRedoDoc
);
144 /** Converts all cells in the selection or sheet according to set language. */
145 virtual void ConvertAll( EditView
& rEditView
);
148 /** Callback from edit engine to convert the next cell. */
149 virtual sal_Bool
ConvertNextDocument();
151 /** Returns true, if the current text contains text to convert. */
152 virtual bool NeedsConversion();
155 ScConversionParam maConvParam
; /// Conversion parameters.
158 // ============================================================================
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */