LibreOffice Module vcl (master)  1
seleng.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_SELENG_HXX
21 #define INCLUDED_VCL_SELENG_HXX
22 
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>
28 
29 class CommandEvent;
30 
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
36 
38 {
39 public:
40  virtual ~FunctionSet() = 0;
41 
42  virtual void BeginDrag() = 0;
43 
44  virtual void CreateAnchor() = 0; // Anker-Pos := Cursor-Pos
45  virtual void DestroyAnchor() = 0;
46 
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;
51 
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;
56 };
57 
58 
60  DRG_ENAB = 0x0001,
61  IN_SEL = 0x0002,
62  IN_ADD = 0x0004,
63  ADD_ALW = 0x0008,
64  HAS_ANCH = 0x0020,
65  CMDEVT = 0x0040,
66  WAIT_UPEVT = 0x0080,
67  EXPANDONMOVE = 0x0100,
68 };
69 namespace o3tl
70 {
71  template<> struct typed_flags<SelectionEngineFlags> : is_typed_flags<SelectionEngineFlags, 0x01ff> {};
72 }
73 
75 {
76 private:
80  Timer aWTimer; // generate fake mouse moves
84  sal_uInt16 nLockedMods;
86  DECL_DLLPRIVATE_LINK( ImpWatchDog, Timer*, void );
87 
88  inline bool ShouldDeselect( bool bModifierKey1 ) const;
89  // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
90 public:
91 
92  SelectionEngine( vcl::Window* pWindow,
93  FunctionSet* pFunctions = nullptr );
94  ~SelectionEngine();
95 
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
106  void ReleaseMouse();
107  void CaptureMouse();
108 
109  // Keyboard
110  void CursorPosChanging( bool bShift, bool bMod1 );
111 
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; }
116 
117  void SetAddMode( bool);
118  bool IsAddMode() const;
119 
120  void AddAlways( bool bOn );
121  bool IsAlwaysAdding() const;
122 
123  void EnableDrag( bool bOn );
124 
125  void SetSelectionMode( SelectionMode eMode );
126  SelectionMode GetSelectionMode() const { return eSelMode; }
127 
128  void SetFunctionSet( FunctionSet* pFuncs )
129  { pFunctionSet = pFuncs; }
130  const FunctionSet* GetFunctionSet() const { return pFunctionSet; }
131 
132  const Point& GetMousePosPixel() const
133  { return aLastMove.GetPosPixel(); }
134  const MouseEvent& GetMouseEvent() const { return aLastMove; }
135 
136  void SetWindow( vcl::Window*);
137  vcl::Window* GetWindow() const { return pWin; }
138 
139  void LockModifiers( sal_uInt16 nModifiers )
140  { nLockedMods = nModifiers; }
141  sal_uInt16 GetLockedModifiers() const { return nLockedMods; }
142 
143  bool IsInSelection() const;
144  void Reset();
145 
146  void Command( const CommandEvent& rCEvt );
147 
148  bool HasAnchor() const;
149  void SetAnchor( bool bAnchor );
150 
151  void SetUpdateInterval( sal_uLong nInterval );
152 
153  // is switched on in the Ctor
154  void ExpandSelectionOnMouseMove( bool bExpand = true )
155  {
156  if( bExpand )
158  else
160  }
161 };
162 
163 inline bool SelectionEngine::IsAddMode() const
164 {
166  return true;
167  else
168  return false;
169 }
170 
171 inline void SelectionEngine::SetAddMode( bool bNewMode )
172 {
173  if ( bNewMode )
175  else
177 }
178 
179 inline void SelectionEngine::EnableDrag( bool bOn )
180 {
181  if ( bOn )
183  else
185 }
186 
187 inline void SelectionEngine::AddAlways( bool bOn )
188 {
189  if( bOn )
191  else
193 }
194 
196 {
198  return true;
199  else
200  return false;
201 }
202 
204 {
206  return true;
207  else
208  return false;
209 }
210 
211 inline bool SelectionEngine::HasAnchor() const
212 {
214  return true;
215  else
216  return false;
217 }
218 
219 inline void SelectionEngine::SetAnchor( bool bAnchor )
220 {
221  if ( bAnchor )
223  else
225 }
226 
227 #endif // INCLUDED_VCL_SELENG_HXX
228 
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Rectangle aArea
Definition: seleng.hxx:79
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
SelectionMode
Definition: vclenum.hxx:26
VclPtr< vcl::Window > pWin
Definition: seleng.hxx:78
bool IsInSelection() const
Definition: seleng.hxx:203
void EnableDrag(bool bOn)
Definition: seleng.hxx:179
sal_uInt16 GetLockedModifiers() const
Definition: seleng.hxx:141
MouseEvent aLastMove
Definition: seleng.hxx:81
const Point & GetMousePosPixel() const
Definition: seleng.hxx:132
const FunctionSet * GetFunctionSet() const
Definition: seleng.hxx:130
void SetAnchor(bool bAnchor)
Definition: seleng.hxx:219
void SetAddMode(bool)
Definition: seleng.hxx:171
void ExpandSelectionOnMouseMove(bool bExpand=true)
Definition: seleng.hxx:154
vcl::Window * GetWindow() const
Definition: seleng.hxx:137
Timer aWTimer
Definition: seleng.hxx:80
bool IsAddMode() const
Definition: seleng.hxx:163
const MouseEvent & GetMouseEvent() const
Definition: seleng.hxx:134
void SetVisibleArea(const tools::Rectangle &rNewArea)
Definition: seleng.hxx:114
sal_uInt16 nLockedMods
Definition: seleng.hxx:84
SelectionMode eSelMode
Definition: seleng.hxx:82
SelectionEngineFlags nFlags
Definition: seleng.hxx:85
sal_uLong nUpdateInterval
Definition: seleng.hxx:83
void AddAlways(bool bOn)
Definition: seleng.hxx:187
const Point & GetPosPixel() const
Definition: event.hxx:117
void SetFunctionSet(FunctionSet *pFuncs)
Definition: seleng.hxx:128
FunctionSet * pFunctionSet
Definition: seleng.hxx:77
Definition: timer.hxx:26
bool HasAnchor() const
Definition: seleng.hxx:211
void LockModifiers(sal_uInt16 nModifiers)
Definition: seleng.hxx:139
SelectionMode GetSelectionMode() const
Definition: seleng.hxx:126
bool IsAlwaysAdding() const
Definition: seleng.hxx:195
SelectionEngineFlags
Definition: seleng.hxx:59