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 : #include <o3tl/typed_flags_set.hxx>
27 :
28 : namespace vcl { class Window; }
29 : class CommandEvent;
30 :
31 : // Timerticks
32 : #define SELENG_DRAGDROP_TIMEOUT 400
33 : #define SELENG_AUTOREPEAT_INTERVAL 50
34 : #define SELENG_AUTOREPEAT_INTERVAL_MIN 25
35 : #define SELENG_AUTOREPEAT_INTERVAL_MAX 300
36 :
37 : enum SelectionMode { NO_SELECTION, SINGLE_SELECTION, RANGE_SELECTION, MULTIPLE_SELECTION };
38 :
39 :
40 : // - FunctionSet -
41 :
42 :
43 42879 : class VCL_DLLPUBLIC FunctionSet
44 : {
45 : public:
46 : virtual ~FunctionSet() = 0;
47 :
48 : virtual void BeginDrag() = 0;
49 :
50 : virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
51 : virtual void DestroyAnchor() = 0;
52 :
53 : // move cursor, at the same time match cursor position to the selection
54 : // starting at anchor. true == Ok
55 : virtual bool SetCursorAtPoint( const Point& rPointPixel,
56 : bool bDontSelectAtCursor = false ) = 0;
57 :
58 : virtual bool IsSelectionAtPoint( const Point& rPointPixel ) = 0;
59 : virtual void DeselectAtPoint( const Point& rPointPixel ) = 0;
60 : // delete anchor & deselect all
61 : virtual void DeselectAll() = 0;
62 : };
63 :
64 :
65 : // - SelectionEngine -
66 :
67 : enum class SelectionEngineFlags {
68 : DRG_ENAB = 0x0001,
69 : IN_SEL = 0x0002,
70 : IN_ADD = 0x0004,
71 : ADD_ALW = 0x0008,
72 : HAS_ANCH = 0x0020,
73 : CMDEVT = 0x0040,
74 : WAIT_UPEVT = 0x0080,
75 : EXPANDONMOVE = 0x0100,
76 : };
77 : namespace o3tl
78 : {
79 : template<> struct typed_flags<SelectionEngineFlags> : is_typed_flags<SelectionEngineFlags, 0x01ff> {};
80 : }
81 :
82 : class VCL_DLLPUBLIC SelectionEngine
83 : {
84 : private:
85 : FunctionSet* pFunctionSet;
86 : VclPtr<vcl::Window> pWin;
87 : Rectangle aArea;
88 : Timer aWTimer; // generate fake mouse moves
89 : MouseEvent aLastMove;
90 : SelectionMode eSelMode;
91 : sal_uLong nUpdateInterval;
92 : sal_uInt16 nLockedMods;
93 : SelectionEngineFlags nFlags;
94 : DECL_DLLPRIVATE_LINK_TYPED( ImpWatchDog, Timer*, void );
95 :
96 : inline bool ShouldDeselect( bool bModifierKey1 ) const;
97 : // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
98 : public:
99 :
100 : SelectionEngine( vcl::Window* pWindow,
101 : FunctionSet* pFunctions = NULL,
102 : sal_uLong nAutoRepeatInterval = SELENG_AUTOREPEAT_INTERVAL );
103 : ~SelectionEngine();
104 :
105 : // true: Event was processed by Selection Engine
106 : bool SelMouseButtonDown( const MouseEvent& rMEvt );
107 : bool SelMouseButtonUp( const MouseEvent& rMEvt );
108 : bool SelMouseMove( const MouseEvent& rMEvt );
109 : //SelMouseButtonDown captures mouse events, SelMouseButtonUp
110 : //releases the capture. If you need to release the mouse
111 : //capture after SelMouseButtonDown but before
112 : //SelMouseButtonUp, e.g. to allow events to go to a
113 : //context menu via "Command" which is delivered after
114 : //mouse down but before mouse up, then use this
115 : void ReleaseMouse();
116 :
117 : // Keyboard
118 : void CursorPosChanging( bool bShift, bool bMod1 );
119 :
120 : // is needed to generate a Move event via a Timer
121 : // when the mouse is outside the area
122 250 : void SetVisibleArea( const Rectangle& rNewArea )
123 250 : { aArea = rNewArea; }
124 : const Rectangle& GetVisibleArea() const { return aArea; }
125 :
126 : void SetAddMode( bool);
127 : bool IsAddMode() const;
128 :
129 : void AddAlways( bool bOn );
130 : bool IsAlwaysAdding() const;
131 :
132 : void EnableDrag( bool bOn );
133 :
134 : void SetSelectionMode( SelectionMode eMode );
135 24 : SelectionMode GetSelectionMode() const { return eSelMode; }
136 :
137 42130 : void SetFunctionSet( FunctionSet* pFuncs )
138 42130 : { pFunctionSet = pFuncs; }
139 108 : const FunctionSet* GetFunctionSet() const { return pFunctionSet; }
140 :
141 0 : const Point& GetMousePosPixel() const
142 0 : { return aLastMove.GetPosPixel(); }
143 0 : const MouseEvent& GetMouseEvent() const { return aLastMove; }
144 :
145 : void SetWindow( vcl::Window*);
146 0 : vcl::Window* GetWindow() const { return pWin; }
147 :
148 0 : void LockModifiers( sal_uInt16 nModifiers )
149 0 : { nLockedMods = nModifiers; }
150 185 : sal_uInt16 GetLockedModifiers() const { return nLockedMods; }
151 :
152 : bool IsInSelection() const;
153 : void Reset();
154 :
155 : void Command( const CommandEvent& rCEvt );
156 :
157 : bool HasAnchor() const;
158 : void SetAnchor( bool bAnchor );
159 :
160 : void SetUpdateInterval( sal_uLong nInterval );
161 :
162 : // wird im Ctor eingeschaltet
163 82 : void ExpandSelectionOnMouseMove( bool bExpand = true )
164 : {
165 82 : if( bExpand )
166 29 : nFlags |= SelectionEngineFlags::EXPANDONMOVE;
167 : else
168 53 : nFlags &= ~SelectionEngineFlags::EXPANDONMOVE;
169 82 : }
170 : };
171 :
172 191 : inline bool SelectionEngine::IsAddMode() const
173 : {
174 191 : if ( nFlags & (SelectionEngineFlags::IN_ADD | SelectionEngineFlags::ADD_ALW) )
175 0 : return true;
176 : else
177 191 : return false;
178 : }
179 :
180 0 : inline void SelectionEngine::SetAddMode( bool bNewMode )
181 : {
182 0 : if ( bNewMode )
183 0 : nFlags |= SelectionEngineFlags::IN_ADD;
184 : else
185 0 : nFlags &= (~SelectionEngineFlags::IN_ADD);
186 0 : }
187 :
188 42904 : inline void SelectionEngine::EnableDrag( bool bOn )
189 : {
190 42904 : if ( bOn )
191 42527 : nFlags |= SelectionEngineFlags::DRG_ENAB;
192 : else
193 377 : nFlags &= (~SelectionEngineFlags::DRG_ENAB);
194 42904 : }
195 :
196 0 : inline void SelectionEngine::AddAlways( bool bOn )
197 : {
198 0 : if( bOn )
199 0 : nFlags |= SelectionEngineFlags::ADD_ALW;
200 : else
201 0 : nFlags &= (~SelectionEngineFlags::ADD_ALW);
202 0 : }
203 :
204 0 : inline bool SelectionEngine::IsAlwaysAdding() const
205 : {
206 0 : if ( nFlags & SelectionEngineFlags::ADD_ALW )
207 0 : return true;
208 : else
209 0 : return false;
210 : }
211 :
212 15 : inline bool SelectionEngine::IsInSelection() const
213 : {
214 15 : if ( nFlags & SelectionEngineFlags::IN_SEL )
215 3 : return true;
216 : else
217 12 : return false;
218 : }
219 :
220 1 : inline bool SelectionEngine::HasAnchor() const
221 : {
222 1 : if ( nFlags & SelectionEngineFlags::HAS_ANCH )
223 0 : return true;
224 : else
225 1 : return false;
226 : }
227 :
228 0 : inline void SelectionEngine::SetAnchor( bool bAnchor )
229 : {
230 0 : if ( bAnchor )
231 0 : nFlags |= SelectionEngineFlags::HAS_ANCH;
232 : else
233 0 : nFlags &= (~SelectionEngineFlags::HAS_ANCH);
234 0 : }
235 :
236 : #endif // INCLUDED_VCL_SELENG_HXX
237 :
238 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|