xref: /trunk/main/sc/source/ui/inc/inputhdl.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_INPUTHDL_HXX
25 #define SC_INPUTHDL_HXX
26 
27 #include "global.hxx"
28 #include "address.hxx"
29 #include <tools/fract.hxx>
30 #include <tools/gen.hxx>
31 #include <editeng/svxenum.hxx>
32 
33 class ScDocument;
34 class ScTabView;
35 class ScTabViewShell;
36 class ScInputWindow;
37 class ScPatternAttr;
38 class EditEngine;
39 class ScEditEngineDefaulter;
40 class EditView;
41 class EditTextObject;
42 class ScInputHdlState;
43 class TypedScStrCollection;
44 class ScRangeFindList;
45 class Timer;
46 class KeyEvent;
47 class CommandEvent;
48 
49 struct ESelection;
50 
51 //========================================================================
52 //	ScInputHandler
53 //========================================================================
54 
55 class ScInputHandler
56 {
57 private:
58 	ScInputWindow*			pInputWin;
59 
60 	ScEditEngineDefaulter*	pEngine;   				// editierte Daten in der Tabelle
61 	EditView*				pTableView;					// aktive EditView dazu
62 	EditView*				pTopView;					// EditView in der Eingabezeile
63 
64 	TypedScStrCollection*		pColumnData;
65 	TypedScStrCollection*		pFormulaData;
66     TypedScStrCollection*		pFormulaDataPara;
67 	Window*					pTipVisibleParent;
68 	sal_uLong					nTipVisible;
69 	Window*					pTipVisibleSecParent;
70     sal_uLong                   nTipVisibleSec;
71 	String					aManualTip;
72 	String					aAutoSearch;
73 	sal_uInt16					nAutoPos;
74 	sal_Bool					bUseTab;					// Blaettern moeglich
75 
76 	sal_Bool					bTextValid;					// Text noch nicht in Edit-Engine
77 	String					aCurrentText;
78 
79 	String					aFormText;					// fuer Funktions-Autopilot
80 	xub_StrLen				nFormSelStart;				// Selektion fuer Funktions-Autopilot
81 	xub_StrLen				nFormSelEnd;
82 
83 	sal_uInt16					nAutoPar;					// autom.parentheses than can be overwritten
84 
85 	ScAddress				aCursorPos;
86 	ScInputMode				eMode;
87 	sal_Bool					bModified;
88 	sal_Bool					bSelIsRef;
89 	sal_Bool					bFormulaMode;
90 	sal_Bool					bInRangeUpdate;
91 	sal_Bool					bParenthesisShown;
92 	sal_Bool					bCreatingFuncView;
93 	sal_Bool					bInEnterHandler;
94 	sal_Bool					bCommandErrorShown;
95 	sal_Bool					bInOwnChange;
96 
97 	sal_Bool					bProtected;
98 	sal_Bool					bCellHasPercentFormat;
99 	sal_uLong					nValidation;
100     SvxCellHorJustify       eAttrAdjust;
101 
102 	Fraction				aScaleX;					// fuer Ref-MapMode
103 	Fraction				aScaleY;
104 
105 	ScTabViewShell*			pRefViewSh;
106 	ScTabViewShell*			pActiveViewSh;
107 
108 	const ScPatternAttr*	pLastPattern;
109 	SfxItemSet*			 	pEditDefaults;
110 	sal_Bool					bLastIsSymbol;
111 
112 	ScInputHdlState*		pLastState;
113 	Timer*					pDelayTimer;
114 
115 	ScRangeFindList*		pRangeFindList;
116 
117 	static sal_Bool				bAutoComplete;				// aus App-Optionen
118 	static sal_Bool				bOptLoaded;
119 
120 #ifdef _INPUTHDL_CXX
121 private:
122 	void			UpdateActiveView();
123 	void			SyncViews( EditView* pSourceView = NULL );
124 	sal_Bool			StartTable( sal_Unicode cTyped, sal_Bool bFromCommand );
125 	void			RemoveSelection();
126 	void			UpdateFormulaMode();
127 	void			InvalidateAttribs();
128 	void			ImplCreateEditEngine();
129 	DECL_LINK(		DelayTimer, Timer* );
130 	void			GetColData();
131 	void			UseColData();
132 	void			NextAutoEntry( sal_Bool bBack );
133 	void			UpdateAdjust( sal_Unicode cTyped );
134 	void			GetFormulaData();
135 	void			UseFormulaData();
136 	void			NextFormulaEntry( sal_Bool bBack );
137 	void			PasteFunctionData();
138 	void			PasteManualTip();
139 	EditView*		GetFuncEditView();
140 	void			RemoveAdjust();
141 	void			RemoveRangeFinder();
142 	void			DeleteRangeFinder();
143 	void			UpdateParenthesis();
144 	void			UpdateAutoCorrFlag();
145 	void			ResetAutoPar();
146 	void			AutoParAdded();
147 	sal_Bool			CursorAtClosingPar();
148 	void			SkipClosingPar();
149 	DECL_LINK( ModifyHdl, void* );
150 	DECL_LINK( ShowHideTipVisibleParentListener, VclWindowEvent* );
151 	DECL_LINK( ShowHideTipVisibleSecParentListener, VclWindowEvent* );
152 #endif
153 
154 public:
155 					ScInputHandler();
156 	virtual			~ScInputHandler();
157 
158 	void			SetMode( ScInputMode eNewMode );
IsInputMode() const159 	sal_Bool			IsInputMode() const	{ return (eMode != SC_INPUT_NONE); }
IsEditMode() const160 	sal_Bool			IsEditMode() const	{ return (eMode != SC_INPUT_NONE &&
161 												  eMode != SC_INPUT_TYPE); }
IsTopMode() const162 	sal_Bool			IsTopMode() const	{ return (eMode == SC_INPUT_TOP);  }
163 
164 	const String&	GetEditString();
GetFormString() const165 	const String&	GetFormString() const	{ return aFormText; }
166 
GetCursorPos() const167     const ScAddress& GetCursorPos() const   { return aCursorPos; }
168 
169 	sal_Bool			GetTextAndFields( ScEditEngineDefaulter& rDestEngine );
170 
171 	sal_Bool			KeyInput( const KeyEvent& rKEvt, sal_Bool bStartEdit = sal_False );
172 	void			EnterHandler( sal_uInt8 nBlockMode = 0 );
173 	void			CancelHandler();
174 	void			SetReference( const ScRange& rRef, ScDocument* pDoc );
175 	void			AddRefEntry();
176 
177 	sal_Bool			InputCommand( const CommandEvent& rCEvt, sal_Bool bForce );
178 
179 	void			InsertFunction( const String& rFuncName, sal_Bool bAddPar = sal_True );
180 	void			ClearText();
181 
182 	void			InputSelection( EditView* pView );
183 	void			InputChanged( EditView* pView, sal_Bool bFromNotify = sal_False );
184 
185 	void			ViewShellGone(ScTabViewShell* pViewSh);
SetRefViewShell(ScTabViewShell * pRefVsh)186 	void			SetRefViewShell(ScTabViewShell*	pRefVsh) {pRefViewSh=pRefVsh;}
187 
188 
189 	void			NotifyChange( const ScInputHdlState* pState, sal_Bool bForce = sal_False,
190 									ScTabViewShell* pSourceSh = NULL,
191                                     sal_Bool bStopEditing = sal_True);
192     void            UpdateCellAdjust( SvxCellHorJustify eJust );
193 
194 	void			ResetDelayTimer(); //BugId 54702
195 
196 	void			HideTip();
197     void            HideTipBelow();
198     void            ShowTipCursor();
199 	void			ShowTip( const String& rText );		// am Cursor
200     void			ShowTipBelow( const String& rText );
201 
202 	void			SetRefScale( const Fraction& rX, const Fraction& rY );
203 	void			UpdateRefDevice();
204 
205 	EditView*		GetActiveView();
GetTableView()206 	EditView*		GetTableView()		{ return pTableView; }
GetTopView()207 	EditView*		GetTopView()		{ return pTopView; }
208 
209 	sal_Bool			DataChanging( sal_Unicode cTyped = 0, sal_Bool bFromCommand = sal_False );
210     void            DataChanged( sal_Bool bFromTopNotify = sal_False, sal_Bool bSetModified = sal_True );
211 
TakesReturn() const212 	sal_Bool			TakesReturn() const		{ return ( nTipVisible != 0 ); }
213 
SetModified()214 	void			SetModified()		{ bModified = sal_True; }
215 
GetSelIsRef() const216 	sal_Bool			GetSelIsRef() const		{ return bSelIsRef; }
SetSelIsRef(sal_Bool bSet)217 	void			SetSelIsRef(sal_Bool bSet)	{ bSelIsRef = bSet; }
218 
219 	void			ShowRefFrame();
220 
GetRangeFindList()221 	ScRangeFindList* GetRangeFindList()		{ return pRangeFindList; }
222 
223 	void			UpdateRange( sal_uInt16 nIndex, const ScRange& rNew );
224 
225 	// Kommunikation mit Funktionsautopilot
226 	void			InputGetSelection		( xub_StrLen& rStart, xub_StrLen& rEnd );
227 	void		 	InputSetSelection		( xub_StrLen nStart, xub_StrLen nEnd );
228 	void		 	InputReplaceSelection	( const String& rStr );
229 	String			InputGetFormulaStr		();
230 
IsFormulaMode() const231 	sal_Bool			IsFormulaMode() const					{ return bFormulaMode; }
GetInputWindow()232 	ScInputWindow*	GetInputWindow()						{ return pInputWin; }
SetInputWindow(ScInputWindow * pNew)233 	void			SetInputWindow( ScInputWindow* pNew )	{ pInputWin = pNew; }
234 	void			StopInputWinEngine( sal_Bool bAll );
235 
IsInEnterHandler() const236 	sal_Bool			IsInEnterHandler() const				{ return bInEnterHandler; }
IsInOwnChange() const237 	sal_Bool			IsInOwnChange() const					{ return bInOwnChange; }
238 
239 	sal_Bool			IsModalMode( SfxObjectShell* pDocSh );
240 
241 	void			ForgetLastPattern();
242 
243 	void			UpdateSpellSettings( sal_Bool bFromStartTab = sal_False );
244 
245 	void			FormulaPreview();
246 
247 	Size			GetTextSize();		// in 1/100mm
248 
249 					// eigentlich private, fuer SID_INPUT_SUM public
250 	void			InitRangeFinder( const String& rFormula );
251 
SetAutoComplete(sal_Bool bSet)252 	static void		SetAutoComplete(sal_Bool bSet)	{ bAutoComplete = bSet; }
253 };
254 
255 //========================================================================
256 //	ScInputHdlState
257 //========================================================================
258 class ScInputHdlState
259 {
260 	friend class ScInputHandler;
261 
262 public:
263 		ScInputHdlState( const ScAddress& rCurPos,
264 						 const ScAddress& rStartPos,
265 						 const ScAddress& rEndPos,
266 						 const String& rString,
267 						 const EditTextObject* pData );
268 		ScInputHdlState( const ScInputHdlState& rCpy );
269 		~ScInputHdlState();
270 
271 	ScInputHdlState&	operator= ( const ScInputHdlState& r );
272 	int					operator==( const ScInputHdlState& r ) const;
operator !=(const ScInputHdlState & r) const273 	int					operator!=( const ScInputHdlState& r ) const
274 							{ return !operator==( r ); }
275 
GetPos() const276 	const ScAddress&		GetPos() const 			{ return aCursorPos; }
GetStartPos() const277 	const ScAddress&		GetStartPos() const 	{ return aStartPos; }
GetEndPos() const278 	const ScAddress& 		GetEndPos() const 		{ return aEndPos; }
GetString() const279 	const String&			GetString() const		{ return aString; }
GetEditData() const280 	const EditTextObject*	GetEditData() const		{ return pEditData; }
281 
282 private:
283 	ScAddress		aCursorPos;
284 	ScAddress		aStartPos;
285 	ScAddress		aEndPos;
286 	String			aString;
287 	EditTextObject* pEditData;
288 };
289 
290 
291 
292 #endif
293 
294 
295