1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: spelleng.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef SC_SPELLENG_HXX
31 #define SC_SPELLENG_HXX
33 #include "editutil.hxx"
34 #include "selectionstate.hxx"
35 #include "spellparam.hxx"
42 // ============================================================================
44 /** Base class for special type of edit engines, i.e. for spell checker and text conversion. */
45 class ScConversionEngineBase
: public ScEditEngineDefaulter
48 explicit ScConversionEngineBase(
49 SfxItemPool
* pEnginePool
, ScViewData
& rViewData
,
50 ScDocument
* pUndoDoc
, ScDocument
* pRedoDoc
);
52 virtual ~ScConversionEngineBase();
54 /** Derived classes implement to convert all cells in the selection or sheet. */
55 virtual void ConvertAll( EditView
& rEditView
) = 0;
57 /** Returns true, if at least one cell has been modified. */
58 inline bool IsAnyModified() const { return mbIsAnyModified
; }
59 /** Returns true, if the entire document/selection has been finished. */
60 inline bool IsFinished() const { return mbFinished
; }
63 /** Implementation of cell iteration. Finds a cell that needs conversion.
64 @return true = Current cell needs conversion (i.e. spelling error found). */
65 bool FindNextConversionCell();
66 /** Restores the initial cursor position. */
67 void RestoreCursorPos();
69 /** Derived classes return, if the current text needs conversion (i.e. spelling error found).
70 @return true = Current edit text needs conversion. */
71 virtual bool NeedsConversion() = 0;
73 /** Derived classes may show a query box that asks whether to restart at top of the sheet.
74 @descr Default here is no dialog and restart always.
75 @return true = Restart at top, false = Stop the conversion. */
76 virtual bool ShowTableWrapDialog();
77 /** Derived classes may show a message box stating that the conversion is finished.
78 @descr Default here is no dialog. */
79 virtual void ShowFinishDialog();
82 /** Fills the edit engine from a document cell. */
83 void FillFromCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
85 protected: // for usage in derived classes
86 ScViewData
& mrViewData
;
87 ScDocShell
& mrDocShell
;
91 ScSelectionState maSelState
; /// Selection data of the document.
92 ScDocument
* mpUndoDoc
; /// Document stores all old cells for UNDO action.
93 ScDocument
* mpRedoDoc
; /// Document stores all new cells for REDO action.
94 LanguageType meCurrLang
; /// Current cell language.
95 SCCOL mnStartCol
; /// Initial column index.
96 SCROW mnStartRow
; /// Initial row index.
97 SCTAB mnStartTab
; /// Initial sheet index.
98 SCCOL mnCurrCol
; /// Current column index.
99 SCROW mnCurrRow
; /// Current row index.
100 bool mbIsAnyModified
; /// true = At least one cell has been changed.
101 bool mbInitialState
; /// true = Not searched for a cell yet.
102 bool mbWrappedInTable
; /// true = Already restarted at top of the sheet.
103 bool mbFinished
; /// true = Entire document/selection finished.
106 // ============================================================================
108 /** Edit engine for spell checking. */
109 class ScSpellingEngine
: public ScConversionEngineBase
112 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XSpellChecker1
> XSpellCheckerRef
;
114 explicit ScSpellingEngine(
115 SfxItemPool
* pEnginePool
,
116 ScViewData
& rViewData
,
117 ScDocument
* pUndoDoc
,
118 ScDocument
* pRedoDoc
,
119 XSpellCheckerRef xSpeller
);
121 /** Checks spelling of all cells in the selection or sheet. */
122 virtual void ConvertAll( EditView
& rEditView
);
125 /** Callback from edit engine to check the next cell. */
126 virtual BOOL
SpellNextDocument();
128 /** Returns true, if the current text contains a spelling error. */
129 virtual bool NeedsConversion();
131 /** Show a query box that asks whether to restart at top of the sheet.
132 @return true = Restart at top, false = Stop the conversion. */
133 virtual bool ShowTableWrapDialog();
134 /** Show a message box stating that spell checking is finished. */
135 virtual void ShowFinishDialog();
138 /** Returns the spelling dialog if it is open. */
139 Window
* GetDialogParent();
142 // ============================================================================
144 /** Edit engine for text conversion. */
145 class ScTextConversionEngine
: public ScConversionEngineBase
148 explicit ScTextConversionEngine(
149 SfxItemPool
* pEnginePool
,
150 ScViewData
& rViewData
,
151 const ScConversionParam
& rConvParam
,
152 ScDocument
* pUndoDoc
,
153 ScDocument
* pRedoDoc
);
155 /** Converts all cells in the selection or sheet according to set language. */
156 virtual void ConvertAll( EditView
& rEditView
);
159 /** Callback from edit engine to convert the next cell. */
160 virtual BOOL
ConvertNextDocument();
162 /** Returns true, if the current text contains text to convert. */
163 virtual bool NeedsConversion();
166 ScConversionParam maConvParam
; /// Conversion parameters.
169 // ============================================================================