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 : 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 0 : 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 : 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( 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 :
104 : // Keyboard
105 : void CursorPosChanging( bool bShift, bool bMod1 );
106 :
107 : // is needed to generate a Move event via a Timer
108 : // when the mouse is outside the area
109 0 : void SetVisibleArea( const Rectangle rNewArea )
110 0 : { aArea = rNewArea; }
111 : const Rectangle& GetVisibleArea() const { return aArea; }
112 :
113 : void SetAddMode( bool);
114 : bool IsAddMode() const;
115 :
116 : void AddAlways( bool bOn );
117 : bool IsAlwaysAdding() const;
118 :
119 : void EnableDrag( bool bOn );
120 :
121 : void SetSelectionMode( SelectionMode eMode );
122 0 : SelectionMode GetSelectionMode() const { return eSelMode; }
123 :
124 0 : void SetFunctionSet( FunctionSet* pFuncs )
125 0 : { pFunctionSet = pFuncs; }
126 0 : const FunctionSet* GetFunctionSet() const { return pFunctionSet; }
127 :
128 0 : const Point& GetMousePosPixel() const
129 0 : { return aLastMove.GetPosPixel(); }
130 0 : const MouseEvent& GetMouseEvent() const { return aLastMove; }
131 :
132 : void SetWindow( Window*);
133 0 : Window* GetWindow() const { return pWin; }
134 :
135 0 : void LockModifiers( sal_uInt16 nModifiers )
136 0 : { nLockedMods = nModifiers; }
137 0 : sal_uInt16 GetLockedModifiers() const { return nLockedMods; }
138 :
139 : bool IsInSelection() const;
140 : void Reset();
141 :
142 : void Command( const CommandEvent& rCEvt );
143 :
144 : bool HasAnchor() const;
145 : void SetAnchor( bool bAnchor );
146 :
147 : void SetUpdateInterval( sal_uLong nInterval );
148 :
149 : // wird im Ctor eingeschaltet
150 0 : void ExpandSelectionOnMouseMove( bool bExpand = true )
151 : {
152 0 : if( bExpand )
153 0 : nFlags |= SELENG_EXPANDONMOVE;
154 : else
155 0 : nFlags &= ~SELENG_EXPANDONMOVE;
156 0 : }
157 : };
158 :
159 0 : inline bool SelectionEngine::IsAddMode() const
160 : {
161 0 : if ( nFlags & (SELENG_IN_ADD | SELENG_ADD_ALW) )
162 0 : return true;
163 : else
164 0 : return false;
165 : }
166 :
167 0 : inline void SelectionEngine::SetAddMode( bool bNewMode )
168 : {
169 0 : if ( bNewMode )
170 0 : nFlags |= SELENG_IN_ADD;
171 : else
172 0 : nFlags &= (~SELENG_IN_ADD);
173 0 : }
174 :
175 0 : inline void SelectionEngine::EnableDrag( bool bOn )
176 : {
177 0 : if ( bOn )
178 0 : nFlags |= SELENG_DRG_ENAB;
179 : else
180 0 : nFlags &= (~SELENG_DRG_ENAB);
181 0 : }
182 :
183 0 : inline void SelectionEngine::AddAlways( bool bOn )
184 : {
185 0 : if( bOn )
186 0 : nFlags |= SELENG_ADD_ALW;
187 : else
188 0 : nFlags &= (~SELENG_ADD_ALW);
189 0 : }
190 :
191 0 : inline bool SelectionEngine::IsAlwaysAdding() const
192 : {
193 0 : if ( nFlags & SELENG_ADD_ALW )
194 0 : return true;
195 : else
196 0 : return false;
197 : }
198 :
199 0 : inline bool SelectionEngine::IsInSelection() const
200 : {
201 0 : if ( nFlags & SELENG_IN_SEL )
202 0 : return true;
203 : else
204 0 : return false;
205 : }
206 :
207 0 : inline bool SelectionEngine::HasAnchor() const
208 : {
209 0 : if ( nFlags & SELENG_HAS_ANCH )
210 0 : return true;
211 : else
212 0 : return false;
213 : }
214 :
215 0 : inline void SelectionEngine::SetAnchor( bool bAnchor )
216 : {
217 0 : if ( bAnchor )
218 0 : nFlags |= SELENG_HAS_ANCH;
219 : else
220 0 : nFlags &= (~SELENG_HAS_ANCH);
221 0 : }
222 :
223 : #endif // INCLUDED_VCL_SELENG_HXX
224 :
225 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|