Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / seleng.hxx
blobd5b9ef572d28ec3d86fe7f25a45fa8e25dfa315d
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 SelectionMode { NO_SELECTION, SINGLE_SELECTION, RANGE_SELECTION, MULTIPLE_SELECTION };
40 // - FunctionSet -
43 class VCL_DLLPUBLIC FunctionSet
45 public:
46 virtual ~FunctionSet() = 0;
48 virtual void BeginDrag() = 0;
50 virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
51 virtual void DestroyAnchor() = 0;
53 // move cursor, at the same time match cursor position to the selection
54 // starting at anchor. true == Ok
55 virtual bool SetCursorAtPoint( const Point& rPointPixel,
56 bool bDontSelectAtCursor = false ) = 0;
58 virtual bool IsSelectionAtPoint( const Point& rPointPixel ) = 0;
59 virtual void DeselectAtPoint( const Point& rPointPixel ) = 0;
60 // delete anchor & deselect all
61 virtual void DeselectAll() = 0;
65 // - SelectionEngine -
67 enum class SelectionEngineFlags {
68 DRG_ENAB = 0x0001,
69 IN_SEL = 0x0002,
70 IN_ADD = 0x0004,
71 ADD_ALW = 0x0008,
72 HAS_ANCH = 0x0020,
73 CMDEVT = 0x0040,
74 WAIT_UPEVT = 0x0080,
75 EXPANDONMOVE = 0x0100,
77 namespace o3tl
79 template<> struct typed_flags<SelectionEngineFlags> : is_typed_flags<SelectionEngineFlags, 0x01ff> {};
82 class VCL_DLLPUBLIC SelectionEngine
84 private:
85 FunctionSet* pFunctionSet;
86 VclPtr<vcl::Window> pWin;
87 Rectangle aArea;
88 Timer aWTimer; // generate fake mouse moves
89 MouseEvent aLastMove;
90 SelectionMode eSelMode;
91 sal_uLong nUpdateInterval;
92 sal_uInt16 nLockedMods;
93 SelectionEngineFlags nFlags;
94 DECL_DLLPRIVATE_LINK_TYPED( ImpWatchDog, Timer*, void );
96 inline bool ShouldDeselect( bool bModifierKey1 ) const;
97 // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
98 public:
100 SelectionEngine( vcl::Window* pWindow,
101 FunctionSet* pFunctions = NULL,
102 sal_uLong nAutoRepeatInterval = SELENG_AUTOREPEAT_INTERVAL );
103 ~SelectionEngine();
105 // true: Event was processed by Selection Engine
106 bool SelMouseButtonDown( const MouseEvent& rMEvt );
107 bool SelMouseButtonUp( const MouseEvent& rMEvt );
108 bool SelMouseMove( const MouseEvent& rMEvt );
109 //SelMouseButtonDown captures mouse events, SelMouseButtonUp
110 //releases the capture. If you need to release the mouse
111 //capture after SelMouseButtonDown but before
112 //SelMouseButtonUp, e.g. to allow events to go to a
113 //context menu via "Command" which is delivered after
114 //mouse down but before mouse up, then use this
115 void ReleaseMouse();
117 // Keyboard
118 void CursorPosChanging( bool bShift, bool bMod1 );
120 // is needed to generate a Move event via a Timer
121 // when the mouse is outside the area
122 void SetVisibleArea( const Rectangle& rNewArea )
123 { aArea = rNewArea; }
124 const Rectangle& GetVisibleArea() const { return aArea; }
126 void SetAddMode( bool);
127 bool IsAddMode() const;
129 void AddAlways( bool bOn );
130 bool IsAlwaysAdding() const;
132 void EnableDrag( bool bOn );
134 void SetSelectionMode( SelectionMode eMode );
135 SelectionMode GetSelectionMode() const { return eSelMode; }
137 void SetFunctionSet( FunctionSet* pFuncs )
138 { pFunctionSet = pFuncs; }
139 const FunctionSet* GetFunctionSet() const { return pFunctionSet; }
141 const Point& GetMousePosPixel() const
142 { return aLastMove.GetPosPixel(); }
143 const MouseEvent& GetMouseEvent() const { return aLastMove; }
145 void SetWindow( vcl::Window*);
146 vcl::Window* GetWindow() const { return pWin; }
148 void LockModifiers( sal_uInt16 nModifiers )
149 { nLockedMods = nModifiers; }
150 sal_uInt16 GetLockedModifiers() const { return nLockedMods; }
152 bool IsInSelection() const;
153 void Reset();
155 void Command( const CommandEvent& rCEvt );
157 bool HasAnchor() const;
158 void SetAnchor( bool bAnchor );
160 void SetUpdateInterval( sal_uLong nInterval );
162 // wird im Ctor eingeschaltet
163 void ExpandSelectionOnMouseMove( bool bExpand = true )
165 if( bExpand )
166 nFlags |= SelectionEngineFlags::EXPANDONMOVE;
167 else
168 nFlags &= ~SelectionEngineFlags::EXPANDONMOVE;
172 inline bool SelectionEngine::IsAddMode() const
174 if ( nFlags & (SelectionEngineFlags::IN_ADD | SelectionEngineFlags::ADD_ALW) )
175 return true;
176 else
177 return false;
180 inline void SelectionEngine::SetAddMode( bool bNewMode )
182 if ( bNewMode )
183 nFlags |= SelectionEngineFlags::IN_ADD;
184 else
185 nFlags &= (~SelectionEngineFlags::IN_ADD);
188 inline void SelectionEngine::EnableDrag( bool bOn )
190 if ( bOn )
191 nFlags |= SelectionEngineFlags::DRG_ENAB;
192 else
193 nFlags &= (~SelectionEngineFlags::DRG_ENAB);
196 inline void SelectionEngine::AddAlways( bool bOn )
198 if( bOn )
199 nFlags |= SelectionEngineFlags::ADD_ALW;
200 else
201 nFlags &= (~SelectionEngineFlags::ADD_ALW);
204 inline bool SelectionEngine::IsAlwaysAdding() const
206 if ( nFlags & SelectionEngineFlags::ADD_ALW )
207 return true;
208 else
209 return false;
212 inline bool SelectionEngine::IsInSelection() const
214 if ( nFlags & SelectionEngineFlags::IN_SEL )
215 return true;
216 else
217 return false;
220 inline bool SelectionEngine::HasAnchor() const
222 if ( nFlags & SelectionEngineFlags::HAS_ANCH )
223 return true;
224 else
225 return false;
228 inline void SelectionEngine::SetAnchor( bool bAnchor )
230 if ( bAnchor )
231 nFlags |= SelectionEngineFlags::HAS_ANCH;
232 else
233 nFlags &= (~SelectionEngineFlags::HAS_ANCH);
236 #endif // INCLUDED_VCL_SELENG_HXX
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */