xref: /AOO41X/main/sc/source/ui/inc/inputhdl.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 
28*cdf0e10cSrcweir #ifndef SC_INPUTHDL_HXX
29*cdf0e10cSrcweir #define SC_INPUTHDL_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "global.hxx"
32*cdf0e10cSrcweir #include "address.hxx"
33*cdf0e10cSrcweir #include <tools/fract.hxx>
34*cdf0e10cSrcweir #include <tools/gen.hxx>
35*cdf0e10cSrcweir #include <editeng/svxenum.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir class ScDocument;
38*cdf0e10cSrcweir class ScTabView;
39*cdf0e10cSrcweir class ScTabViewShell;
40*cdf0e10cSrcweir class ScInputWindow;
41*cdf0e10cSrcweir class ScPatternAttr;
42*cdf0e10cSrcweir class EditEngine;
43*cdf0e10cSrcweir class ScEditEngineDefaulter;
44*cdf0e10cSrcweir class EditView;
45*cdf0e10cSrcweir class EditTextObject;
46*cdf0e10cSrcweir class ScInputHdlState;
47*cdf0e10cSrcweir class TypedScStrCollection;
48*cdf0e10cSrcweir class ScRangeFindList;
49*cdf0e10cSrcweir class Timer;
50*cdf0e10cSrcweir class KeyEvent;
51*cdf0e10cSrcweir class CommandEvent;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir struct ESelection;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //========================================================================
56*cdf0e10cSrcweir //	ScInputHandler
57*cdf0e10cSrcweir //========================================================================
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir class ScInputHandler
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir private:
62*cdf0e10cSrcweir 	ScInputWindow*			pInputWin;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 	ScEditEngineDefaulter*	pEngine;   				// editierte Daten in der Tabelle
65*cdf0e10cSrcweir 	EditView*				pTableView;					// aktive EditView dazu
66*cdf0e10cSrcweir 	EditView*				pTopView;					// EditView in der Eingabezeile
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 	TypedScStrCollection*		pColumnData;
69*cdf0e10cSrcweir 	TypedScStrCollection*		pFormulaData;
70*cdf0e10cSrcweir     TypedScStrCollection*		pFormulaDataPara;
71*cdf0e10cSrcweir 	Window*					pTipVisibleParent;
72*cdf0e10cSrcweir 	sal_uLong					nTipVisible;
73*cdf0e10cSrcweir 	Window*					pTipVisibleSecParent;
74*cdf0e10cSrcweir     sal_uLong                   nTipVisibleSec;
75*cdf0e10cSrcweir 	String					aManualTip;
76*cdf0e10cSrcweir 	String					aAutoSearch;
77*cdf0e10cSrcweir 	sal_uInt16					nAutoPos;
78*cdf0e10cSrcweir 	sal_Bool					bUseTab;					// Blaettern moeglich
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	sal_Bool					bTextValid;					// Text noch nicht in Edit-Engine
81*cdf0e10cSrcweir 	String					aCurrentText;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	String					aFormText;					// fuer Funktions-Autopilot
84*cdf0e10cSrcweir 	xub_StrLen				nFormSelStart;				// Selektion fuer Funktions-Autopilot
85*cdf0e10cSrcweir 	xub_StrLen				nFormSelEnd;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	sal_uInt16					nAutoPar;					// autom.parentheses than can be overwritten
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	ScAddress				aCursorPos;
90*cdf0e10cSrcweir 	ScInputMode				eMode;
91*cdf0e10cSrcweir 	sal_Bool					bModified;
92*cdf0e10cSrcweir 	sal_Bool					bSelIsRef;
93*cdf0e10cSrcweir 	sal_Bool					bFormulaMode;
94*cdf0e10cSrcweir 	sal_Bool					bInRangeUpdate;
95*cdf0e10cSrcweir 	sal_Bool					bParenthesisShown;
96*cdf0e10cSrcweir 	sal_Bool					bCreatingFuncView;
97*cdf0e10cSrcweir 	sal_Bool					bInEnterHandler;
98*cdf0e10cSrcweir 	sal_Bool					bCommandErrorShown;
99*cdf0e10cSrcweir 	sal_Bool					bInOwnChange;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	sal_Bool					bProtected;
102*cdf0e10cSrcweir 	sal_Bool					bCellHasPercentFormat;
103*cdf0e10cSrcweir 	sal_uLong					nValidation;
104*cdf0e10cSrcweir     SvxCellHorJustify       eAttrAdjust;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	Fraction				aScaleX;					// fuer Ref-MapMode
107*cdf0e10cSrcweir 	Fraction				aScaleY;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	ScTabViewShell*			pRefViewSh;
110*cdf0e10cSrcweir 	ScTabViewShell*			pActiveViewSh;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	const ScPatternAttr*	pLastPattern;
113*cdf0e10cSrcweir 	SfxItemSet*			 	pEditDefaults;
114*cdf0e10cSrcweir 	sal_Bool					bLastIsSymbol;
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	ScInputHdlState*		pLastState;
117*cdf0e10cSrcweir 	Timer*					pDelayTimer;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	ScRangeFindList*		pRangeFindList;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	static sal_Bool				bAutoComplete;				// aus App-Optionen
122*cdf0e10cSrcweir 	static sal_Bool				bOptLoaded;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir #ifdef _INPUTHDL_CXX
125*cdf0e10cSrcweir private:
126*cdf0e10cSrcweir 	void			UpdateActiveView();
127*cdf0e10cSrcweir 	void			SyncViews( EditView* pSourceView = NULL );
128*cdf0e10cSrcweir 	sal_Bool			StartTable( sal_Unicode cTyped, sal_Bool bFromCommand );
129*cdf0e10cSrcweir 	void			RemoveSelection();
130*cdf0e10cSrcweir 	void			UpdateFormulaMode();
131*cdf0e10cSrcweir 	void			InvalidateAttribs();
132*cdf0e10cSrcweir 	void			ImplCreateEditEngine();
133*cdf0e10cSrcweir 	DECL_LINK(		DelayTimer, Timer* );
134*cdf0e10cSrcweir 	void			GetColData();
135*cdf0e10cSrcweir 	void			UseColData();
136*cdf0e10cSrcweir 	void			NextAutoEntry( sal_Bool bBack );
137*cdf0e10cSrcweir 	void			UpdateAdjust( sal_Unicode cTyped );
138*cdf0e10cSrcweir 	void			GetFormulaData();
139*cdf0e10cSrcweir 	void			UseFormulaData();
140*cdf0e10cSrcweir 	void			NextFormulaEntry( sal_Bool bBack );
141*cdf0e10cSrcweir 	void			PasteFunctionData();
142*cdf0e10cSrcweir 	void			PasteManualTip();
143*cdf0e10cSrcweir 	EditView*		GetFuncEditView();
144*cdf0e10cSrcweir 	void			RemoveAdjust();
145*cdf0e10cSrcweir 	void			RemoveRangeFinder();
146*cdf0e10cSrcweir 	void			DeleteRangeFinder();
147*cdf0e10cSrcweir 	void			UpdateParenthesis();
148*cdf0e10cSrcweir 	void			UpdateAutoCorrFlag();
149*cdf0e10cSrcweir 	void			ResetAutoPar();
150*cdf0e10cSrcweir 	void			AutoParAdded();
151*cdf0e10cSrcweir 	sal_Bool			CursorAtClosingPar();
152*cdf0e10cSrcweir 	void			SkipClosingPar();
153*cdf0e10cSrcweir 	DECL_LINK( ModifyHdl, void* );
154*cdf0e10cSrcweir 	DECL_LINK( ShowHideTipVisibleParentListener, VclWindowEvent* );
155*cdf0e10cSrcweir 	DECL_LINK( ShowHideTipVisibleSecParentListener, VclWindowEvent* );
156*cdf0e10cSrcweir #endif
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir public:
159*cdf0e10cSrcweir 					ScInputHandler();
160*cdf0e10cSrcweir 	virtual			~ScInputHandler();
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	void			SetMode( ScInputMode eNewMode );
163*cdf0e10cSrcweir 	sal_Bool			IsInputMode() const	{ return (eMode != SC_INPUT_NONE); }
164*cdf0e10cSrcweir 	sal_Bool			IsEditMode() const	{ return (eMode != SC_INPUT_NONE &&
165*cdf0e10cSrcweir 												  eMode != SC_INPUT_TYPE); }
166*cdf0e10cSrcweir 	sal_Bool			IsTopMode() const	{ return (eMode == SC_INPUT_TOP);  }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	const String&	GetEditString();
169*cdf0e10cSrcweir 	const String&	GetFormString() const	{ return aFormText; }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     const ScAddress& GetCursorPos() const   { return aCursorPos; }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	sal_Bool			GetTextAndFields( ScEditEngineDefaulter& rDestEngine );
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	sal_Bool			KeyInput( const KeyEvent& rKEvt, sal_Bool bStartEdit = sal_False );
176*cdf0e10cSrcweir 	void			EnterHandler( sal_uInt8 nBlockMode = 0 );
177*cdf0e10cSrcweir 	void			CancelHandler();
178*cdf0e10cSrcweir 	void			SetReference( const ScRange& rRef, ScDocument* pDoc );
179*cdf0e10cSrcweir 	void			AddRefEntry();
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	sal_Bool			InputCommand( const CommandEvent& rCEvt, sal_Bool bForce );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	void			InsertFunction( const String& rFuncName, sal_Bool bAddPar = sal_True );
184*cdf0e10cSrcweir 	void			ClearText();
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	void			InputSelection( EditView* pView );
187*cdf0e10cSrcweir 	void			InputChanged( EditView* pView, sal_Bool bFromNotify = sal_False );
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	void			ViewShellGone(ScTabViewShell* pViewSh);
190*cdf0e10cSrcweir 	void			SetRefViewShell(ScTabViewShell*	pRefVsh) {pRefViewSh=pRefVsh;}
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	void			NotifyChange( const ScInputHdlState* pState, sal_Bool bForce = sal_False,
194*cdf0e10cSrcweir 									ScTabViewShell* pSourceSh = NULL,
195*cdf0e10cSrcweir                                     sal_Bool bStopEditing = sal_True);
196*cdf0e10cSrcweir     void            UpdateCellAdjust( SvxCellHorJustify eJust );
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	void			ResetDelayTimer(); //BugId 54702
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 	void			HideTip();
201*cdf0e10cSrcweir     void            HideTipBelow();
202*cdf0e10cSrcweir     void            ShowTipCursor();
203*cdf0e10cSrcweir 	void			ShowTip( const String& rText );		// am Cursor
204*cdf0e10cSrcweir     void			ShowTipBelow( const String& rText );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 	void			SetRefScale( const Fraction& rX, const Fraction& rY );
207*cdf0e10cSrcweir 	void			UpdateRefDevice();
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	EditView*		GetActiveView();
210*cdf0e10cSrcweir 	EditView*		GetTableView()		{ return pTableView; }
211*cdf0e10cSrcweir 	EditView*		GetTopView()		{ return pTopView; }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 	sal_Bool			DataChanging( sal_Unicode cTyped = 0, sal_Bool bFromCommand = sal_False );
214*cdf0e10cSrcweir     void            DataChanged( sal_Bool bFromTopNotify = sal_False, sal_Bool bSetModified = sal_True );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	sal_Bool			TakesReturn() const		{ return ( nTipVisible != 0 ); }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	void			SetModified()		{ bModified = sal_True; }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	sal_Bool			GetSelIsRef() const		{ return bSelIsRef; }
221*cdf0e10cSrcweir 	void			SetSelIsRef(sal_Bool bSet)	{ bSelIsRef = bSet; }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	void			ShowRefFrame();
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	ScRangeFindList* GetRangeFindList()		{ return pRangeFindList; }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 	void			UpdateRange( sal_uInt16 nIndex, const ScRange& rNew );
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	// Kommunikation mit Funktionsautopilot
230*cdf0e10cSrcweir 	void			InputGetSelection		( xub_StrLen& rStart, xub_StrLen& rEnd );
231*cdf0e10cSrcweir 	void		 	InputSetSelection		( xub_StrLen nStart, xub_StrLen nEnd );
232*cdf0e10cSrcweir 	void		 	InputReplaceSelection	( const String& rStr );
233*cdf0e10cSrcweir 	String			InputGetFormulaStr		();
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 	sal_Bool			IsFormulaMode() const					{ return bFormulaMode; }
236*cdf0e10cSrcweir 	ScInputWindow*	GetInputWindow()						{ return pInputWin; }
237*cdf0e10cSrcweir 	void			SetInputWindow( ScInputWindow* pNew )	{ pInputWin = pNew; }
238*cdf0e10cSrcweir 	void			StopInputWinEngine( sal_Bool bAll );
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 	sal_Bool			IsInEnterHandler() const				{ return bInEnterHandler; }
241*cdf0e10cSrcweir 	sal_Bool			IsInOwnChange() const					{ return bInOwnChange; }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 	sal_Bool			IsModalMode( SfxObjectShell* pDocSh );
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	void			ForgetLastPattern();
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	void			UpdateSpellSettings( sal_Bool bFromStartTab = sal_False );
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	void			FormulaPreview();
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	Size			GetTextSize();		// in 1/100mm
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 					// eigentlich private, fuer SID_INPUT_SUM public
254*cdf0e10cSrcweir 	void			InitRangeFinder( const String& rFormula );
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 	static void		SetAutoComplete(sal_Bool bSet)	{ bAutoComplete = bSet; }
257*cdf0e10cSrcweir };
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir //========================================================================
260*cdf0e10cSrcweir //	ScInputHdlState
261*cdf0e10cSrcweir //========================================================================
262*cdf0e10cSrcweir class ScInputHdlState
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir 	friend class ScInputHandler;
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir public:
267*cdf0e10cSrcweir 		ScInputHdlState( const ScAddress& rCurPos,
268*cdf0e10cSrcweir 						 const ScAddress& rStartPos,
269*cdf0e10cSrcweir 						 const ScAddress& rEndPos,
270*cdf0e10cSrcweir 						 const String& rString,
271*cdf0e10cSrcweir 						 const EditTextObject* pData );
272*cdf0e10cSrcweir 		ScInputHdlState( const ScInputHdlState& rCpy );
273*cdf0e10cSrcweir 		~ScInputHdlState();
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 	ScInputHdlState&	operator= ( const ScInputHdlState& r );
276*cdf0e10cSrcweir 	int					operator==( const ScInputHdlState& r ) const;
277*cdf0e10cSrcweir 	int					operator!=( const ScInputHdlState& r ) const
278*cdf0e10cSrcweir 							{ return !operator==( r ); }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	const ScAddress&		GetPos() const 			{ return aCursorPos; }
281*cdf0e10cSrcweir 	const ScAddress&		GetStartPos() const 	{ return aStartPos; }
282*cdf0e10cSrcweir 	const ScAddress& 		GetEndPos() const 		{ return aEndPos; }
283*cdf0e10cSrcweir 	const String&			GetString() const		{ return aString; }
284*cdf0e10cSrcweir 	const EditTextObject*	GetEditData() const		{ return pEditData; }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir private:
287*cdf0e10cSrcweir 	ScAddress		aCursorPos;
288*cdf0e10cSrcweir 	ScAddress		aStartPos;
289*cdf0e10cSrcweir 	ScAddress		aEndPos;
290*cdf0e10cSrcweir 	String			aString;
291*cdf0e10cSrcweir 	EditTextObject* pEditData;
292*cdf0e10cSrcweir };
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir #endif
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 
299