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