xref: /aoo42x/main/sc/source/ui/inc/spelleng.hxx (revision 38d50f7b)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*38d50f7bSAndrew Rist  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19*38d50f7bSAndrew Rist  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir #ifndef SC_SPELLENG_HXX
24cdf0e10cSrcweir #define SC_SPELLENG_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "editutil.hxx"
27cdf0e10cSrcweir #include "selectionstate.hxx"
28cdf0e10cSrcweir #include "spellparam.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir class ScViewData;
31cdf0e10cSrcweir class ScDocShell;
32cdf0e10cSrcweir class ScDocument;
33cdf0e10cSrcweir class SfxItemPool;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // ============================================================================
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /** Base class for special type of edit engines, i.e. for spell checker and text conversion. */
38cdf0e10cSrcweir class ScConversionEngineBase : public ScEditEngineDefaulter
39cdf0e10cSrcweir {
40cdf0e10cSrcweir public:
41cdf0e10cSrcweir     explicit            ScConversionEngineBase(
42cdf0e10cSrcweir                             SfxItemPool* pEnginePool, ScViewData& rViewData,
43cdf0e10cSrcweir                             ScDocument* pUndoDoc, ScDocument* pRedoDoc );
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     virtual             ~ScConversionEngineBase();
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     /** Derived classes implement to convert all cells in the selection or sheet. */
48cdf0e10cSrcweir     virtual void        ConvertAll( EditView& rEditView ) = 0;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     /** Returns true, if at least one cell has been modified. */
IsAnyModified() const51cdf0e10cSrcweir     inline bool         IsAnyModified() const { return mbIsAnyModified; }
52cdf0e10cSrcweir     /** Returns true, if the entire document/selection has been finished. */
IsFinished() const53cdf0e10cSrcweir     inline bool         IsFinished() const { return mbFinished; }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir protected:
56cdf0e10cSrcweir     /** Implementation of cell iteration. Finds a cell that needs conversion.
57cdf0e10cSrcweir         @return  true = Current cell needs conversion (i.e. spelling error found). */
58cdf0e10cSrcweir     bool                FindNextConversionCell();
59cdf0e10cSrcweir     /** Restores the initial cursor position. */
60cdf0e10cSrcweir     void                RestoreCursorPos();
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /** Derived classes return, if the current text needs conversion (i.e. spelling error found).
63cdf0e10cSrcweir         @return  true = Current edit text needs conversion. */
64cdf0e10cSrcweir     virtual bool        NeedsConversion() = 0;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /** Derived classes may show a query box that asks whether to restart at top of the sheet.
67cdf0e10cSrcweir         @descr  Default here is no dialog and restart always.
68cdf0e10cSrcweir         @return  true = Restart at top, false = Stop the conversion. */
69cdf0e10cSrcweir     virtual bool        ShowTableWrapDialog();
70cdf0e10cSrcweir     /** Derived classes may show a message box stating that the conversion is finished.
71cdf0e10cSrcweir         @descr  Default here is no dialog. */
72cdf0e10cSrcweir     virtual void        ShowFinishDialog();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir private:
75cdf0e10cSrcweir     /** Fills the edit engine from a document cell. */
76cdf0e10cSrcweir     void                FillFromCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir protected:  // for usage in derived classes
79cdf0e10cSrcweir     ScViewData&         mrViewData;
80cdf0e10cSrcweir     ScDocShell&         mrDocShell;
81cdf0e10cSrcweir     ScDocument&         mrDoc;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir private:
84cdf0e10cSrcweir     ScSelectionState    maSelState;         /// Selection data of the document.
85cdf0e10cSrcweir     ScDocument*         mpUndoDoc;          /// Document stores all old cells for UNDO action.
86cdf0e10cSrcweir     ScDocument*         mpRedoDoc;          /// Document stores all new cells for REDO action.
87cdf0e10cSrcweir     LanguageType        meCurrLang;         /// Current cell language.
88cdf0e10cSrcweir     SCCOL               mnStartCol;         /// Initial column index.
89cdf0e10cSrcweir     SCROW               mnStartRow;         /// Initial row index.
90cdf0e10cSrcweir     SCTAB               mnStartTab;         /// Initial sheet index.
91cdf0e10cSrcweir     SCCOL               mnCurrCol;          /// Current column index.
92cdf0e10cSrcweir     SCROW               mnCurrRow;          /// Current row index.
93cdf0e10cSrcweir     bool                mbIsAnyModified;    /// true = At least one cell has been changed.
94cdf0e10cSrcweir     bool                mbInitialState;     /// true = Not searched for a cell yet.
95cdf0e10cSrcweir     bool                mbWrappedInTable;   /// true = Already restarted at top of the sheet.
96cdf0e10cSrcweir     bool                mbFinished;         /// true = Entire document/selection finished.
97cdf0e10cSrcweir };
98cdf0e10cSrcweir 
99cdf0e10cSrcweir // ============================================================================
100cdf0e10cSrcweir 
101cdf0e10cSrcweir /** Edit engine for spell checking. */
102cdf0e10cSrcweir class ScSpellingEngine : public ScConversionEngineBase
103cdf0e10cSrcweir {
104cdf0e10cSrcweir public:
105cdf0e10cSrcweir     typedef ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellChecker1 > XSpellCheckerRef;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     explicit            ScSpellingEngine(
108cdf0e10cSrcweir                             SfxItemPool* pEnginePool,
109cdf0e10cSrcweir                             ScViewData& rViewData,
110cdf0e10cSrcweir                             ScDocument* pUndoDoc,
111cdf0e10cSrcweir                             ScDocument* pRedoDoc,
112cdf0e10cSrcweir                             XSpellCheckerRef xSpeller );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     /** Checks spelling of all cells in the selection or sheet. */
115cdf0e10cSrcweir     virtual void        ConvertAll( EditView& rEditView );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir protected:
118cdf0e10cSrcweir     /** Callback from edit engine to check the next cell. */
119cdf0e10cSrcweir     virtual sal_Bool        SpellNextDocument();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     /** Returns true, if the current text contains a spelling error. */
122cdf0e10cSrcweir     virtual bool        NeedsConversion();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     /** Show a query box that asks whether to restart at top of the sheet.
125cdf0e10cSrcweir         @return  true = Restart at top, false = Stop the conversion. */
126cdf0e10cSrcweir     virtual bool        ShowTableWrapDialog();
127cdf0e10cSrcweir     /** Show a message box stating that spell checking is finished. */
128cdf0e10cSrcweir     virtual void        ShowFinishDialog();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir private:
131cdf0e10cSrcweir     /** Returns the spelling dialog if it is open. */
132cdf0e10cSrcweir     Window*             GetDialogParent();
133cdf0e10cSrcweir };
134cdf0e10cSrcweir 
135cdf0e10cSrcweir // ============================================================================
136cdf0e10cSrcweir 
137cdf0e10cSrcweir /** Edit engine for text conversion. */
138cdf0e10cSrcweir class ScTextConversionEngine : public ScConversionEngineBase
139cdf0e10cSrcweir {
140cdf0e10cSrcweir public:
141cdf0e10cSrcweir     explicit            ScTextConversionEngine(
142cdf0e10cSrcweir                             SfxItemPool* pEnginePool,
143cdf0e10cSrcweir                             ScViewData& rViewData,
144cdf0e10cSrcweir                             const ScConversionParam& rConvParam,
145cdf0e10cSrcweir                             ScDocument* pUndoDoc,
146cdf0e10cSrcweir                             ScDocument* pRedoDoc );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     /** Converts all cells in the selection or sheet according to set language. */
149cdf0e10cSrcweir     virtual void        ConvertAll( EditView& rEditView );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir protected:
152cdf0e10cSrcweir     /** Callback from edit engine to convert the next cell. */
153cdf0e10cSrcweir     virtual sal_Bool        ConvertNextDocument();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     /** Returns true, if the current text contains text to convert. */
156cdf0e10cSrcweir     virtual bool        NeedsConversion();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir private:
159cdf0e10cSrcweir     ScConversionParam   maConvParam;        /// Conversion parameters.
160cdf0e10cSrcweir };
161cdf0e10cSrcweir 
162cdf0e10cSrcweir // ============================================================================
163cdf0e10cSrcweir 
164cdf0e10cSrcweir #endif
165cdf0e10cSrcweir 
166