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