tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / spelleng.hxx
blob98baa5c8e46a839e848760a3ddffc2a3a9efacd4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #pragma once
21 #include <editutil.hxx>
22 #include "selectionstate.hxx"
23 #include "spellparam.hxx"
25 class ScViewData;
26 class ScDocShell;
27 class ScDocument;
28 class SfxItemPool;
30 namespace weld { class Widget; }
32 /** Base class for special type of edit engines, i.e. for spell checker and text conversion. */
33 class ScConversionEngineBase : public ScEditEngineDefaulter
35 public:
36 explicit ScConversionEngineBase(
37 SfxItemPool* pEnginePool, ScViewData& rViewData,
38 ScDocument* pUndoDoc, ScDocument* pRedoDoc );
40 virtual ~ScConversionEngineBase() override;
42 /** Derived classes implement to convert all cells in the selection or sheet. */
43 virtual void ConvertAll(weld::Widget* pDialogParent, EditView& rEditView) = 0;
45 /** Returns true, if at least one cell has been modified. */
46 bool IsAnyModified() const { return mbIsAnyModified; }
47 /** Returns true, if the entire document/selection has been finished. */
48 bool IsFinished() const { return mbFinished; }
50 protected:
51 /** Implementation of cell iteration. Finds a cell that needs conversion.
52 @return true = Current cell needs conversion (i.e. spelling error found). */
53 bool FindNextConversionCell();
54 /** Restores the initial cursor position. */
55 void RestoreCursorPos();
57 /** Derived classes return, if the current text needs conversion (i.e. spelling error found).
58 @return true = Current edit text needs conversion. */
59 virtual bool NeedsConversion() = 0;
61 /** Derived classes may show a query box that asks whether to restart at top of the sheet.
62 @descr Default here is no dialog and restart always.
63 @return true = Restart at top, false = Stop the conversion. */
64 virtual bool ShowTableWrapDialog();
65 /** Derived classes may show a message box stating that the conversion is finished.
66 @descr Default here is no dialog. */
67 virtual void ShowFinishDialog();
69 private:
70 /** Fills the edit engine from a document cell. */
71 void FillFromCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
73 protected: // for usage in derived classes
74 ScViewData& mrViewData;
75 ScDocShell& mrDocShell;
76 ScDocument& mrDoc;
78 private:
79 ScSelectionState maSelState; /// Selection data of the document.
80 ScDocument* mpUndoDoc; /// Document stores all old cells for UNDO action.
81 ScDocument* mpRedoDoc; /// Document stores all new cells for REDO action.
82 LanguageType meCurrLang; /// Current cell language.
83 SCCOL mnStartCol; /// Initial column index.
84 SCROW mnStartRow; /// Initial row index.
85 SCTAB mnStartTab; /// Initial sheet index.
86 SCCOL mnCurrCol; /// Current column index.
87 SCROW mnCurrRow; /// Current row index.
88 bool mbIsAnyModified; /// true = At least one cell has been changed.
89 bool mbInitialState; /// true = Not searched for a cell yet.
90 bool mbWrappedInTable; /// true = Already restarted at top of the sheet.
91 bool mbFinished; /// true = Entire document/selection finished.
94 /** Edit engine for spell checking. */
95 class ScSpellingEngine : public ScConversionEngineBase
97 public:
98 explicit ScSpellingEngine(
99 SfxItemPool* pEnginePool,
100 ScViewData& rViewData,
101 ScDocument* pUndoDoc,
102 ScDocument* pRedoDoc,
103 css::uno::Reference< css::linguistic2::XSpellChecker1 > const & xSpeller );
105 /** Checks spelling of all cells in the selection or sheet. */
106 virtual void ConvertAll(weld::Widget* pDialogParent, EditView& rEditView) override;
108 protected:
109 /** Callback from edit engine to check the next cell. */
110 virtual bool SpellNextDocument() override;
112 /** Returns true, if the current text contains a spelling error. */
113 virtual bool NeedsConversion() override;
115 /** Show a query box that asks whether to restart at top of the sheet.
116 @return true = Restart at top, false = Stop the conversion. */
117 virtual bool ShowTableWrapDialog() override;
118 /** Show a message box stating that spell checking is finished. */
119 virtual void ShowFinishDialog() override;
121 private:
122 /** Returns the spelling dialog if it is open. */
123 weld::Widget* GetDialogParent();
126 /** Edit engine for text conversion. */
127 class ScTextConversionEngine : public ScConversionEngineBase
129 public:
130 explicit ScTextConversionEngine(
131 SfxItemPool* pEnginePool,
132 ScViewData& rViewData,
133 ScConversionParam aConvParam,
134 ScDocument* pUndoDoc,
135 ScDocument* pRedoDoc );
137 /** Converts all cells in the selection or sheet according to set language. */
138 virtual void ConvertAll(weld::Widget* pDialogParent, EditView& rEditView) override;
140 protected:
141 /** Callback from edit engine to convert the next cell. */
142 virtual bool ConvertNextDocument() override;
144 /** Returns true, if the current text contains text to convert. */
145 virtual bool NeedsConversion() override;
147 private:
148 ScConversionParam maConvParam; /// Conversion parameters.
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */