Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/inc/inputhdl.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#pragma once
21
22
#include <global.hxx>
23
#include <address.hxx>
24
#include <tools/solar.h>
25
#include <typedstrdata.hxx>
26
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"
33
34
#include <set>
35
#include <memory>
36
#include <vector>
37
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
54
typedef std::function<void(ScTabViewShell*, TranslateId)> ErrorHdl;
55
56
//  ScInputHandler
57
58
class ScInputHandler final
59
{
60
private:
61
    VclPtr<ScInputWindow>          pInputWin;
62
63
    std::unique_ptr<ScEditEngineDefaulter> mpEditEngine;     ///< Edited data in the sheet (when the user clicks into the sheet, and starts writing there).
64
    EditView*               pTableView;                 // associated active EditView
65
    EditView*               pTopView;                   // EditView in the input row
66
67
    std::unique_ptr<ScTypedCaseStrSet> pColumnData;
68
    std::unique_ptr<ScTypedCaseStrSet> pFormulaData;
69
    std::unique_ptr<ScTypedCaseStrSet> pFormulaDataPara;
70
    ScTypedCaseStrSet::const_iterator  miAutoPosColumn;
71
    ScTypedCaseStrSet::const_iterator  miAutoPosFormula;
72
    std::set<sal_Unicode>              maFormulaChar;
73
74
    VclPtr<vcl::Window>     pTipVisibleParent;
75
    void*                   nTipVisible;
76
    VclPtr<vcl::Window>     pTipVisibleSecParent;
77
    void*                   nTipVisibleSec;
78
    OUString                aManualTip;
79
    OUString                aAutoSearch;
80
81
    OUString                aCurrentText;
82
83
    OUString                aFormText;                  // for autopilot function
84
    sal_Int32               nFormSelStart;              // Selection for autopilot function
85
    sal_Int32               nFormSelEnd;
86
87
    sal_Unicode             nCellPercentFormatDecSep;   // 0:= no percent format, else which decimal separator
88
89
    sal_uInt16              nAutoPar;                   // autom.parentheses than can be overwritten
90
91
    ScAddress               aCursorPos;
92
    ScInputMode             eMode;
93
    bool                    bUseTab:1;                    // Scrolling possible
94
    bool                    bTextValid:1;                 // Text is not in edit engine
95
    bool                    bModified:1;
96
    bool                    bSelIsRef:1;
97
    bool                    bFormulaMode:1;
98
    bool                    bInRangeUpdate:1;
99
    bool                    bParenthesisShown:1;
100
    bool                    bCreatingFuncView:1;
101
    bool                    bInEnterHandler:1;
102
    bool                    bCommandErrorShown:1;
103
    bool                    bInOwnChange:1;
104
105
    bool                    bProtected:1;
106
    bool                    bLastIsSymbol:1;
107
    bool                    mbDocumentDisposing:1;
108
    /// To indicate if there is a partial prefix completion.
109
    bool                    mbPartialPrefix:1;
110
    bool                    mbEditingExistingContent:1;
111
112
    sal_uLong                   nValidation;
113
    SvxCellHorJustify       eAttrAdjust;
114
115
    Fraction                aScaleX;                    // for ref MapMode
116
    Fraction                aScaleY;
117
118
    ScTabViewShell*         pRefViewSh;
119
    ScTabViewShell*         pActiveViewSh;
120
121
    const ScPatternAttr*    pLastPattern;
122
    std::unique_ptr<SfxItemSet>
123
                            pEditDefaults;
124
125
    std::unique_ptr<ScInputHdlState>
126
                            pLastState;
127
    std::unique_ptr<Timer>  pDelayTimer;
128
129
    std::unique_ptr<ScRangeFindList>
130
                            pRangeFindList;
131
    std::optional<ScEnterMode>
132
                            monPrevBlockMode;
133
134
private:
135
    void            UpdateActiveView();
136
    void            SyncViews( const EditView* pSourceView = nullptr );
137
    /**
138
     * @param cTyped typed character. If 0, look at existing document content
139
     *               for text or number.
140
     * @param bInputActivated true if the cell input mode is activated (via
141
     *                        F2), false otherwise.
142
     * @param pTopEngine top window input line EditEngine. If not nullptr then
143
     *                   some default attributes are merged to it from the
144
     *                   table EditEngine.
145
     * @return true if the new edit mode has been started.
146
     */
147
    bool            StartTable(sal_Unicode cTyped, bool bFromCommand, bool bInputActivated,
148
                               ScEditEngineDefaulter* pTopEngine, const ErrorHdl& errorHdl);
149
    void            RemoveSelection();
150
    bool            StartsLikeFormula( std::u16string_view rStr ) const;
151
    void            UpdateFormulaMode();
152
    static void     InvalidateAttribs();
153
    void            ImplCreateEditEngine();
154
    DECL_LINK( DelayTimer, Timer*, void );
155
    void            GetColData();
156
    void            UseColData();
157
    void            NextAutoEntry( bool bBack );
158
    void            UpdateAdjust( sal_Unicode cTyped );
159
    void            GetFormulaData();
160
    void            UseFormulaData();
161
    void            NextFormulaEntry( bool bBack );
162
    void            PasteFunctionData();
163
    void            PasteManualTip();
164
    EditView*       GetFuncEditView();
165
    void            RemoveAdjust();
166
    void            RemoveRangeFinder();
167
    void            DeleteRangeFinder();
168
    void            UpdateParenthesis();
169
    void            UpdateAutoCorrFlag();
170
    void            ResetAutoPar();
171
    void            AutoParAdded();
172
    bool            CursorAtClosingPar();
173
    void            SkipClosingPar();
174
    bool            GetFuncName( OUString& aStart, OUString& aResult );  // fdo75264
175
    void            ShowArgumentsTip( OUString& rSelText );
176
    DECL_LINK( ModifyHdl, LinkParamNone*, void );
177
    DECL_LINK( ShowHideTipVisibleParentListener, VclWindowEvent&, void );
178
    DECL_LINK( ShowHideTipVisibleSecParentListener, VclWindowEvent&, void );
179
180
public:
181
    ScInputHandler(const ScInputHandler&) = delete;
182
    const ScInputHandler& operator=(const ScInputHandler&) = delete;
183
184
                    ScInputHandler();
185
                    ~ScInputHandler();
186
187
    void            SetMode(ScInputMode eNewMode, const OUString* pInitText = nullptr,
188
                            ScEditEngineDefaulter* pTopEngine = nullptr,
189
                            const ErrorHdl& errorHdl = ScInputHandler::ErrorMessage);
190
    void            StartOrToggleEditMode();
191
0
    bool            IsInputMode() const { return (eMode != SC_INPUT_NONE); }
192
0
    bool            IsEditMode() const  { return (eMode != SC_INPUT_NONE &&
193
0
                                                  eMode != SC_INPUT_TYPE); }
194
0
    bool            IsTopMode() const   { return (eMode == SC_INPUT_TOP);  }
195
196
    const OUString& GetEditString();
197
0
    const OUString& GetFormString() const { return aFormText; }
198
199
0
    const ScAddress& GetCursorPos() const   { return aCursorPos; }
200
201
    bool            GetTextAndFields( ScEditEngineDefaulter& rDestEngine );
202
    void            MergeLanguageAttributes( ScEditEngineDefaulter& rDestEngine ) const;
203
204
    bool            KeyInput( const KeyEvent& rKEvt, bool bStartEdit );
205
    void            EnterHandler( ScEnterMode nBlockMode = ScEnterMode::NORMAL, bool bBeforeSavingInLOK = false );
206
    void            EnterHandler2(ScEnterMode nBlockMode, bool bForget, OUString aString,
207
                       const OUString& aPreAutoCorrectString);
208
    void            CancelHandler();
209
    void            SetReference( const ScRange& rRef, const ScDocument& rDoc );
210
    void            AddRefEntry();
211
212
    void            InputCommand( const CommandEvent& rCEvt );
213
214
    OUString        GetSurroundingText();
215
    Selection       GetSurroundingTextSelection();
216
    bool            DeleteSurroundingText(const Selection& rSelection);
217
218
    void            InsertFunction( const OUString& rFuncName, bool bAddPar = true );
219
    void            ClearText();
220
221
    void            InputSelection( const EditView* pView );
222
    void            InputChanged( const EditView* pView, bool bFromNotify );
223
224
    void            ViewShellGone(const ScTabViewShell* pViewSh);
225
0
    void            SetRefViewShell(ScTabViewShell* pRefVsh) {pRefViewSh=pRefVsh;}
226
227
    void            NotifyChange( const ScInputHdlState* pState, bool bForce = false,
228
                                  ScTabViewShell* pSourceSh = nullptr,
229
                                  bool bStopEditing = true);
230
    void            UpdateCellAdjust( SvxCellHorJustify eJust );
231
232
    void            ResetDelayTimer(); //BugId 54702
233
234
    void            HideTip();
235
    void            HideTipBelow();
236
    void            ShowTipCursor();
237
    void            ShowTip( const OUString& rText );     // at Cursor
238
    void            ShowTipBelow( const OUString& rText );
239
    void            ShowFuncList( const ::std::vector< OUString > & rFuncStrVec );
240
241
    void            SetRefScale( const Fraction& rX, const Fraction& rY );
242
    void            UpdateRefDevice();
243
244
    EditView*       GetActiveView();
245
0
    EditView*       GetTableView()      { return pTableView; }
246
0
    EditView*       GetTopView()        { return pTopView; }
247
248
    bool            DataChanging( sal_Unicode cTyped = 0, bool bFromCommand = false );
249
    void            DataChanged( bool bFromTopNotify = false, bool bSetModified = true );
250
251
0
    bool            TakesReturn() const     { return ( nTipVisible != nullptr ); }
252
253
0
    void            SetModified()       { bModified = true; }
254
255
0
    bool            GetSelIsRef() const     { return bSelIsRef; }
256
0
    void            SetSelIsRef(bool bSet)  { bSelIsRef = bSet; }
257
258
    void            ShowRefFrame();
259
260
0
    ScRangeFindList* GetRangeFindList()     { return pRangeFindList.get(); }
261
262
    void            UpdateRange( sal_uInt16 nIndex, const ScRange& rNew );
263
264
    // Communication with the autopilot function
265
    void            InputGetSelection       ( sal_Int32& rStart, sal_Int32& rEnd );
266
    void            InputSetSelection       ( sal_Int32 nStart, sal_Int32 nEnd );
267
    void            InputReplaceSelection   ( std::u16string_view aStr );
268
    void            InputTurnOffWinEngine();
269
270
0
    bool            IsFormulaMode() const                   { return bFormulaMode; }
271
0
    ScInputWindow*  GetInputWindow()                        { return pInputWin; }
272
    void            SetInputWindow( ScInputWindow* pNew );
273
    void            StopInputWinEngine( bool bAll );
274
275
0
    bool            IsInEnterHandler() const                { return bInEnterHandler; }
276
0
    bool            IsInOwnChange() const                   { return bInOwnChange; }
277
278
    /// Returns true if there is a partial autocomplete suggestion.
279
0
    bool            HasPartialComplete() const              { return mbPartialPrefix; };
280
281
    bool            IsModalMode( const SfxObjectShell& rDocSh );
282
283
    void            ForgetLastPattern();
284
285
    void            UpdateSpellSettings( bool bFromStartTab = false );
286
287
    void            FormulaPreview();
288
289
    Size            GetTextSize();      // in 1/100mm
290
291
                    // actually private, public for SID_INPUT_SUM
292
    void            InitRangeFinder(const OUString& rFormula);
293
294
    void            UpdateLokReferenceMarks();
295
    static void     SendReferenceMarks( const SfxViewShell* pViewShell,
296
                         const std::vector<ReferenceMark>& rReferenceMarks );
297
298
    void SetDocumentDisposing( bool b );
299
300
    static ReferenceMark GetReferenceMark( const ScViewData& rViewData, ScDocShell& rDocSh,
301
                                    tools::Long nX1, tools::Long nX2, tools::Long nY1, tools::Long nY2,
302
                                    tools::Long nTab, const Color& rColor );
303
304
    static void ErrorMessage(ScTabViewShell* pActiveViewShell, TranslateId errorMessage);
305
306
    void            LOKPasteFunctionData(const OUString& rFunctionName);
307
};
308
309
//  ScInputHdlState
310
311
class ScInputHdlState
312
{
313
    friend class ScInputHandler;
314
315
public:
316
        ScInputHdlState( const ScAddress& rCurPos,
317
                         const ScAddress& rStartPos,
318
                         const ScAddress& rEndPos,
319
                         OUString aString,
320
                         const EditTextObject* pData );
321
        ScInputHdlState( const ScInputHdlState& rCpy );
322
        ~ScInputHdlState();
323
324
    ScInputHdlState&    operator= ( const ScInputHdlState& r );
325
    bool                operator==( const ScInputHdlState& r ) const;
326
327
0
    const ScAddress&        GetPos() const          { return aCursorPos; }
328
0
    const ScAddress&        GetStartPos() const     { return aStartPos; }
329
0
    const ScAddress&        GetEndPos() const       { return aEndPos; }
330
0
    const OUString&         GetString() const       { return aString; }
331
0
    const EditTextObject*   GetEditData() const     { return pEditData.get(); }
332
333
private:
334
    ScAddress       aCursorPos;
335
    ScAddress       aStartPos;
336
    ScAddress       aEndPos;
337
    OUString        aString;
338
    std::unique_ptr<EditTextObject> pEditData;
339
};
340
341
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */