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 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XSpellChecker1
> XSpellCheckerRef
;
99 explicit ScSpellingEngine(
100 SfxItemPool
* pEnginePool
,
101 ScViewData
& rViewData
,
102 ScDocument
* pUndoDoc
,
103 ScDocument
* pRedoDoc
,
104 XSpellCheckerRef xSpeller
);
106 /** Checks spelling of all cells in the selection or sheet. */
107 virtual void ConvertAll( EditView
& rEditView
) SAL_OVERRIDE
;
110 /** Callback from edit engine to check the next cell. */
111 virtual bool SpellNextDocument() SAL_OVERRIDE
;
113 /** Returns true, if the current text contains a spelling error. */
114 virtual bool NeedsConversion() SAL_OVERRIDE
;
116 /** Show a query box that asks whether to restart at top of the sheet.
117 @return true = Restart at top, false = Stop the conversion. */
118 virtual bool ShowTableWrapDialog() SAL_OVERRIDE
;
119 /** Show a message box stating that spell checking is finished. */
120 virtual void ShowFinishDialog() SAL_OVERRIDE
;
123 /** Returns the spelling dialog if it is open. */
124 vcl::Window
* GetDialogParent();
127 /** Edit engine for text conversion. */
128 class ScTextConversionEngine
: public ScConversionEngineBase
131 explicit ScTextConversionEngine(
132 SfxItemPool
* pEnginePool
,
133 ScViewData
& rViewData
,
134 const ScConversionParam
& rConvParam
,
135 ScDocument
* pUndoDoc
,
136 ScDocument
* pRedoDoc
);
138 /** Converts all cells in the selection or sheet according to set language. */
139 virtual void ConvertAll( EditView
& rEditView
) SAL_OVERRIDE
;
142 /** Callback from edit engine to convert the next cell. */
143 virtual bool ConvertNextDocument() SAL_OVERRIDE
;
145 /** Returns true, if the current text contains text to convert. */
146 virtual bool NeedsConversion() SAL_OVERRIDE
;
149 ScConversionParam maConvParam
; /// Conversion parameters.
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */