LibreOffice Module toolkit (master) 1
defaultinputhandler.cxx
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
22
23#include <vcl/event.hxx>
24#include <osl/diagnose.h>
25
26namespace svt::table
27{
28
29
30 //= DefaultInputHandler
31
32
34 {
35 aMouseFunctions.push_back( new ColumnResize );
36 aMouseFunctions.push_back( new RowSelection );
37 aMouseFunctions.push_back( new ColumnSortHandler );
38 }
39
40
42 {
43 }
44
45
47 FunctionResult ( MouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) )
48 {
49 if ( pActiveFunction.is() )
50 {
51 bool furtherHandler = false;
52 switch ( (pActiveFunction.get()->*i_handlerMethod)( i_control, i_event ) )
53 {
55 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" );
56 break;
58 break;
60 pActiveFunction.clear();
61 break;
62 case SkipFunction:
63 furtherHandler = true;
64 break;
65 }
66 if ( !furtherHandler )
67 // handled the event
68 return true;
69 }
70
71 // ask all other handlers
72 bool handled = false;
73 for (auto const& mouseFunction : aMouseFunctions)
74 {
75 if (handled)
76 break;
77 if (mouseFunction == pActiveFunction)
78 // we already invoked this function
79 continue;
80
81 switch ( (mouseFunction.get()->*i_handlerMethod)( i_control, i_event ) )
82 {
84 pActiveFunction = mouseFunction;
85 handled = true;
86 break;
89 OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactive handler cannot be continued or deactivated!" );
90 break;
91 case SkipFunction:
92 handled = false;
93 break;
94 }
95 }
96 return handled;
97 }
98
99
100 bool DefaultInputHandler::MouseMove( ITableControl& i_tableControl, const MouseEvent& i_event )
101 {
102 return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseMove );
103 }
104
105
106 bool DefaultInputHandler::MouseButtonDown( ITableControl& i_tableControl, const MouseEvent& i_event )
107 {
108 return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseDown );
109 }
110
111
112 bool DefaultInputHandler::MouseButtonUp( ITableControl& i_tableControl, const MouseEvent& i_event )
113 {
114 return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseUp );
115 }
116
117
118 bool DefaultInputHandler::KeyInput( ITableControl& _rControl, const KeyEvent& rKEvt )
119 {
120 bool bHandled = false;
121
122 const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
123 sal_uInt16 nKeyCode = rKeyCode.GetCode();
124
125 struct ActionMapEntry
126 {
127 sal_uInt16 nKeyCode;
128 sal_uInt16 nKeyModifier;
129 TableControlAction eAction;
130 }
131 static const aKnownActions[] = {
132 { KEY_DOWN, 0, cursorDown },
133 { KEY_UP, 0, cursorUp },
134 { KEY_LEFT, 0, cursorLeft },
135 { KEY_RIGHT, 0, cursorRight },
137 { KEY_END, 0, cursorToLineEnd },
138 { KEY_PAGEUP, 0, cursorPageUp },
149
151 };
152
153 const ActionMapEntry* pActions = aKnownActions;
154 for ( ; pActions->eAction != invalidTableControlAction; ++pActions )
155 {
156 if ( ( pActions->nKeyCode == nKeyCode ) && ( pActions->nKeyModifier == rKeyCode.GetModifier() ) )
157 {
158 bHandled = _rControl.dispatchAction( pActions->eAction );
159 break;
160 }
161 }
162
163 return bHandled;
164 }
165
166
168 {
169 _rControl.showCursor();
170 return false; // continue processing
171 }
172
173
175 {
176 _rControl.hideCursor();
177 return false; // continue processing
178 }
179
180
181} // namespace svt::table
182
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const vcl::KeyCode & GetKeyCode() const
virtual bool MouseButtonDown(ITableControl &_rControl, const MouseEvent &rMEvt) override
rtl::Reference< MouseFunction > pActiveFunction
bool delegateMouseEvent(ITableControl &i_control, const MouseEvent &i_event, FunctionResult(MouseFunction::*i_handlerMethod)(ITableControl &, const MouseEvent &))
virtual bool MouseButtonUp(ITableControl &_rControl, const MouseEvent &rMEvt) override
virtual bool LoseFocus(ITableControl &_rControl) override
virtual bool KeyInput(ITableControl &_rControl, const KeyEvent &rKEvt) override
std::vector< rtl::Reference< MouseFunction > > aMouseFunctions
virtual bool MouseMove(ITableControl &_rControl, const MouseEvent &rMEvt) override
virtual bool GetFocus(ITableControl &_rControl) override
defines a callback interface to be implemented by a concrete table control
virtual void showCursor()=0
shows the cell cursor
virtual void hideCursor()=0
hides the cell cursor
virtual bool dispatchAction(TableControlAction _eAction)=0
dispatches an action to the table control
virtual FunctionResult handleMouseUp(ITableControl &i_tableControl, MouseEvent const &i_event)=0
virtual FunctionResult handleMouseDown(ITableControl &i_tableControl, MouseEvent const &i_event)=0
virtual FunctionResult handleMouseMove(ITableControl &i_tableControl, MouseEvent const &i_event)=0
sal_uInt16 GetCode() const
sal_uInt16 GetModifier() const
constexpr sal_uInt16 KEY_MOD1
constexpr sal_uInt16 KEY_HOME
constexpr sal_uInt16 KEY_LEFT
constexpr sal_uInt16 KEY_PAGEDOWN
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_RIGHT
constexpr sal_uInt16 KEY_DOWN
constexpr sal_uInt16 KEY_SPACE
constexpr sal_uInt16 KEY_PAGEUP
constexpr sal_uInt16 KEY_SHIFT
constexpr sal_uInt16 KEY_END
@ cursorToFirstLine
moves the cursor to the first row, keeping the current column
@ cursorToLineStart
moves the cursor to the beginning of the current line
@ cursorLeft
moves the cursor in the table control one column to the left, if possible, by keeping the current row
@ cursorPageDown
moves the cursor one page down, keeping the current column
@ cursorSelectRowUp
selects the rows, above the actual cursor is
@ cursorBottomRight
moves the cursor to the bottom-most, right-most cell
@ cursorDown
moves the cursor in the table control one row down, if possible, by keeping the current column
@ invalidTableControlAction
invalid and final enumeration value, not to be actually used
@ cursorPageUp
moves the cursor one page up, keeping the current column
@ cursorSelectRowDown
selects the row, beneath the actual cursor is
@ cursorUp
moves the cursor in the table control one row up, if possible, by keeping the current column
@ cursorToLineEnd
moves the cursor to the end of the current line
@ cursorSelectRow
selects the row, where the actual cursor is
@ cursorTopLeft
moves the cursor to the top-most, left-most cell
@ cursorSelectRowAreaBottom
selects the row, from the actual cursor till bottom
@ cursorRight
moves the cursor in the table control one column to the right, if possible, by keeping the current ro...
@ cursorSelectRowAreaTop
selects the row, from the actual cursor till top
@ cursorToLastLine
moves the cursor to the last row, keeping the current column