1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_SELENG_HXX
21 #define INCLUDED_VCL_SELENG_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/timer.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/vclenum.hxx>
27 #include <o3tl/typed_flags_set.hxx>
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
37 class VCL_DLLPUBLIC FunctionSet
40 virtual ~FunctionSet() = 0;
42 virtual void BeginDrag() = 0;
44 virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
45 virtual void DestroyAnchor() = 0;
47 // move cursor, at the same time match cursor position to the selection
48 // starting at anchor. true == Ok
49 virtual void SetCursorAtPoint( const Point
& rPointPixel
,
50 bool bDontSelectAtCursor
= false ) = 0;
52 virtual bool IsSelectionAtPoint( const Point
& rPointPixel
) = 0;
53 virtual void DeselectAtPoint( const Point
& rPointPixel
) = 0;
54 // delete anchor & deselect all
55 virtual void DeselectAll() = 0;
59 enum class SelectionEngineFlags
{
67 EXPANDONMOVE
= 0x0100,
71 template<> struct typed_flags
<SelectionEngineFlags
> : is_typed_flags
<SelectionEngineFlags
, 0x01ff> {};
74 class VCL_DLLPUBLIC SelectionEngine
77 FunctionSet
* pFunctionSet
;
78 VclPtr
<vcl::Window
> pWin
;
79 tools::Rectangle aArea
;
80 Timer aWTimer
; // generate fake mouse moves
82 SelectionMode eSelMode
;
83 sal_uLong nUpdateInterval
;
84 sal_uInt16 nLockedMods
;
85 SelectionEngineFlags nFlags
;
86 DECL_DLLPRIVATE_LINK( ImpWatchDog
, Timer
*, void );
88 inline bool ShouldDeselect( bool bModifierKey1
) const;
89 // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
92 SelectionEngine( vcl::Window
* pWindow
,
93 FunctionSet
* pFunctions
= nullptr );
96 // true: Event was processed by Selection Engine
97 bool SelMouseButtonDown( const MouseEvent
& rMEvt
);
98 bool SelMouseButtonUp( const MouseEvent
& rMEvt
);
99 bool SelMouseMove( const MouseEvent
& rMEvt
);
100 //SelMouseButtonDown captures mouse events, SelMouseButtonUp
101 //releases the capture. If you need to release the mouse
102 //capture after SelMouseButtonDown but before
103 //SelMouseButtonUp, e.g. to allow events to go to a
104 //context menu via "Command" which is delivered after
105 //mouse down but before mouse up, then use this
110 void CursorPosChanging( bool bShift
, bool bMod1
);
112 // is needed to generate a Move event via a Timer
113 // when the mouse is outside the area
114 void SetVisibleArea( const tools::Rectangle
& rNewArea
)
115 { aArea
= rNewArea
; }
117 void SetAddMode( bool);
118 bool IsAddMode() const;
120 void AddAlways( bool bOn
);
121 bool IsAlwaysAdding() const;
123 void EnableDrag( bool bOn
);
125 void SetSelectionMode( SelectionMode eMode
);
126 SelectionMode
GetSelectionMode() const { return eSelMode
; }
128 void SetFunctionSet( FunctionSet
* pFuncs
)
129 { pFunctionSet
= pFuncs
; }
130 const FunctionSet
* GetFunctionSet() const { return pFunctionSet
; }
132 const Point
& GetMousePosPixel() const
133 { return aLastMove
.GetPosPixel(); }
134 const MouseEvent
& GetMouseEvent() const { return aLastMove
; }
136 void SetWindow( vcl::Window
*);
137 vcl::Window
* GetWindow() const { return pWin
; }
139 void LockModifiers( sal_uInt16 nModifiers
)
140 { nLockedMods
= nModifiers
; }
141 sal_uInt16
GetLockedModifiers() const { return nLockedMods
; }
143 bool IsInSelection() const;
146 void Command( const CommandEvent
& rCEvt
);
148 bool HasAnchor() const;
149 void SetAnchor( bool bAnchor
);
151 void SetUpdateInterval( sal_uLong nInterval
);
153 // is switched on in the Ctor
154 void ExpandSelectionOnMouseMove( bool bExpand
= true )
157 nFlags
|= SelectionEngineFlags::EXPANDONMOVE
;
159 nFlags
&= ~SelectionEngineFlags::EXPANDONMOVE
;
163 inline bool SelectionEngine::IsAddMode() const
165 if ( nFlags
& (SelectionEngineFlags::IN_ADD
| SelectionEngineFlags::ADD_ALW
) )
171 inline void SelectionEngine::SetAddMode( bool bNewMode
)
174 nFlags
|= SelectionEngineFlags::IN_ADD
;
176 nFlags
&= ~SelectionEngineFlags::IN_ADD
;
179 inline void SelectionEngine::EnableDrag( bool bOn
)
182 nFlags
|= SelectionEngineFlags::DRG_ENAB
;
184 nFlags
&= ~SelectionEngineFlags::DRG_ENAB
;
187 inline void SelectionEngine::AddAlways( bool bOn
)
190 nFlags
|= SelectionEngineFlags::ADD_ALW
;
192 nFlags
&= ~SelectionEngineFlags::ADD_ALW
;
195 inline bool SelectionEngine::IsAlwaysAdding() const
197 if ( nFlags
& SelectionEngineFlags::ADD_ALW
)
203 inline bool SelectionEngine::IsInSelection() const
205 if ( nFlags
& SelectionEngineFlags::IN_SEL
)
211 inline bool SelectionEngine::HasAnchor() const
213 if ( nFlags
& SelectionEngineFlags::HAS_ANCH
)
219 inline void SelectionEngine::SetAnchor( bool bAnchor
)
222 nFlags
|= SelectionEngineFlags::HAS_ANCH
;
224 nFlags
&= ~SelectionEngineFlags::HAS_ANCH
;
227 #endif // INCLUDED_VCL_SELENG_HXX
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */