xref: /trunk/main/vcl/inc/vcl/seleng.hxx (revision 0d63794c)
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 _SV_SELENG_HXX
25 #define _SV_SELENG_HXX
26 
27 #include <vcl/dllapi.h>
28 #include <vcl/timer.hxx>
29 #include <vcl/event.hxx>
30 
31 class Window;
32 class CommandEvent;
33 
34 // Timerticks
35 #define SELENG_DRAGDROP_TIMEOUT     400
36 #define SELENG_AUTOREPEAT_INTERVAL  50
37 
38 enum SelectionMode { NO_SELECTION, SINGLE_SELECTION, RANGE_SELECTION, MULTIPLE_SELECTION };
39 
40 // ---------------
41 // - FunctionSet -
42 // ---------------
43 
44 class VCL_DLLPUBLIC FunctionSet
45 {
46 public:
47     virtual void    BeginDrag() = 0;
48 
49     virtual void    CreateAnchor() = 0;  // Anker-Pos := Cursor-Pos
50 	virtual void	DestroyAnchor() = 0;
51 
52     // Cursor neu setzen, dabei die beim Anker beginnende
53     // Selektion der neuen Cursor-Position anpassen. sal_True == Ok
54     virtual sal_Bool    SetCursorAtPoint( const Point& rPointPixel,
55                                       sal_Bool bDontSelectAtCursor = sal_False ) = 0;
56 
57     virtual sal_Bool    IsSelectionAtPoint( const Point& rPointPixel ) = 0;
58 	virtual void    DeselectAtPoint( const Point& rPointPixel ) = 0;
59 	// Anker loeschen & alles deselektieren
60     virtual void    DeselectAll() = 0;
61 };
62 
63 // -------------------
64 // - SelectionEngine -
65 // -------------------
66 
67 #define SELENG_DRG_ENAB     0x0001
68 #define SELENG_IN_SEL       0x0002
69 #define SELENG_IN_ADD       0x0004
70 #define SELENG_ADD_ALW      0x0008
71 #define SELENG_IN_DRG       0x0010
72 #define SELENG_HAS_ANCH     0x0020
73 #define SELENG_CMDEVT       0x0040
74 #define SELENG_WAIT_UPEVT   0x0080
75 #define SELENG_EXPANDONMOVE	0x0100
76 
77 class VCL_DLLPUBLIC SelectionEngine
78 {
79 private:
80     FunctionSet*        pFunctionSet;
81     Window*             pWin;
82     Rectangle           aArea;
83     Timer               aWTimer; // erzeugt kuenstliche Mouse-Moves
84     MouseEvent          aLastMove;
85     SelectionMode       eSelMode;
86     // Stufigkeit fuer Mausbewegungen waehrend einer Selektion
87     sal_uInt16              nMouseSensitivity;
88     sal_uInt16              nLockedMods;
89     sal_uInt16              nFlags;
90 //#if 0 // _SOLAR__PRIVATE
91     DECL_DLLPRIVATE_LINK( ImpWatchDog, Timer * );
92 //#endif
93 
94 	inline sal_Bool			ShouldDeselect( sal_Bool bModifierKey1 ) const;
95 								// determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
96 public:
97 
98                         SelectionEngine( Window* pWindow,
99                                          FunctionSet* pFunctions = NULL );
100                         ~SelectionEngine();
101 
102     // sal_True: Event wurde von Selection-Engine verarbeitet.
103     sal_Bool                SelMouseButtonDown( const MouseEvent& rMEvt );
104     sal_Bool                SelMouseButtonUp( const MouseEvent& rMEvt );
105     sal_Bool                SelMouseMove( const MouseEvent& rMEvt );
106 
107     // Tastatur
108     void                CursorPosChanging( sal_Bool bShift, sal_Bool bMod1 );
109 
110     // wird benoetigt, um bei ausserhalb des Bereichs stehender
111     // Maus ueber einen Timer Move-Events zu erzeugen
SetVisibleArea(const Rectangle rNewArea)112     void                SetVisibleArea( const Rectangle rNewArea )
113                             { aArea = rNewArea; }
GetVisibleArea() const114     const Rectangle&    GetVisibleArea() const { return aArea; }
115 
116     void                SetAddMode( sal_Bool);
117     sal_Bool                IsAddMode() const;
118 
119     void                AddAlways( sal_Bool bOn );
120     sal_Bool                IsAlwaysAdding() const;
121 
122     void                EnableDrag( sal_Bool bOn );
123     sal_Bool                IsDragEnabled() const;
124     void                ActivateDragMode();
125     sal_Bool                IsInDragMode() const;
126 
127     void                SetSelectionMode( SelectionMode eMode );
GetSelectionMode() const128     SelectionMode       GetSelectionMode() const { return eSelMode; }
129 
SetFunctionSet(FunctionSet * pFuncs)130     void                SetFunctionSet( FunctionSet* pFuncs )
131                             { pFunctionSet = pFuncs; }
GetFunctionSet() const132     const FunctionSet*  GetFunctionSet() const { return pFunctionSet; }
133 
SetMouseSensitivity(sal_uInt16 nSensitivity)134     void                SetMouseSensitivity( sal_uInt16 nSensitivity )
135                             { nMouseSensitivity = nSensitivity; }
GetMouseSensitivity() const136     sal_uInt16              GetMouseSensitivity() const
137                             { return nMouseSensitivity; }
138 
GetMousePosPixel() const139     const Point&        GetMousePosPixel() const
140                             { return aLastMove.GetPosPixel(); }
GetMouseEvent() const141     const MouseEvent&   GetMouseEvent() const { return aLastMove; }
142 
143     void                SetWindow( Window*);
GetWindow() const144     Window*             GetWindow() const { return pWin; }
145 
LockModifiers(sal_uInt16 nModifiers)146     void                LockModifiers( sal_uInt16 nModifiers )
147                             { nLockedMods = nModifiers; }
GetLockedModifiers() const148     sal_uInt16              GetLockedModifiers() const { return nLockedMods; }
149 
150     sal_Bool                IsInSelection() const;
151     void                Reset();
152 
153     void                Command( const CommandEvent& rCEvt );
154 
155     sal_Bool                HasAnchor() const;
156     void                SetAnchor( sal_Bool bAnchor );
157 
158 	// wird im Ctor eingeschaltet
ExpandSelectionOnMouseMove(sal_Bool bExpand=sal_True)159 	void				ExpandSelectionOnMouseMove( sal_Bool bExpand = sal_True )
160 						{
161 							if( bExpand )
162 								nFlags |= SELENG_EXPANDONMOVE;
163 							else
164 								nFlags &= ~SELENG_EXPANDONMOVE;
165 						}
166 };
167 
IsDragEnabled() const168 inline sal_Bool SelectionEngine::IsDragEnabled() const
169 {
170     if ( nFlags & SELENG_DRG_ENAB )
171         return sal_True;
172     else
173         return sal_False;
174 }
175 
IsAddMode() const176 inline sal_Bool SelectionEngine::IsAddMode()  const
177 {
178     if ( nFlags & (SELENG_IN_ADD | SELENG_ADD_ALW) )
179         return sal_True;
180     else
181         return sal_False;
182 }
183 
SetAddMode(sal_Bool bNewMode)184 inline void SelectionEngine::SetAddMode( sal_Bool bNewMode )
185 {
186     if ( bNewMode )
187         nFlags |= SELENG_IN_ADD;
188     else
189         nFlags &= (~SELENG_IN_ADD);
190 }
191 
EnableDrag(sal_Bool bOn)192 inline void SelectionEngine::EnableDrag( sal_Bool bOn )
193 {
194     if ( bOn )
195         nFlags |= SELENG_DRG_ENAB;
196     else
197         nFlags &= (~SELENG_DRG_ENAB);
198 }
199 
AddAlways(sal_Bool bOn)200 inline void SelectionEngine::AddAlways( sal_Bool bOn )
201 {
202     if( bOn )
203         nFlags |= SELENG_ADD_ALW;
204     else
205         nFlags &= (~SELENG_ADD_ALW);
206 }
207 
IsAlwaysAdding() const208 inline sal_Bool SelectionEngine::IsAlwaysAdding() const
209 {
210     if ( nFlags & SELENG_ADD_ALW )
211         return sal_True;
212     else
213         return sal_False;
214 }
215 
IsInDragMode() const216 inline sal_Bool SelectionEngine::IsInDragMode() const
217 {
218     if ( nFlags & SELENG_IN_DRG )
219         return sal_True;
220     else
221         return sal_False;
222 }
223 
IsInSelection() const224 inline sal_Bool SelectionEngine::IsInSelection() const
225 {
226     if ( nFlags & SELENG_IN_SEL )
227         return sal_True;
228     else
229         return sal_False;
230 }
231 
HasAnchor() const232 inline sal_Bool SelectionEngine::HasAnchor() const
233 {
234     if ( nFlags & SELENG_HAS_ANCH )
235         return sal_True;
236     else
237         return sal_False;
238 }
239 
SetAnchor(sal_Bool bAnchor)240 inline void SelectionEngine::SetAnchor( sal_Bool bAnchor )
241 {
242     if ( bAnchor )
243         nFlags |= SELENG_HAS_ANCH;
244     else
245         nFlags &= (~SELENG_HAS_ANCH);
246 }
247 
248 #endif	// _SV_SELENG_HXX
249 
250