Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SV_SELENG_HXX
30 : : #define _SV_SELENG_HXX
31 : :
32 : : #include <vcl/dllapi.h>
33 : : #include <vcl/timer.hxx>
34 : : #include <vcl/event.hxx>
35 : :
36 : : class Window;
37 : : class CommandEvent;
38 : :
39 : : // Timerticks
40 : : #define SELENG_DRAGDROP_TIMEOUT 400
41 : : #define SELENG_AUTOREPEAT_INTERVAL 50
42 : : #define SELENG_AUTOREPEAT_INTERVAL_MIN 25
43 : : #define SELENG_AUTOREPEAT_INTERVAL_MAX 300
44 : :
45 : : enum SelectionMode { NO_SELECTION, SINGLE_SELECTION, RANGE_SELECTION, MULTIPLE_SELECTION };
46 : :
47 : : // ---------------
48 : : // - FunctionSet -
49 : : // ---------------
50 : :
51 : 31306 : class VCL_DLLPUBLIC FunctionSet
52 : : {
53 : : public:
54 : : virtual ~FunctionSet() = 0;
55 : :
56 : : virtual void BeginDrag() = 0;
57 : :
58 : : virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
59 : : virtual void DestroyAnchor() = 0;
60 : :
61 : : // move cursor, at the same time match cursor position to the selection
62 : : // starting at anchor. sal_True == Ok
63 : : virtual sal_Bool SetCursorAtPoint( const Point& rPointPixel,
64 : : sal_Bool bDontSelectAtCursor = sal_False ) = 0;
65 : :
66 : : virtual sal_Bool IsSelectionAtPoint( const Point& rPointPixel ) = 0;
67 : : virtual void DeselectAtPoint( const Point& rPointPixel ) = 0;
68 : : // delete anchor & deselect all
69 : : virtual void DeselectAll() = 0;
70 : : };
71 : :
72 : : // -------------------
73 : : // - SelectionEngine -
74 : : // -------------------
75 : :
76 : : #define SELENG_DRG_ENAB 0x0001
77 : : #define SELENG_IN_SEL 0x0002
78 : : #define SELENG_IN_ADD 0x0004
79 : : #define SELENG_ADD_ALW 0x0008
80 : : #define SELENG_HAS_ANCH 0x0020
81 : : #define SELENG_CMDEVT 0x0040
82 : : #define SELENG_WAIT_UPEVT 0x0080
83 : : #define SELENG_EXPANDONMOVE 0x0100
84 : :
85 : : class VCL_DLLPUBLIC SelectionEngine
86 : : {
87 : : private:
88 : : FunctionSet* pFunctionSet;
89 : : Window* pWin;
90 : : Rectangle aArea;
91 : : Timer aWTimer; // generate fake mouse moves
92 : : MouseEvent aLastMove;
93 : : SelectionMode eSelMode;
94 : : sal_uLong nUpdateInterval;
95 : : // sensitivity of mouse moves during a selection
96 : : sal_uInt16 nMouseSensitivity;
97 : : sal_uInt16 nLockedMods;
98 : : sal_uInt16 nFlags;
99 : : DECL_DLLPRIVATE_LINK( ImpWatchDog, void* );
100 : :
101 : : inline sal_Bool ShouldDeselect( sal_Bool bModifierKey1 ) const;
102 : : // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
103 : : public:
104 : :
105 : : SelectionEngine( Window* pWindow,
106 : : FunctionSet* pFunctions = NULL,
107 : : sal_uLong nAutoRepeatInterval = SELENG_AUTOREPEAT_INTERVAL );
108 : : ~SelectionEngine();
109 : :
110 : : // sal_True: Event was processed by Selection Engine
111 : : sal_Bool SelMouseButtonDown( const MouseEvent& rMEvt );
112 : : sal_Bool SelMouseButtonUp( const MouseEvent& rMEvt );
113 : : sal_Bool SelMouseMove( const MouseEvent& rMEvt );
114 : :
115 : : // Keyboard
116 : : void CursorPosChanging( sal_Bool bShift, sal_Bool bMod1 );
117 : :
118 : : // is needed to generate a Move event via a Timer
119 : : // when the mouse is outside the area
120 : 625 : void SetVisibleArea( const Rectangle rNewArea )
121 : 625 : { aArea = rNewArea; }
122 : : const Rectangle& GetVisibleArea() const { return aArea; }
123 : :
124 : : void SetAddMode( sal_Bool);
125 : : sal_Bool IsAddMode() const;
126 : :
127 : : void AddAlways( sal_Bool bOn );
128 : : sal_Bool IsAlwaysAdding() const;
129 : :
130 : : void EnableDrag( sal_Bool bOn );
131 : :
132 : : void SetSelectionMode( SelectionMode eMode );
133 : 126 : SelectionMode GetSelectionMode() const { return eSelMode; }
134 : :
135 : 30758 : void SetFunctionSet( FunctionSet* pFuncs )
136 : 30758 : { pFunctionSet = pFuncs; }
137 : 148 : const FunctionSet* GetFunctionSet() const { return pFunctionSet; }
138 : :
139 : : void SetMouseSensitivity( sal_uInt16 nSensitivity )
140 : : { nMouseSensitivity = nSensitivity; }
141 : : sal_uInt16 GetMouseSensitivity() const
142 : : { return nMouseSensitivity; }
143 : :
144 : 0 : const Point& GetMousePosPixel() const
145 : 0 : { return aLastMove.GetPosPixel(); }
146 : 0 : const MouseEvent& GetMouseEvent() const { return aLastMove; }
147 : :
148 : : void SetWindow( Window*);
149 : 0 : Window* GetWindow() const { return pWin; }
150 : :
151 : 0 : void LockModifiers( sal_uInt16 nModifiers )
152 : 0 : { nLockedMods = nModifiers; }
153 : 247 : sal_uInt16 GetLockedModifiers() const { return nLockedMods; }
154 : :
155 : : sal_Bool IsInSelection() const;
156 : : void Reset();
157 : :
158 : : void Command( const CommandEvent& rCEvt );
159 : :
160 : : sal_Bool HasAnchor() const;
161 : : void SetAnchor( sal_Bool bAnchor );
162 : :
163 : : void SetUpdateInterval( sal_uLong nInterval );
164 : :
165 : : // wird im Ctor eingeschaltet
166 : 246 : void ExpandSelectionOnMouseMove( sal_Bool bExpand = sal_True )
167 : : {
168 [ + + ]: 246 : if( bExpand )
169 : 124 : nFlags |= SELENG_EXPANDONMOVE;
170 : : else
171 : 122 : nFlags &= ~SELENG_EXPANDONMOVE;
172 : 246 : }
173 : : };
174 : :
175 : 20 : inline sal_Bool SelectionEngine::IsAddMode() const
176 : : {
177 [ - + ]: 20 : if ( nFlags & (SELENG_IN_ADD | SELENG_ADD_ALW) )
178 : 0 : return sal_True;
179 : : else
180 : 20 : return sal_False;
181 : : }
182 : :
183 : 0 : inline void SelectionEngine::SetAddMode( sal_Bool bNewMode )
184 : : {
185 [ # # ]: 0 : if ( bNewMode )
186 : 0 : nFlags |= SELENG_IN_ADD;
187 : : else
188 : 0 : nFlags &= (~SELENG_IN_ADD);
189 : 0 : }
190 : :
191 : 31308 : inline void SelectionEngine::EnableDrag( sal_Bool bOn )
192 : : {
193 [ + + ]: 31308 : if ( bOn )
194 : 30955 : nFlags |= SELENG_DRG_ENAB;
195 : : else
196 : 353 : nFlags &= (~SELENG_DRG_ENAB);
197 : 31308 : }
198 : :
199 : 0 : inline void SelectionEngine::AddAlways( sal_Bool bOn )
200 : : {
201 [ # # ]: 0 : if( bOn )
202 : 0 : nFlags |= SELENG_ADD_ALW;
203 : : else
204 : 0 : nFlags &= (~SELENG_ADD_ALW);
205 : 0 : }
206 : :
207 : 0 : inline sal_Bool SelectionEngine::IsAlwaysAdding() const
208 : : {
209 [ # # ]: 0 : if ( nFlags & SELENG_ADD_ALW )
210 : 0 : return sal_True;
211 : : else
212 : 0 : return sal_False;
213 : : }
214 : :
215 : 0 : inline sal_Bool SelectionEngine::IsInSelection() const
216 : : {
217 [ # # ]: 0 : if ( nFlags & SELENG_IN_SEL )
218 : 0 : return sal_True;
219 : : else
220 : 0 : return sal_False;
221 : : }
222 : :
223 : 0 : inline sal_Bool SelectionEngine::HasAnchor() const
224 : : {
225 [ # # ]: 0 : if ( nFlags & SELENG_HAS_ANCH )
226 : 0 : return sal_True;
227 : : else
228 : 0 : return sal_False;
229 : : }
230 : :
231 : 0 : inline void SelectionEngine::SetAnchor( sal_Bool bAnchor )
232 : : {
233 [ # # ]: 0 : if ( bAnchor )
234 : 0 : nFlags |= SELENG_HAS_ANCH;
235 : : else
236 : 0 : nFlags &= (~SELENG_HAS_ANCH);
237 : 0 : }
238 : :
239 : : #endif // _SV_SELENG_HXX
240 : :
241 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|