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