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