Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_SELENG_HXX
21 : #define INCLUDED_VCL_SELENG_HXX
22 :
23 : #include <vcl/dllapi.h>
24 : #include <vcl/timer.hxx>
25 : #include <vcl/event.hxx>
26 :
27 : namespace vcl { class Window; }
28 : class CommandEvent;
29 :
30 : // Timerticks
31 : #define SELENG_DRAGDROP_TIMEOUT 400
32 : #define SELENG_AUTOREPEAT_INTERVAL 50
33 : #define SELENG_AUTOREPEAT_INTERVAL_MIN 25
34 : #define SELENG_AUTOREPEAT_INTERVAL_MAX 300
35 :
36 : enum SelectionMode { NO_SELECTION, SINGLE_SELECTION, RANGE_SELECTION, MULTIPLE_SELECTION };
37 :
38 :
39 : // - FunctionSet -
40 :
41 :
42 53147 : class VCL_DLLPUBLIC FunctionSet
43 : {
44 : public:
45 : virtual ~FunctionSet() = 0;
46 :
47 : virtual void BeginDrag() = 0;
48 :
49 : virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
50 : virtual void DestroyAnchor() = 0;
51 :
52 : // move cursor, at the same time match cursor position to the selection
53 : // starting at anchor. true == Ok
54 : virtual bool SetCursorAtPoint( const Point& rPointPixel,
55 : bool bDontSelectAtCursor = false ) = 0;
56 :
57 : virtual bool IsSelectionAtPoint( const Point& rPointPixel ) = 0;
58 : virtual void DeselectAtPoint( const Point& rPointPixel ) = 0;
59 : // delete anchor & deselect all
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_HAS_ANCH 0x0020
72 : #define SELENG_CMDEVT 0x0040
73 : #define SELENG_WAIT_UPEVT 0x0080
74 : #define SELENG_EXPANDONMOVE 0x0100
75 :
76 : class VCL_DLLPUBLIC SelectionEngine
77 : {
78 : private:
79 : FunctionSet* pFunctionSet;
80 : vcl::Window* pWin;
81 : Rectangle aArea;
82 : Timer aWTimer; // generate fake mouse moves
83 : MouseEvent aLastMove;
84 : SelectionMode eSelMode;
85 : sal_uLong nUpdateInterval;
86 : sal_uInt16 nLockedMods;
87 : sal_uInt16 nFlags;
88 : DECL_DLLPRIVATE_LINK( ImpWatchDog, void* );
89 :
90 : inline bool ShouldDeselect( bool bModifierKey1 ) const;
91 : // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
92 : public:
93 :
94 : SelectionEngine( vcl::Window* pWindow,
95 : FunctionSet* pFunctions = NULL,
96 : sal_uLong nAutoRepeatInterval = SELENG_AUTOREPEAT_INTERVAL );
97 : ~SelectionEngine();
98 :
99 : // true: Event was processed by Selection Engine
100 : bool SelMouseButtonDown( const MouseEvent& rMEvt );
101 : bool SelMouseButtonUp( const MouseEvent& rMEvt );
102 : bool SelMouseMove( const MouseEvent& rMEvt );
103 : //SelMouseButtonDown captures mouse events, SelMouseButtonUp
104 : //releases the capture. If you need to release the mouse
105 : //capture after SelMouseButtonDown but before
106 : //SelMouseButtonUp, e.g. to allow events to go to a
107 : //context menu via "Command" which is delivered after
108 : //mouse down but before mouse up, then use this
109 : void ReleaseMouse();
110 :
111 : // Keyboard
112 : void CursorPosChanging( bool bShift, bool bMod1 );
113 :
114 : // is needed to generate a Move event via a Timer
115 : // when the mouse is outside the area
116 2636 : void SetVisibleArea( const Rectangle rNewArea )
117 2636 : { aArea = rNewArea; }
118 : const Rectangle& GetVisibleArea() const { return aArea; }
119 :
120 : void SetAddMode( bool);
121 : bool IsAddMode() const;
122 :
123 : void AddAlways( bool bOn );
124 : bool IsAlwaysAdding() const;
125 :
126 : void EnableDrag( bool bOn );
127 :
128 : void SetSelectionMode( SelectionMode eMode );
129 258 : SelectionMode GetSelectionMode() const { return eSelMode; }
130 :
131 51939 : void SetFunctionSet( FunctionSet* pFuncs )
132 51939 : { pFunctionSet = pFuncs; }
133 164 : const FunctionSet* GetFunctionSet() const { return pFunctionSet; }
134 :
135 0 : const Point& GetMousePosPixel() const
136 0 : { return aLastMove.GetPosPixel(); }
137 0 : const MouseEvent& GetMouseEvent() const { return aLastMove; }
138 :
139 : void SetWindow( vcl::Window*);
140 0 : vcl::Window* GetWindow() const { return pWin; }
141 :
142 0 : void LockModifiers( sal_uInt16 nModifiers )
143 0 : { nLockedMods = nModifiers; }
144 374 : sal_uInt16 GetLockedModifiers() const { return nLockedMods; }
145 :
146 : bool IsInSelection() const;
147 : void Reset();
148 :
149 : void Command( const CommandEvent& rCEvt );
150 :
151 : bool HasAnchor() const;
152 : void SetAnchor( bool bAnchor );
153 :
154 : void SetUpdateInterval( sal_uLong nInterval );
155 :
156 : // wird im Ctor eingeschaltet
157 896 : void ExpandSelectionOnMouseMove( bool bExpand = true )
158 : {
159 896 : if( bExpand )
160 268 : nFlags |= SELENG_EXPANDONMOVE;
161 : else
162 628 : nFlags &= ~SELENG_EXPANDONMOVE;
163 896 : }
164 : };
165 :
166 90 : inline bool SelectionEngine::IsAddMode() const
167 : {
168 90 : if ( nFlags & (SELENG_IN_ADD | SELENG_ADD_ALW) )
169 0 : return true;
170 : else
171 90 : return false;
172 : }
173 :
174 0 : inline void SelectionEngine::SetAddMode( bool bNewMode )
175 : {
176 0 : if ( bNewMode )
177 0 : nFlags |= SELENG_IN_ADD;
178 : else
179 0 : nFlags &= (~SELENG_IN_ADD);
180 0 : }
181 :
182 53509 : inline void SelectionEngine::EnableDrag( bool bOn )
183 : {
184 53509 : if ( bOn )
185 52695 : nFlags |= SELENG_DRG_ENAB;
186 : else
187 814 : nFlags &= (~SELENG_DRG_ENAB);
188 53509 : }
189 :
190 0 : inline void SelectionEngine::AddAlways( bool bOn )
191 : {
192 0 : if( bOn )
193 0 : nFlags |= SELENG_ADD_ALW;
194 : else
195 0 : nFlags &= (~SELENG_ADD_ALW);
196 0 : }
197 :
198 0 : inline bool SelectionEngine::IsAlwaysAdding() const
199 : {
200 0 : if ( nFlags & SELENG_ADD_ALW )
201 0 : return true;
202 : else
203 0 : return false;
204 : }
205 :
206 0 : inline bool SelectionEngine::IsInSelection() const
207 : {
208 0 : if ( nFlags & SELENG_IN_SEL )
209 0 : return true;
210 : else
211 0 : return false;
212 : }
213 :
214 0 : inline bool SelectionEngine::HasAnchor() const
215 : {
216 0 : if ( nFlags & SELENG_HAS_ANCH )
217 0 : return true;
218 : else
219 0 : return false;
220 : }
221 :
222 0 : inline void SelectionEngine::SetAnchor( bool bAnchor )
223 : {
224 0 : if ( bAnchor )
225 0 : nFlags |= SELENG_HAS_ANCH;
226 : else
227 0 : nFlags &= (~SELENG_HAS_ANCH);
228 0 : }
229 :
230 : #endif // INCLUDED_VCL_SELENG_HXX
231 :
232 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|