Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / seleng.hxx
blob9b1c269e2582c1f3c7e3485cfb4267cae2decd37
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <o3tl/typed_flags_set.hxx>
28 namespace vcl { class Window; }
29 class CommandEvent;
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
37 enum class SelectionMode { NONE, Single, Range, Multiple };
40 class VCL_DLLPUBLIC FunctionSet
42 public:
43 virtual ~FunctionSet() = 0;
45 virtual void BeginDrag() = 0;
47 virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
48 virtual void DestroyAnchor() = 0;
50 // move cursor, at the same time match cursor position to the selection
51 // starting at anchor. true == Ok
52 virtual bool SetCursorAtPoint( const Point& rPointPixel,
53 bool bDontSelectAtCursor = false ) = 0;
55 virtual bool IsSelectionAtPoint( const Point& rPointPixel ) = 0;
56 virtual void DeselectAtPoint( const Point& rPointPixel ) = 0;
57 // delete anchor & deselect all
58 virtual void DeselectAll() = 0;
62 enum class SelectionEngineFlags {
63 DRG_ENAB = 0x0001,
64 IN_SEL = 0x0002,
65 IN_ADD = 0x0004,
66 ADD_ALW = 0x0008,
67 HAS_ANCH = 0x0020,
68 CMDEVT = 0x0040,
69 WAIT_UPEVT = 0x0080,
70 EXPANDONMOVE = 0x0100,
72 namespace o3tl
74 template<> struct typed_flags<SelectionEngineFlags> : is_typed_flags<SelectionEngineFlags, 0x01ff> {};
77 class VCL_DLLPUBLIC SelectionEngine
79 private:
80 FunctionSet* pFunctionSet;
81 VclPtr<vcl::Window> pWin;
82 tools::Rectangle aArea;
83 Timer aWTimer; // generate fake mouse moves
84 MouseEvent aLastMove;
85 SelectionMode eSelMode;
86 sal_uLong nUpdateInterval;
87 sal_uInt16 nLockedMods;
88 SelectionEngineFlags nFlags;
89 DECL_DLLPRIVATE_LINK( ImpWatchDog, Timer*, void );
91 inline bool ShouldDeselect( bool bModifierKey1 ) const;
92 // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
93 public:
95 SelectionEngine( vcl::Window* pWindow,
96 FunctionSet* pFunctions = nullptr );
97 ~SelectionEngine();
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();
111 // Keyboard
112 void CursorPosChanging( bool bShift, bool bMod1 );
114 // is needed to generate a Move event via a Timer
115 // when the mouse is outside the area
116 void SetVisibleArea( const tools::Rectangle& rNewArea )
117 { aArea = rNewArea; }
119 void SetAddMode( bool);
120 bool IsAddMode() const;
122 void AddAlways( bool bOn );
123 bool IsAlwaysAdding() const;
125 void EnableDrag( bool bOn );
127 void SetSelectionMode( SelectionMode eMode );
128 SelectionMode GetSelectionMode() const { return eSelMode; }
130 void SetFunctionSet( FunctionSet* pFuncs )
131 { pFunctionSet = pFuncs; }
132 const FunctionSet* GetFunctionSet() const { return pFunctionSet; }
134 const Point& GetMousePosPixel() const
135 { return aLastMove.GetPosPixel(); }
136 const MouseEvent& GetMouseEvent() const { return aLastMove; }
138 void SetWindow( vcl::Window*);
139 vcl::Window* GetWindow() const { return pWin; }
141 void LockModifiers( sal_uInt16 nModifiers )
142 { nLockedMods = nModifiers; }
143 sal_uInt16 GetLockedModifiers() const { return nLockedMods; }
145 bool IsInSelection() const;
146 void Reset();
148 void Command( const CommandEvent& rCEvt );
150 bool HasAnchor() const;
151 void SetAnchor( bool bAnchor );
153 void SetUpdateInterval( sal_uLong nInterval );
155 // wird im Ctor eingeschaltet
156 void ExpandSelectionOnMouseMove( bool bExpand = true )
158 if( bExpand )
159 nFlags |= SelectionEngineFlags::EXPANDONMOVE;
160 else
161 nFlags &= ~SelectionEngineFlags::EXPANDONMOVE;
165 inline bool SelectionEngine::IsAddMode() const
167 if ( nFlags & (SelectionEngineFlags::IN_ADD | SelectionEngineFlags::ADD_ALW) )
168 return true;
169 else
170 return false;
173 inline void SelectionEngine::SetAddMode( bool bNewMode )
175 if ( bNewMode )
176 nFlags |= SelectionEngineFlags::IN_ADD;
177 else
178 nFlags &= (~SelectionEngineFlags::IN_ADD);
181 inline void SelectionEngine::EnableDrag( bool bOn )
183 if ( bOn )
184 nFlags |= SelectionEngineFlags::DRG_ENAB;
185 else
186 nFlags &= (~SelectionEngineFlags::DRG_ENAB);
189 inline void SelectionEngine::AddAlways( bool bOn )
191 if( bOn )
192 nFlags |= SelectionEngineFlags::ADD_ALW;
193 else
194 nFlags &= (~SelectionEngineFlags::ADD_ALW);
197 inline bool SelectionEngine::IsAlwaysAdding() const
199 if ( nFlags & SelectionEngineFlags::ADD_ALW )
200 return true;
201 else
202 return false;
205 inline bool SelectionEngine::IsInSelection() const
207 if ( nFlags & SelectionEngineFlags::IN_SEL )
208 return true;
209 else
210 return false;
213 inline bool SelectionEngine::HasAnchor() const
215 if ( nFlags & SelectionEngineFlags::HAS_ANCH )
216 return true;
217 else
218 return false;
221 inline void SelectionEngine::SetAnchor( bool bAnchor )
223 if ( bAnchor )
224 nFlags |= SelectionEngineFlags::HAS_ANCH;
225 else
226 nFlags &= (~SelectionEngineFlags::HAS_ANCH);
229 #endif // INCLUDED_VCL_SELENG_HXX
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */