Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / vcl / seleng.hxx
blob580ae74177bf585ded3e5f4dbc6d444ee1287ae4
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 <vcl/vclenum.hxx>
27 #include <o3tl/typed_flags_set.hxx>
29 class CommandEvent;
31 namespace vcl {
32 class Window;
35 // Timerticks
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
43 public:
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 {
64 DRG_ENAB = 0x0001,
65 IN_SEL = 0x0002,
66 IN_ADD = 0x0004,
67 ADD_ALW = 0x0008,
68 HAS_ANCH = 0x0020,
69 CMDEVT = 0x0040,
70 WAIT_UPEVT = 0x0080,
71 EXPANDONMOVE = 0x0100,
73 namespace o3tl
75 template<> struct typed_flags<SelectionEngineFlags> : is_typed_flags<SelectionEngineFlags, 0x01ef> {};
78 class VCL_DLLPUBLIC SelectionEngine
80 private:
81 FunctionSet* pFunctionSet;
82 VclPtr<vcl::Window> pWin;
83 tools::Rectangle aArea;
84 Timer aWTimer; // generate fake mouse moves
85 MouseEvent aLastMove;
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
94 public:
96 SelectionEngine( vcl::Window* pWindow,
97 FunctionSet* pFunctions = nullptr );
98 ~SelectionEngine();
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
117 void ReleaseMouse();
118 void CaptureMouse();
120 // Keyboard
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;
155 void Reset();
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 )
167 if( bExpand )
168 nFlags |= SelectionEngineFlags::EXPANDONMOVE;
169 else
170 nFlags &= ~SelectionEngineFlags::EXPANDONMOVE;
174 inline bool SelectionEngine::IsAddMode() const
176 if ( nFlags & (SelectionEngineFlags::IN_ADD | SelectionEngineFlags::ADD_ALW) )
177 return true;
178 else
179 return false;
182 inline void SelectionEngine::SetAddMode( bool bNewMode )
184 if ( bNewMode )
185 nFlags |= SelectionEngineFlags::IN_ADD;
186 else
187 nFlags &= ~SelectionEngineFlags::IN_ADD;
190 inline void SelectionEngine::EnableDrag( bool bOn )
192 if ( bOn )
193 nFlags |= SelectionEngineFlags::DRG_ENAB;
194 else
195 nFlags &= ~SelectionEngineFlags::DRG_ENAB;
198 inline void SelectionEngine::AddAlways( bool bOn )
200 if( bOn )
201 nFlags |= SelectionEngineFlags::ADD_ALW;
202 else
203 nFlags &= ~SelectionEngineFlags::ADD_ALW;
206 inline bool SelectionEngine::IsAlwaysAdding() const
208 if ( nFlags & SelectionEngineFlags::ADD_ALW )
209 return true;
210 else
211 return false;
214 inline bool SelectionEngine::IsInSelection() const
216 if ( nFlags & SelectionEngineFlags::IN_SEL )
217 return true;
218 else
219 return false;
222 inline bool SelectionEngine::HasAnchor() const
224 if ( nFlags & SelectionEngineFlags::HAS_ANCH )
225 return true;
226 else
227 return false;
230 inline void SelectionEngine::SetAnchor( bool bAnchor )
232 if ( bAnchor )
233 nFlags |= SelectionEngineFlags::HAS_ANCH;
234 else
235 nFlags &= ~SelectionEngineFlags::HAS_ANCH;
238 #endif // INCLUDED_VCL_SELENG_HXX
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */