Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / inc / inputhdl.hxx
blob1c2d9c36b278768cff84d1fe442f1e2a32fca57a
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 #ifndef SC_INPUTHDL_HXX
21 #define SC_INPUTHDL_HXX
23 #include "global.hxx"
24 #include "address.hxx"
25 #include "typedstrdata.hxx"
27 #include <tools/fract.hxx>
28 #include <tools/gen.hxx>
29 #include "tools/link.hxx"
30 #include "vcl/vclevent.hxx"
31 #include <editeng/svxenum.hxx>
33 #include <set>
35 #include <boost/noncopyable.hpp>
37 class ScDocument;
38 class ScTabViewShell;
39 class ScInputWindow;
40 class ScPatternAttr;
41 class ScEditEngineDefaulter;
42 class EditView;
43 class EditTextObject;
44 class ScInputHdlState;
45 class ScRangeFindList;
46 class Timer;
47 class KeyEvent;
48 class CommandEvent;
50 struct ESelection;
52 //========================================================================
53 // ScInputHandler
54 //========================================================================
56 class ScInputHandler : boost::noncopyable
58 private:
59 ScInputWindow* pInputWin;
61 ScEditEngineDefaulter* pEngine; // edited data in the sheet
62 EditView* pTableView; // associated active EditView
63 EditView* pTopView; // EditView in dthe input row
65 ScTypedCaseStrSet* pColumnData;
66 ScTypedCaseStrSet* pFormulaData;
67 ScTypedCaseStrSet* pFormulaDataPara;
68 ScTypedCaseStrSet::const_iterator miAutoPosColumn;
69 ScTypedCaseStrSet::const_iterator miAutoPosFormula;
71 Window* pTipVisibleParent;
72 sal_uLong nTipVisible;
73 Window* pTipVisibleSecParent;
74 sal_uLong nTipVisibleSec;
75 OUString aManualTip;
76 OUString aAutoSearch;
78 OUString aCurrentText;
80 OUString aFormText; // for autopilot function
81 xub_StrLen nFormSelStart; // Selection for autopilot function
82 xub_StrLen nFormSelEnd;
84 sal_uInt16 nAutoPar; // autom.parentheses than can be overwritten
86 ScAddress aCursorPos;
87 ScInputMode eMode;
88 bool bUseTab:1; // Scrolling possible
89 bool bTextValid:1; // Text is not in edit engine
90 bool bModified:1;
91 bool bSelIsRef:1;
92 bool bFormulaMode:1;
93 bool bInRangeUpdate:1;
94 bool bParenthesisShown:1;
95 bool bCreatingFuncView:1;
96 bool bInEnterHandler:1;
97 bool bCommandErrorShown:1;
98 bool bInOwnChange:1;
100 bool bProtected:1;
101 bool bCellHasPercentFormat:1;
102 bool bLastIsSymbol:1;
103 sal_uLong nValidation;
104 SvxCellHorJustify eAttrAdjust;
106 Fraction aScaleX; // for ref MapMode
107 Fraction aScaleY;
109 ScTabViewShell* pRefViewSh;
110 ScTabViewShell* pActiveViewSh;
112 const ScPatternAttr* pLastPattern;
113 SfxItemSet* pEditDefaults;
115 ScInputHdlState* pLastState;
116 Timer* pDelayTimer;
118 ScRangeFindList* pRangeFindList;
120 static bool bAutoComplete; // from app options
121 static bool bOptLoaded;
123 private:
124 void UpdateActiveView();
125 void SyncViews( EditView* pSourceView = NULL );
127 * @param cTyped typed character. If 0, look at existing document content
128 * for text or number.
129 * @param bInputActivated true if the cell input mode is activated (via
130 * F2), false otherwise.
131 * @return true if the new edit mode has been started.
133 bool StartTable( sal_Unicode cTyped, bool bFromCommand, bool bInputActivated );
134 void RemoveSelection();
135 void UpdateFormulaMode();
136 void InvalidateAttribs();
137 void ImplCreateEditEngine();
138 DECL_LINK( DelayTimer, Timer* );
139 void GetColData();
140 void UseColData();
141 void NextAutoEntry( bool bBack );
142 void UpdateAdjust( sal_Unicode cTyped );
143 void GetFormulaData();
144 void UseFormulaData();
145 void NextFormulaEntry( bool bBack );
146 void PasteFunctionData();
147 void PasteManualTip();
148 EditView* GetFuncEditView();
149 void RemoveAdjust();
150 void RemoveRangeFinder();
151 void DeleteRangeFinder();
152 void UpdateParenthesis();
153 void UpdateAutoCorrFlag();
154 void ResetAutoPar();
155 void AutoParAdded();
156 bool CursorAtClosingPar();
157 void SkipClosingPar();
158 DECL_LINK( ModifyHdl, void* );
159 DECL_LINK( ShowHideTipVisibleParentListener, VclWindowEvent* );
160 DECL_LINK( ShowHideTipVisibleSecParentListener, VclWindowEvent* );
162 public:
163 ScInputHandler();
164 virtual ~ScInputHandler();
166 void SetMode( ScInputMode eNewMode );
167 bool IsInputMode() const { return (eMode != SC_INPUT_NONE); }
168 bool IsEditMode() const { return (eMode != SC_INPUT_NONE &&
169 eMode != SC_INPUT_TYPE); }
170 bool IsTopMode() const { return (eMode == SC_INPUT_TOP); }
172 const OUString& GetEditString();
173 const OUString& GetFormString() const { return aFormText; }
175 const ScAddress& GetCursorPos() const { return aCursorPos; }
177 bool GetTextAndFields( ScEditEngineDefaulter& rDestEngine );
179 bool KeyInput( const KeyEvent& rKEvt, bool bStartEdit = false );
180 void EnterHandler( sal_uInt8 nBlockMode = 0 );
181 void CancelHandler();
182 void SetReference( const ScRange& rRef, ScDocument* pDoc );
183 void AddRefEntry();
185 bool InputCommand( const CommandEvent& rCEvt, bool bForce );
187 void InsertFunction( const OUString& rFuncName, bool bAddPar = true );
188 void ClearText();
190 void InputSelection( EditView* pView );
191 void InputChanged( EditView* pView, bool bFromNotify = false );
193 void ViewShellGone(ScTabViewShell* pViewSh);
194 void SetRefViewShell(ScTabViewShell* pRefVsh) {pRefViewSh=pRefVsh;}
196 void NotifyChange( const ScInputHdlState* pState, bool bForce = false,
197 ScTabViewShell* pSourceSh = NULL,
198 bool bStopEditing = true);
199 void UpdateCellAdjust( SvxCellHorJustify eJust );
201 void ResetDelayTimer(); //BugId 54702
203 void HideTip();
204 void HideTipBelow();
205 void ShowTipCursor();
206 void ShowTip( const OUString& rText ); // at Cursor
207 void ShowTipBelow( const OUString& rText );
209 void SetRefScale( const Fraction& rX, const Fraction& rY );
210 void UpdateRefDevice();
212 EditView* GetActiveView();
213 EditView* GetTableView() { return pTableView; }
214 EditView* GetTopView() { return pTopView; }
216 bool DataChanging( sal_Unicode cTyped = 0, bool bFromCommand = false );
217 void DataChanged( bool bFromTopNotify = false, bool bSetModified = true );
219 bool TakesReturn() const { return ( nTipVisible != 0 ); }
221 void SetModified() { bModified = true; }
223 bool GetSelIsRef() const { return bSelIsRef; }
224 void SetSelIsRef(bool bSet) { bSelIsRef = bSet; }
226 void ShowRefFrame();
228 ScRangeFindList* GetRangeFindList() { return pRangeFindList; }
230 void UpdateRange( sal_uInt16 nIndex, const ScRange& rNew );
232 // Communication with the autopilot function
233 void InputGetSelection ( xub_StrLen& rStart, xub_StrLen& rEnd );
234 void InputSetSelection ( xub_StrLen nStart, xub_StrLen nEnd );
235 void InputReplaceSelection ( const OUString& rStr );
236 void InputTurnOffWinEngine();
238 bool IsFormulaMode() const { return bFormulaMode; }
239 ScInputWindow* GetInputWindow() { return pInputWin; }
240 void SetInputWindow( ScInputWindow* pNew ) { pInputWin = pNew; }
241 void StopInputWinEngine( bool bAll );
243 bool IsInEnterHandler() const { return bInEnterHandler; }
244 bool IsInOwnChange() const { return bInOwnChange; }
246 bool IsModalMode( SfxObjectShell* pDocSh );
248 void ForgetLastPattern();
250 void UpdateSpellSettings( bool bFromStartTab = false );
252 void FormulaPreview();
254 Size GetTextSize(); // in 1/100mm
256 // actually private, public for SID_INPUT_SUM
257 void InitRangeFinder(const OUString& rFormula);
259 static void SetAutoComplete(bool bSet) { bAutoComplete = bSet; }
262 //========================================================================
263 // ScInputHdlState
264 //========================================================================
265 class ScInputHdlState
267 friend class ScInputHandler;
269 public:
270 ScInputHdlState( const ScAddress& rCurPos,
271 const ScAddress& rStartPos,
272 const ScAddress& rEndPos,
273 const OUString& rString,
274 const EditTextObject* pData );
275 ScInputHdlState( const ScInputHdlState& rCpy );
276 ~ScInputHdlState();
278 ScInputHdlState& operator= ( const ScInputHdlState& r );
279 int operator==( const ScInputHdlState& r ) const;
280 int operator!=( const ScInputHdlState& r ) const
281 { return !operator==( r ); }
283 const ScAddress& GetPos() const { return aCursorPos; }
284 const ScAddress& GetStartPos() const { return aStartPos; }
285 const ScAddress& GetEndPos() const { return aEndPos; }
286 const OUString& GetString() const { return aString; }
287 const EditTextObject* GetEditData() const { return pEditData; }
289 private:
290 ScAddress aCursorPos;
291 ScAddress aStartPos;
292 ScAddress aEndPos;
293 OUString aString;
294 EditTextObject* pEditData;
297 #endif
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */