tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / inputhdl.hxx
blob3067dd819397c665e83a323eecb3425f2e25e0b1
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 .
20 #pragma once
22 #include <global.hxx>
23 #include <address.hxx>
24 #include <tools/solar.h>
25 #include <typedstrdata.hxx>
27 #include <tools/fract.hxx>
28 #include <tools/gen.hxx>
29 #include <tools/link.hxx>
30 #include <vcl/vclptr.hxx>
31 #include <editeng/svxenum.hxx>
32 #include "viewdata.hxx"
34 #include <set>
35 #include <memory>
36 #include <vector>
38 class ScDocument;
39 class ScTabViewShell;
40 class ScInputWindow;
41 class ScPatternAttr;
42 class ScEditEngineDefaulter;
43 class EditView;
44 class EditTextObject;
45 class ScInputHdlState;
46 class ScRangeFindList;
47 class Timer;
48 class KeyEvent;
49 class CommandEvent;
50 class VclWindowEvent;
51 namespace vcl { class Window; }
52 struct ReferenceMark;
53 struct ESelection;
55 // ScInputHandler
57 class ScInputHandler final
59 private:
60 VclPtr<ScInputWindow> pInputWin;
62 std::unique_ptr<ScEditEngineDefaulter> mpEditEngine; ///< Edited data in the sheet (when the user clicks into the sheet, and starts writing there).
63 EditView* pTableView; // associated active EditView
64 EditView* pTopView; // EditView in the input row
66 std::unique_ptr<ScTypedCaseStrSet> pColumnData;
67 std::unique_ptr<ScTypedCaseStrSet> pFormulaData;
68 std::unique_ptr<ScTypedCaseStrSet> pFormulaDataPara;
69 ScTypedCaseStrSet::const_iterator miAutoPosColumn;
70 ScTypedCaseStrSet::const_iterator miAutoPosFormula;
71 std::set<sal_Unicode> maFormulaChar;
73 VclPtr<vcl::Window> pTipVisibleParent;
74 void* nTipVisible;
75 VclPtr<vcl::Window> pTipVisibleSecParent;
76 void* nTipVisibleSec;
77 OUString aManualTip;
78 OUString aAutoSearch;
80 OUString aCurrentText;
82 OUString aFormText; // for autopilot function
83 sal_Int32 nFormSelStart; // Selection for autopilot function
84 sal_Int32 nFormSelEnd;
86 sal_Unicode nCellPercentFormatDecSep; // 0:= no percent format, else which decimal separator
88 sal_uInt16 nAutoPar; // autom.parentheses than can be overwritten
90 ScAddress aCursorPos;
91 ScInputMode eMode;
92 bool bUseTab:1; // Scrolling possible
93 bool bTextValid:1; // Text is not in edit engine
94 bool bModified:1;
95 bool bSelIsRef:1;
96 bool bFormulaMode:1;
97 bool bInRangeUpdate:1;
98 bool bParenthesisShown:1;
99 bool bCreatingFuncView:1;
100 bool bInEnterHandler:1;
101 bool bCommandErrorShown:1;
102 bool bInOwnChange:1;
104 bool bProtected:1;
105 bool bLastIsSymbol:1;
106 bool mbDocumentDisposing:1;
107 /// To indicate if there is a partial prefix completion.
108 bool mbPartialPrefix:1;
109 bool mbEditingExistingContent:1;
111 sal_uLong nValidation;
112 SvxCellHorJustify eAttrAdjust;
114 Fraction aScaleX; // for ref MapMode
115 Fraction aScaleY;
117 ScTabViewShell* pRefViewSh;
118 ScTabViewShell* pActiveViewSh;
120 const ScPatternAttr* pLastPattern;
121 std::unique_ptr<SfxItemSet>
122 pEditDefaults;
124 std::unique_ptr<ScInputHdlState>
125 pLastState;
126 std::unique_ptr<Timer> pDelayTimer;
128 std::unique_ptr<ScRangeFindList>
129 pRangeFindList;
131 private:
132 void UpdateActiveView();
133 void SyncViews( const EditView* pSourceView = nullptr );
135 * @param cTyped typed character. If 0, look at existing document content
136 * for text or number.
137 * @param bInputActivated true if the cell input mode is activated (via
138 * F2), false otherwise.
139 * @param pTopEngine top window input line EditEngine. If not nullptr then
140 * some default attributes are merged to it from the
141 * table EditEngine.
142 * @return true if the new edit mode has been started.
144 bool StartTable( sal_Unicode cTyped, bool bFromCommand, bool bInputActivated,
145 ScEditEngineDefaulter* pTopEngine );
146 void RemoveSelection();
147 bool StartsLikeFormula( std::u16string_view rStr ) const;
148 void UpdateFormulaMode();
149 static void InvalidateAttribs();
150 void ImplCreateEditEngine();
151 DECL_LINK( DelayTimer, Timer*, void );
152 void GetColData();
153 void UseColData();
154 void NextAutoEntry( bool bBack );
155 void UpdateAdjust( sal_Unicode cTyped );
156 void GetFormulaData();
157 void UseFormulaData();
158 void NextFormulaEntry( bool bBack );
159 void PasteFunctionData();
160 void PasteManualTip();
161 EditView* GetFuncEditView();
162 void RemoveAdjust();
163 void RemoveRangeFinder();
164 void DeleteRangeFinder();
165 void UpdateParenthesis();
166 void UpdateAutoCorrFlag();
167 void ResetAutoPar();
168 void AutoParAdded();
169 bool CursorAtClosingPar();
170 void SkipClosingPar();
171 bool GetFuncName( OUString& aStart, OUString& aResult ); // fdo75264
172 void ShowArgumentsTip( OUString& rSelText );
173 DECL_LINK( ModifyHdl, LinkParamNone*, void );
174 DECL_LINK( ShowHideTipVisibleParentListener, VclWindowEvent&, void );
175 DECL_LINK( ShowHideTipVisibleSecParentListener, VclWindowEvent&, void );
177 public:
178 ScInputHandler(const ScInputHandler&) = delete;
179 const ScInputHandler& operator=(const ScInputHandler&) = delete;
181 ScInputHandler();
182 ~ScInputHandler();
184 void SetMode( ScInputMode eNewMode, const OUString* pInitText = nullptr,
185 ScEditEngineDefaulter* pTopEngine = nullptr );
186 bool IsInputMode() const { return (eMode != SC_INPUT_NONE); }
187 bool IsEditMode() const { return (eMode != SC_INPUT_NONE &&
188 eMode != SC_INPUT_TYPE); }
189 bool IsTopMode() const { return (eMode == SC_INPUT_TOP); }
191 const OUString& GetEditString();
192 const OUString& GetFormString() const { return aFormText; }
194 const ScAddress& GetCursorPos() const { return aCursorPos; }
196 bool GetTextAndFields( ScEditEngineDefaulter& rDestEngine );
197 void MergeLanguageAttributes( ScEditEngineDefaulter& rDestEngine ) const;
199 bool KeyInput( const KeyEvent& rKEvt, bool bStartEdit );
200 void EnterHandler( ScEnterMode nBlockMode = ScEnterMode::NORMAL, bool bBeforeSavingInLOK = false );
201 void CancelHandler();
202 void SetReference( const ScRange& rRef, const ScDocument& rDoc );
203 void AddRefEntry();
205 void InputCommand( const CommandEvent& rCEvt );
207 OUString GetSurroundingText();
208 Selection GetSurroundingTextSelection();
209 bool DeleteSurroundingText(const Selection& rSelection);
211 void InsertFunction( const OUString& rFuncName, bool bAddPar = true );
212 void ClearText();
214 void InputSelection( const EditView* pView );
215 void InputChanged( const EditView* pView, bool bFromNotify );
217 void ViewShellGone(const ScTabViewShell* pViewSh);
218 void SetRefViewShell(ScTabViewShell* pRefVsh) {pRefViewSh=pRefVsh;}
220 void NotifyChange( const ScInputHdlState* pState, bool bForce = false,
221 ScTabViewShell* pSourceSh = nullptr,
222 bool bStopEditing = true);
223 void UpdateCellAdjust( SvxCellHorJustify eJust );
225 void ResetDelayTimer(); //BugId 54702
227 void HideTip();
228 void HideTipBelow();
229 void ShowTipCursor();
230 void ShowTip( const OUString& rText ); // at Cursor
231 void ShowTipBelow( const OUString& rText );
232 void ShowFuncList( const ::std::vector< OUString > & rFuncStrVec );
234 void SetRefScale( const Fraction& rX, const Fraction& rY );
235 void UpdateRefDevice();
237 EditView* GetActiveView();
238 EditView* GetTableView() { return pTableView; }
239 EditView* GetTopView() { return pTopView; }
241 bool DataChanging( sal_Unicode cTyped = 0, bool bFromCommand = false );
242 void DataChanged( bool bFromTopNotify = false, bool bSetModified = true );
244 bool TakesReturn() const { return ( nTipVisible != nullptr ); }
246 void SetModified() { bModified = true; }
248 bool GetSelIsRef() const { return bSelIsRef; }
249 void SetSelIsRef(bool bSet) { bSelIsRef = bSet; }
251 void ShowRefFrame();
253 ScRangeFindList* GetRangeFindList() { return pRangeFindList.get(); }
255 void UpdateRange( sal_uInt16 nIndex, const ScRange& rNew );
257 // Communication with the autopilot function
258 void InputGetSelection ( sal_Int32& rStart, sal_Int32& rEnd );
259 void InputSetSelection ( sal_Int32 nStart, sal_Int32 nEnd );
260 void InputReplaceSelection ( std::u16string_view aStr );
261 void InputTurnOffWinEngine();
263 bool IsFormulaMode() const { return bFormulaMode; }
264 ScInputWindow* GetInputWindow() { return pInputWin; }
265 void SetInputWindow( ScInputWindow* pNew );
266 void StopInputWinEngine( bool bAll );
268 bool IsInEnterHandler() const { return bInEnterHandler; }
269 bool IsInOwnChange() const { return bInOwnChange; }
271 /// Returns true if there is a partial autocomplete suggestion.
272 bool HasPartialComplete() const { return mbPartialPrefix; };
274 bool IsModalMode( const SfxObjectShell* pDocSh );
276 void ForgetLastPattern();
278 void UpdateSpellSettings( bool bFromStartTab = false );
280 void FormulaPreview();
282 Size GetTextSize(); // in 1/100mm
284 // actually private, public for SID_INPUT_SUM
285 void InitRangeFinder(const OUString& rFormula);
287 void UpdateLokReferenceMarks();
288 static void SendReferenceMarks( const SfxViewShell* pViewShell,
289 const std::vector<ReferenceMark>& rReferenceMarks );
291 void SetDocumentDisposing( bool b );
293 static ReferenceMark GetReferenceMark( const ScViewData& rViewData, ScDocShell* pDocSh,
294 tools::Long nX1, tools::Long nX2, tools::Long nY1, tools::Long nY2,
295 tools::Long nTab, const Color& rColor );
297 void LOKPasteFunctionData(const OUString& rFunctionName);
300 // ScInputHdlState
302 class ScInputHdlState
304 friend class ScInputHandler;
306 public:
307 ScInputHdlState( const ScAddress& rCurPos,
308 const ScAddress& rStartPos,
309 const ScAddress& rEndPos,
310 OUString aString,
311 const EditTextObject* pData );
312 ScInputHdlState( const ScInputHdlState& rCpy );
313 ~ScInputHdlState();
315 ScInputHdlState& operator= ( const ScInputHdlState& r );
316 bool operator==( const ScInputHdlState& r ) const;
318 const ScAddress& GetPos() const { return aCursorPos; }
319 const ScAddress& GetStartPos() const { return aStartPos; }
320 const ScAddress& GetEndPos() const { return aEndPos; }
321 const OUString& GetString() const { return aString; }
322 const EditTextObject* GetEditData() const { return pEditData.get(); }
324 private:
325 ScAddress aCursorPos;
326 ScAddress aStartPos;
327 ScAddress aEndPos;
328 OUString aString;
329 std::unique_ptr<EditTextObject> pEditData;
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */