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>
36 #define SELENG_DRAGDROP_TIMEOUT 400
37 #define SELENG_AUTOREPEAT_INTERVAL 50
38 #define SELENG_AUTOREPEAT_INTERVAL_MIN 25
39 #define SELENG_AUTOREPEAT_INTERVAL_MAX 300
41 class VCL_DLLPUBLIC FunctionSet
44 virtual ~FunctionSet() = 0;
46 virtual void BeginDrag() = 0;
48 virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
49 virtual void DestroyAnchor() = 0;
51 // move cursor, at the same time match cursor position to the selection
52 // starting at anchor. true == Ok
53 virtual void SetCursorAtPoint( const Point
& rPointPixel
,
54 bool bDontSelectAtCursor
= false ) = 0;
56 virtual bool IsSelectionAtPoint( const Point
& rPointPixel
) = 0;
57 virtual void DeselectAtPoint( const Point
& rPointPixel
) = 0;
58 // delete anchor & deselect all
59 virtual void DeselectAll() = 0;
63 enum class SelectionEngineFlags
{
71 EXPANDONMOVE
= 0x0100,
75 template<> struct typed_flags
<SelectionEngineFlags
> : is_typed_flags
<SelectionEngineFlags
, 0x01ef> {};
78 class VCL_DLLPUBLIC SelectionEngine
81 FunctionSet
* pFunctionSet
;
82 VclPtr
<vcl::Window
> pWin
;
83 tools::Rectangle aArea
;
84 Timer aWTimer
; // generate fake mouse moves
86 SelectionMode eSelMode
;
87 sal_uLong nUpdateInterval
;
88 sal_uInt16 nLockedMods
;
89 SelectionEngineFlags nFlags
;
90 DECL_DLLPRIVATE_LINK( ImpWatchDog
, Timer
*, void );
92 inline bool ShouldDeselect( bool bModifierKey1
) const;
93 // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
96 SelectionEngine( vcl::Window
* pWindow
,
97 FunctionSet
* pFunctions
= nullptr );
99 // Avoid implicitly defined copy constructors/assignments for the
100 // DLLPUBLIC class (they may require forward-declared classes used
101 // internally to be defined in places using SelectionEngine)
102 SelectionEngine(const SelectionEngine
&) = delete;
103 SelectionEngine(SelectionEngine
&&) = delete;
104 SelectionEngine
& operator=(const SelectionEngine
&) = delete;
105 SelectionEngine
& operator=(SelectionEngine
&&) = delete;
107 // true: Event was processed by Selection Engine
108 bool SelMouseButtonDown( const MouseEvent
& rMEvt
);
109 bool SelMouseButtonUp( const MouseEvent
& rMEvt
);
110 bool SelMouseMove( const MouseEvent
& rMEvt
);
111 //SelMouseButtonDown captures mouse events, SelMouseButtonUp
112 //releases the capture. If you need to release the mouse
113 //capture after SelMouseButtonDown but before
114 //SelMouseButtonUp, e.g. to allow events to go to a
115 //context menu via "Command" which is delivered after
116 //mouse down but before mouse up, then use this
121 void CursorPosChanging( bool bShift
, bool bMod1
);
123 // is needed to generate a Move event via a Timer
124 // when the mouse is outside the area
125 void SetVisibleArea( const tools::Rectangle
& rNewArea
)
126 { aArea
= rNewArea
; }
128 void SetAddMode( bool);
129 bool IsAddMode() const;
131 void AddAlways( bool bOn
);
132 bool IsAlwaysAdding() const;
134 void EnableDrag( bool bOn
);
136 void SetSelectionMode( SelectionMode eMode
);
137 SelectionMode
GetSelectionMode() const { return eSelMode
; }
139 void SetFunctionSet( FunctionSet
* pFuncs
)
140 { pFunctionSet
= pFuncs
; }
141 const FunctionSet
* GetFunctionSet() const { return pFunctionSet
; }
143 const Point
& GetMousePosPixel() const
144 { return aLastMove
.GetPosPixel(); }
145 const MouseEvent
& GetMouseEvent() const { return aLastMove
; }
147 void SetWindow( vcl::Window
*);
148 vcl::Window
* GetWindow() const { return pWin
; }
150 void LockModifiers( sal_uInt16 nModifiers
)
151 { nLockedMods
= nModifiers
; }
152 sal_uInt16
GetLockedModifiers() const { return nLockedMods
; }
154 bool IsInSelection() const;
157 bool Command(const CommandEvent
& rCEvt
);
159 bool HasAnchor() const;
160 void SetAnchor( bool bAnchor
);
162 void SetUpdateInterval( sal_uLong nInterval
);
164 // is switched on in the Ctor
165 void ExpandSelectionOnMouseMove( bool bExpand
= true )
168 nFlags
|= SelectionEngineFlags::EXPANDONMOVE
;
170 nFlags
&= ~SelectionEngineFlags::EXPANDONMOVE
;
174 inline bool SelectionEngine::IsAddMode() const
176 if ( nFlags
& (SelectionEngineFlags::IN_ADD
| SelectionEngineFlags::ADD_ALW
) )
182 inline void SelectionEngine::SetAddMode( bool bNewMode
)
185 nFlags
|= SelectionEngineFlags::IN_ADD
;
187 nFlags
&= ~SelectionEngineFlags::IN_ADD
;
190 inline void SelectionEngine::EnableDrag( bool bOn
)
193 nFlags
|= SelectionEngineFlags::DRG_ENAB
;
195 nFlags
&= ~SelectionEngineFlags::DRG_ENAB
;
198 inline void SelectionEngine::AddAlways( bool bOn
)
201 nFlags
|= SelectionEngineFlags::ADD_ALW
;
203 nFlags
&= ~SelectionEngineFlags::ADD_ALW
;
206 inline bool SelectionEngine::IsAlwaysAdding() const
208 if ( nFlags
& SelectionEngineFlags::ADD_ALW
)
214 inline bool SelectionEngine::IsInSelection() const
216 if ( nFlags
& SelectionEngineFlags::IN_SEL
)
222 inline bool SelectionEngine::HasAnchor() const
224 if ( nFlags
& SelectionEngineFlags::HAS_ANCH
)
230 inline void SelectionEngine::SetAnchor( bool bAnchor
)
233 nFlags
|= SelectionEngineFlags::HAS_ANCH
;
235 nFlags
&= ~SelectionEngineFlags::HAS_ANCH
;
238 #endif // INCLUDED_VCL_SELENG_HXX
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */